View on GitHub
Open this notebook in GitHub to run it yourself
Guided Implementation
Now that we know how the LCU algorithm works, it’s time to implement it on Classiq. For that, we will be using two important functions:How does the Within-Apply function work?
How does the Within-Apply function work?
The Within-Apply maps unitary operations of the kind into the quantum circuit, given and .
With the SELECT function defined, we are able to apply the V operator, by using the Within-Apply function.
For this, it is necessary to build the PREPARE operator, which will be done using the inplace_prepare_state() function, that requires the probability distribution , the maximum error in the decomposition of the operator and the target qubits, which are the controllers.
- Define the error bound in the decomposition, and define the probability distribution
- Allocate target and control qubits
- Execute the Within-Apply function, using the PREPARE and SELECT functions
Output:
Output:
Mathematical Description
The initial state of our circuit is , for some general . After that, the PREPARE operation is applied, transforming it in the state: We can always represent the PREPARE operation, which acts only in the control qubits, as being: for some . The SELECT operation, which acts both in the control and target qubits, can also be described this way by Now, the state generated by is given by: When applying the projector onto the control qubits, we finally obtain the desired stateAll the Code Together
Output:
Output: