usingblock. As you note, you can't use measurement to do that in an adjointable operation; given that resetting is a special case of measurement, the
Resetoperation will also fail to preserve adjointability. The trick is that you need to coherently reset the qubit to |0⟩ without measurement. You can do that because you know exactly what state it's in at the end of the
using, and can unprepare it using only unitary operations. The
applyfeature of Q# or the
ApplyWithCAoperation will be very handy here.
By the way, @crazy4pi314 will be streaming with @bettinaheim about the Q# compiler today in a little under three hours if anyone is interested to join at https://twitch.tv/crazy4pi314. More details at https://twitter.com/crazy4pi314/status/1271837229221101569.
'Tand that returns an output of type
'Uis written as
'T => 'U; thus,
unitary : (Qubit = > Unit is Adj + Ctl)indicates that unitary takes a
Qubitinput and returns
is Adj + Ctltells you that
unitaryis adjointable and controllable (very important for some of the contest problems!). In this case, we can read the signature of
Solveas telling us that it takes an adjointable and controllable single-qubit operation, and returns an
Adjointfunctor to an adjointable operation doesn't change the type of that operation. For example,
Qubit => Unit is Adj + Ctl, such that
Adjoint Xalso has type
Qubit => Unit is Adj + Ctl. In the example from the contest problem,
Adjoint unitaryis an operation with type
(Qubit => Unit is Adj + Ctl). By contrast, for a controllable operation
Controlled opdoes modify the type to add the new control register. For more detail, you can checkout my book with @crazy4pi314 at bit.ly/qsharp-book, or the Microsoft Quantum docs at https://docs.microsoft.com/quantum/user-guide/using-qsharp/operations-functions#controlled-and-adjoint-operations.
IQSharpError: The Q# kernel raised the following errors: C:/Users/AmirEbrahimi/dev/qc/CodeForces2020/Warmup/notebook/Backend.qs(6,10): error QS6104: No namespace with the name "Microsoft.Quantum.Intrinsic" exists. C:/Users/AmirEbrahimi/dev/qc/CodeForces2020/Warmup/notebook/Backend.qs(9,10): error QS6104: No namespace with the name "Microsoft.Quantum.MachineLearning" exists. C:/Users/AmirEbrahimi/dev/qc/CodeForces2020/Warmup/notebook/Backend.qs(19,38): error QS6005: No type with the name "ControlledRotation" exists in any of the open namespaces. C:/Users/AmirEbrahimi/dev/qc/CodeForces2020/Warmup/notebook/Backend.qs(12,54): error QS6005: No type with the name "SamplingSchedule" exists in any of the open namespaces. C:/Users/AmirEbrahimi/dev/qc/CodeForces2020/Warmup/notebook/Backend.qs(33,23): error QS5022: No identifier with the name "Mapped" exists. ...
qsharp.reloadhappens and it finds a .qs file in the directory that it somehow doesn't have the full qsharp environment ?
@amirebrahimi I think it's the same issue as discussed at https://quantumcomputing.stackexchange.com/questions/12466/qsharp-reload-throws-error-in-python and in comments at https://codeforces.com/blog/entry/77614
This fixed it for me. Thank you @tcNickolas_twitter!
Re: D1 - I'm trying to modify the ClassifierStructure() to simply add an additional controlled rotation:
ControlledRotation((1, new Int), PauliY, 1)
but get the following error:
Unhandled exception. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
---> Microsoft.Quantum.MachineLearning.EstimateGradient on D:\a\1\s\submodules\QuantumLibraries\MachineLearning\src\GradientEstimation.qs:line 78
at Microsoft.Quantum.MachineLearning._RunSingleTrainingStep on D:\a\1\s\submodules\QuantumLibraries\MachineLearning\src\Training.qs:line 148
at Microsoft.Quantum.MachineLearning._RunSingleTrainingEpoch on D:\a\1\s\submodules\QuantumLibraries\MachineLearning\src\Training.qs:line 229
at Microsoft.Quantum.MachineLearning._TrainSequentialClassifierAtModel on D:\a\1\s\submodules\QuantumLibraries\MachineLearning\src\Training.qs:line 388
at Microsoft.Quantum.MachineLearning.TrainSequentialClassifierAtModel on D:\a\1\s\submodules\QuantumLibraries\MachineLearning\src\Training.qs:line 322
at Microsoft.Quantum.MachineLearning.TrainSequentialClassifier on D:\a\1\s\submodules\QuantumLibraries\MachineLearning\src\Training.qs:line 98
at Microsoft.Quantum.Kata.QuantumClassification.TrainLinearlySeparableModel on C:\Users\AmirEbrahimi\dev\qc\CodeForces2020\Warmup\notebook\Backend.qs:line 0
I've dug through the source on GitHub a bit and it seems it is failing at estimating the number of qubits needed. Any ideas of how to resolve this? I would think simply by adding that ControlledRotation with another qubit referenced that it would expand the number of qubits.
So, this isn't immediately apparent, but you need to use the unwrap '!' operator to get at the qubits:
e.g. - register!
As far as the rest, you need to consider how adders work and the equivalent on a quantum computer (that is also reversible).