qp.labs.transforms.make_selectpaulirot_to_phase_gradient_decomp¶
- make_selectpaulirot_to_phase_gradient_decomp(angle_wires, phase_grad_wires, work_wires)[source]¶
Custom decomposition rule for
SelectPauliRotgatesThis is a temporary workaround before moving to capture as default frontend, which unlocks dynamic wire allocation. Here, we explicitly provide the necessary wires for the phase gradient decomposition of SelectPauliRot. This way, this function can be used in a workflow context that explicitly uses those wires to generate this decomposition rule, which can then be used as
alt_decompsorfixed_decompwithindecompose().- Parameters:
- Returns:
decomposition rule to be used within
decompose().- Return type:
func
See also
Example
In this example we decompose a circuit containing only a single
SelectPauliRotgate using the custom decomposition rule that we generate from within the context of the example, where all auxiliary wires exist.import pennylane as qp from pennylane.labs.transforms import make_selectpaulirot_to_phase_gradient_decomp import numpy as np qp.decomposition.enable_graph() prec = 3 np.random.seed(35) angles = np.random.rand(2**3) angle_wires = qp.wires.Wires([f"aux_{i}" for i in range(prec)]) phase_grad_wires = qp.wires.Wires([f"qft_{i}" for i in range(prec)]) work_wires = qp.wires.Wires([f"work_{i}" for i in range(prec - 1)]) custom_decomp = make_selectpaulirot_to_phase_gradient_decomp( angle_wires, phase_grad_wires, work_wires ) @qp.decompose( gate_set={"QROM", "Adjoint(QROM)", "SemiAdder", "MultiControlledX", "GlobalPhase"}, fixed_decomps={qp.SelectPauliRot: custom_decomp} ) @qp.qnode(qp.device("null.qubit")) def circuit(angles): qp.SelectPauliRot(angles, control_wires=range(3), target_wire=3) return qp.state() specs = qp.specs(circuit)(angles)["resources"].gate_types
The resulting circuit corresponds to the phase gradient decomposition of
SelectPauliRot, containing two CNOT fanouts corresponding to the binary representation of the angle (111 in this case), theSemiAdder, and aGlobalPhase.>>> specs {'QROM': 1, 'MultiControlledX': 6, 'SemiAdder': 1, 'Adjoint(QROM)': 1} >>> print(qp.draw(circuit, wire_order=[0, 1, 2, 3] + angle_wires + phase_grad_wires + work_wires)(angles)) 0: ─╭QROM(M0)──────────────────────────────╭QROM(M0)†─┤ State 1: ─├QROM(M0)──────────────────────────────├QROM(M0)†─┤ State 2: ─├QROM(M0)──────────────────────────────├QROM(M0)†─┤ State 3: ─│─────────╭○─╭○─╭○────────────╭○─╭○─╭○─│──────────┤ State aux_0: ─├QROM(M0)─│──│──│──╭SemiAdder─│──│──│──├QROM(M0)†─┤ State aux_1: ─├QROM(M0)─│──│──│──├SemiAdder─│──│──│──├QROM(M0)†─┤ State aux_2: ─├QROM(M0)─│──│──│──├SemiAdder─│──│──│──├QROM(M0)†─┤ State qft_0: ─│─────────╰X─│──│──├SemiAdder─│──│──╰X─│──────────┤ State qft_1: ─│────────────╰X─│──├SemiAdder─│──╰X────│──────────┤ State qft_2: ─│───────────────╰X─├SemiAdder─╰X───────│──────────┤ State work_0: ─├QROM(M0)──────────├SemiAdder──────────├QROM(M0)†─┤ State work_1: ─╰QROM(M0)──────────╰SemiAdder──────────╰QROM(M0)†─┤ State