qpe_toolbox.circuit.controls¶
Routines for quimb circuits and/or gates.
Functions¶
|
Add controls to a list of gates, optionally shifting and setting their round. |
|
Shift gate targets and controls to account for an auxiliary qubit register. |
Module Contents¶
- qpe_toolbox.circuit.controls.add_gate_controls(gates, controls, *, qubit_shift=0, gate_round=None)[source]¶
Add controls to a list of gates, optionally shifting and setting their round.
Each gate is copied once: its target and control qubits are shifted by
qubit_shift,controlsare appended, and the gate round is set whengate_roundis given.- Parameters:
gates (iterable of Gate) – Gates to control.
controls (sequence of int) – Control qubits, appended to the existing controls of each gate.
qubit_shift (int, default
0) – Offset added to every target and existing-control qubit index. The appendedcontrolsare taken as already-final indices and not shifted.gate_round (int or None, default
None) – Gate round assigned to each copy. WhenNonethe existing round is left untouched.
- Yields:
controlled_gate (Gate) – New gate object with the additional controls. The generator is one-shot: wrap it in
listto iterate more than once.
Notes
Use
shift_control_gatesfor the common case of shifting gates past an auxiliary register and controlling on one of its qubits.The original gate objects are not modified.
- qpe_toolbox.circuit.controls.shift_control_gates(gates, m_aux, k_ctrl, *, gate_round=None)[source]¶
Shift gate targets and controls to account for an auxiliary qubit register.
This function is used when an auxiliary (ancilla) register occupies the first
m_auxqubits of a circuit. All gates acting on the data register are shifted bym_auxin their qubit indices, and an additional control qubit from the auxiliary register is added to each gate.- Parameters:
gates (iterable of Gate) – List of gates to shift.
m_aux (int) – Number of auxiliary qubits occupying the lowest indices
[0, m_aux - 1].k_ctrl (int) – Index of the control qubit within the auxiliary register. Must satisfy
0 <= k_ctrl < m_aux.gate_round (int or None, default
None) – Gate round assigned to each shifted gate. WhenNonethe existing round is left untouched.
- Returns:
controlled_gates – New gate objects with shifted qubit indices and added control. The generator is one-shot: wrap it in
listto iterate more than once.- Return type:
generator of Gate
- Raises:
ValueError – If
k_ctrllies outside the auxiliary register.
Notes
Target qubits
qare mapped toq + m_aux.Existing control qubits are also shifted by
m_aux.If a gate originally has no controls, it becomes singly controlled by
k_ctrl.The original gate objects are not modified.