setups.decompositions
The decomposition package is a collection of gate decomposition / replacement rules which can be used by, e.g., the AutoReplacer engine.
Registers a decomposition for quantum amplitude amplification. |
|
Register the Z-Y decomposition for an arbitrary one qubit gate. |
|
Registers a decomposition rule for barriers. |
|
Register the decomposition of an controlled arbitary single qubit gate. |
|
Registers a decomposition to for a CNOT gate in terms of CZ and Hadamard. |
|
Register a decomposition to for a CNOT gate in terms of Rxx, Rx and Ry gates. |
|
Register a decomposition rule for multi-controlled gates. |
|
Register a decomposition to replace turn negatively controlled qubits into positively controlled qubits. |
|
Registers a decomposition for controlled z-rotation gates. |
|
Registers a decomposition for the Entangle gate. |
|
Registers a decomposition rule for global phases. |
|
Register a decomposition for the H gate into an Ry and Rx gate. |
|
Registers a decomposition for the controlled global phase gate. |
|
Registers a decomposition for phase estimation. |
|
Registers a decomposition rule for the quantum Fourier transform. |
|
Register a decomposition rule for a unitary QubitOperator to one qubit gates. |
|
Registers a decomposition rule for the phase-shift gate. |
|
Register a decomposition for the Rx gate into an Rz gate and Hadamard. |
|
Register a decomposition for the Ry gate into an Rz and Rx(pi/2) gate. |
|
Registers a decomposition for the Rz gate into an Rx and Ry(pi/2) or Ry(-pi/2) gate. |
|
Register a decomposition to achieve a SqrtSwap gate. |
|
Register decomposition for StatePreparation. |
|
Registers a decomposition to achieve a Swap gate. |
|
Register decomposition for the TimeEvolution gates. |
|
Registers a decomposition rule for the Toffoli gate. |
|
Register decomposition for UnformlyControlledRy and UnformlyControlledRz. |
|
|
Built-in mutable sequence. |
Submodules
amplitudeamplification
Registers a decomposition for quantum amplitude amplification.
(Quick reference https://en.wikipedia.org/wiki/Amplitude_amplification. Complete reference G. Brassard, P. Hoyer, M. Mosca, A. Tapp (2000) Quantum Amplitude Amplification and Estimation https://arxiv.org/abs/quant-ph/0005055)
Quantum Amplitude Amplification (QAA) executes the algorithm, but not the final measurement required to obtain the marked state(s) with high probability. The starting state on wich the QAA algorithm is executed is the one resulting of aplying the Algorithm on the |0> state.
Example
def func_algorithm(eng, system_qubits):
All(H) | system_qubits
def func_oracle(eng, system_qubits, qaa_ancilla):
# This oracle selects the state |010> as the one marked
with Compute(eng):
All(X) | system_qubits[0::2]
with Control(eng, system_qubits):
X | qaa_ancilla
Uncompute(eng)
system_qubits = eng.allocate_qureg(3)
# Prepare the qaa_ancilla qubit in the |-> state
qaa_ancilla = eng.allocate_qubit()
X | qaa_ancilla
H | qaa_ancilla
# Creates the initial state form the Algorithm
func_algorithm(eng, system_qubits)
# Apply Quantum Amplitude Amplification the correct number of times
num_it = int(math.pi / 4.0 * math.sqrt(1 << 3))
with Loop(eng, num_it):
QAA(func_algorithm, func_oracle) | (system_qubits, qaa_ancilla)
All(Measure) | system_qubits
Warning
No qubit allocation/deallocation may take place during the call
to the defined Algorithm func_algorithm
- projectq.setups.decompositions.amplitudeamplification.func_algorithm
Algorithm that initialite the state and to be used in the QAA algorithm
- projectq.setups.decompositions.amplitudeamplification.func_oracle
The Oracle that marks the state(s) as “good”
- projectq.setups.decompositions.amplitudeamplification.system_qubits
the system we are interested on
- projectq.setups.decompositions.amplitudeamplification.qaa_ancilla
auxiliary qubit that helps to invert the amplitude of the “good” states
- projectq.setups.decompositions.amplitudeamplification.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
arb1qubit2rzandry
Register the Z-Y decomposition for an arbitrary one qubit gate.
See paper “Elementary gates for quantum computing” by Adriano Barenco et al., arXiv:quant-ph/9503016v1. (Note: They use different gate definitions!) Or see theorem 4.1 in Nielsen and Chuang.
Decompose an arbitrary one qubit gate U into U = e^(i alpha) Rz(beta) Ry(gamma) Rz(delta). If a gate V is element of SU(2), i.e., determinant == 1, then V = Rz(beta) Ry(gamma) Rz(delta)
- projectq.setups.decompositions.arb1qubit2rzandry.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
barrier
Registers a decomposition rule for barriers.
Deletes all barriers if they are not supported.
- projectq.setups.decompositions.barrier.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
carb1qubit2cnotrzandry
Register the decomposition of an controlled arbitary single qubit gate.
See paper “Elementary gates for quantum computing” by Adriano Barenco et al., arXiv:quant-ph/9503016v1. (Note: They use different gate definitions!) or Nielsen and Chuang chapter 4.3.
- projectq.setups.decompositions.carb1qubit2cnotrzandry.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
cnot2cz
Registers a decomposition to for a CNOT gate in terms of CZ and Hadamard.
- projectq.setups.decompositions.cnot2cz.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
cnot2rxx
Register a decomposition to for a CNOT gate in terms of Rxx, Rx and Ry gates.
- projectq.setups.decompositions.cnot2rxx.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>, <projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
cnu2toffoliandcu
Register a decomposition rule for multi-controlled gates.
Implements the decomposition of Nielsen and Chuang (Fig. 4.10) which decomposes a C^n(U) gate into a sequence of 2 * (n-1) Toffoli gates and one C(U) gate by using (n-1) ancilla qubits and circuit depth of 2n-1.
- projectq.setups.decompositions.cnu2toffoliandcu.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
controlstate
Register a decomposition to replace turn negatively controlled qubits into positively controlled qubits.
This achived by applying X gates to selected qubits.
- projectq.setups.decompositions.controlstate.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
crz2cxandrz
Registers a decomposition for controlled z-rotation gates.
It uses 2 z-rotations and 2 C^n NOT gates to achieve this gate.
- projectq.setups.decompositions.crz2cxandrz.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
entangle
Registers a decomposition for the Entangle gate.
Applies a Hadamard gate to the first qubit and then, conditioned on this first qubit, CNOT gates to all others.
- projectq.setups.decompositions.entangle.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
globalphase
Registers a decomposition rule for global phases.
Deletes global phase gates (which can be ignored).
- projectq.setups.decompositions.globalphase.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
h2rx
Register a decomposition for the H gate into an Ry and Rx gate.
- projectq.setups.decompositions.h2rx.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>, <projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
ph2r
Registers a decomposition for the controlled global phase gate.
Turns the controlled global phase gate into a (controlled) phase-shift gate. Each time this rule is applied, one control can be shaved off.
- projectq.setups.decompositions.ph2r.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
phaseestimation
Registers a decomposition for phase estimation.
(reference https://en.wikipedia.org/wiki/Quantum_phase_estimation_algorithm)
The Quantum Phase Estimation (QPE) executes the algorithm up to the inverse QFT included. The following steps measuring the ancillas and computing the phase should be executed outside of the QPE.
The decomposition uses as ancillas (qpe_ancillas) the first qubit/qureg in the Command and as system qubits teh second qubit/qureg in the Command.
The unitary operator for which the phase estimation is estimated (unitary) is the gate in Command
Example
# Example using a ProjectQ gate
n_qpe_ancillas = 3
qpe_ancillas = eng.allocate_qureg(n_qpe_ancillas)
system_qubits = eng.allocate_qureg(1)
angle = cmath.pi * 2.0 * 0.125
U = Ph(angle) # unitary_specfic_to_the_problem()
# Apply Quantum Phase Estimation
QPE(U) | (qpe_ancillas, system_qubits)
All(Measure) | qpe_ancillas
# Compute the phase from the ancilla measurement
# (https://en.wikipedia.org/wiki/Quantum_phase_estimation_algorithm)
phasebinlist = [int(q) for q in qpe_ancillas]
phase_in_bin = ''.join(str(j) for j in phasebinlist)
phase_int = int(phase_in_bin, 2)
phase = phase_int / (2**n_qpe_ancillas)
print(phase)
# Example using a function (two_qubit_gate).
# Instead of applying QPE on a gate U one could provide a function
def two_qubit_gate(system_q, time):
CNOT | (system_q[0], system_q[1])
Ph(2.0 * cmath.pi * (time * 0.125)) | system_q[1]
CNOT | (system_q[0], system_q[1])
n_qpe_ancillas = 3
qpe_ancillas = eng.allocate_qureg(n_qpe_ancillas)
system_qubits = eng.allocate_qureg(2)
X | system_qubits[0]
# Apply Quantum Phase Estimation
QPE(two_qubit_gate) | (qpe_ancillas, system_qubits)
All(Measure) | qpe_ancillas
# Compute the phase from the ancilla measurement
# (https://en.wikipedia.org/wiki/Quantum_phase_estimation_algorithm)
phasebinlist = [int(q) for q in qpe_ancillas]
phase_in_bin = ''.join(str(j) for j in phasebinlist)
phase_int = int(phase_in_bin, 2)
phase = phase_int / (2**n_qpe_ancillas)
print(phase)
- projectq.setups.decompositions.phaseestimation.unitary
Unitary Operation either a ProjectQ gate or a function f.
- Type
- Calling the function with the parameters system_qubits
- Type
Qureg) and time (integer
- i.e. f
- Type
system_qubits, time
- with parameter time.
- projectq.setups.decompositions.phaseestimation.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
qft2crandhadamard
Registers a decomposition rule for the quantum Fourier transform.
Decomposes the QFT gate into Hadamard and controlled phase-shift gates (R).
Warning
The final Swaps are not included, as those are simply a re-indexing of quantum registers.
- projectq.setups.decompositions.qft2crandhadamard.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
qubitop2onequbit
Register a decomposition rule for a unitary QubitOperator to one qubit gates.
- projectq.setups.decompositions.qubitop2onequbit.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
r2rzandph
Registers a decomposition rule for the phase-shift gate.
Decomposes the (controlled) phase-shift gate using z-rotation and a global phase gate.
- projectq.setups.decompositions.r2rzandph.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
rx2rz
Register a decomposition for the Rx gate into an Rz gate and Hadamard.
- projectq.setups.decompositions.rx2rz.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
ry2rz
Register a decomposition for the Ry gate into an Rz and Rx(pi/2) gate.
- projectq.setups.decompositions.ry2rz.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
rz2rx
Registers a decomposition for the Rz gate into an Rx and Ry(pi/2) or Ry(-pi/2) gate.
- projectq.setups.decompositions.rz2rx.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>, <projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
sqrtswap2cnot
Register a decomposition to achieve a SqrtSwap gate.
- projectq.setups.decompositions.sqrtswap2cnot.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
stateprep2cnot
Register decomposition for StatePreparation.
- projectq.setups.decompositions.stateprep2cnot.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
swap2cnot
Registers a decomposition to achieve a Swap gate.
Decomposes a Swap gate using 3 CNOT gates, where the one in the middle features as many control qubits as the Swap gate has control qubits.
- projectq.setups.decompositions.swap2cnot.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
time_evolution
Register decomposition for the TimeEvolution gates.
An exact straight forward decomposition of a TimeEvolution gate is possible if the hamiltonian has only one term or if all the terms commute with each other in which case one can implement each term individually.
- projectq.setups.decompositions.time_evolution.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>, <projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
toffoli2cnotandtgate
Registers a decomposition rule for the Toffoli gate.
Decomposes the Toffoli gate using Hadamard, T, Tdag, and CNOT gates.
- projectq.setups.decompositions.toffoli2cnotandtgate.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules
uniformlycontrolledr2cnot
Register decomposition for UnformlyControlledRy and UnformlyControlledRz.
- projectq.setups.decompositions.uniformlycontrolledr2cnot.all_defined_decomposition_rules = [<projectq.cengines._replacer._decomposition_rule.DecompositionRule object>, <projectq.cengines._replacer._decomposition_rule.DecompositionRule object>]
Decomposition rules