qrunch.quantum.gates.controlled_gate
ControlledGate — a gate conditioned on a single control qubit.
Classes
A gate conditioned on a single control qubit. |
- class ControlledGate
Bases:
GateA gate conditioned on a single control qubit.
The base gate is applied only when the control qubit is in the state specified by control_state (\(|1\rangle\) by default).
- __init__(base_gate: Gate, control_qubit: int, *, control_state: bool = True) None
Initialise a
ControlledGate.- Parameters:
base_gate (Gate) – The gate whose action is conditioned on the control qubit.
control_qubit (int) – Index of the control qubit. Must be non-negative and must not overlap with any qubit index in base_gate.
control_state (bool) –
True(default) for \(|1\rangle\)-control,Falsefor \(|0\rangle\)-control.
- Return type:
None
- commutes_with_pauli_string(pauli_string: PauliString) bool
Check if gate commutes with the given pauli string. Default is False.
The default implementation always returns False. So False is considered a safe answer. An only True should be trusted.
- Parameters:
pauli_string (PauliString) – Pauli string to check commutation for.
- Return type:
bool
- property control_qubit: int
The index of the control qubit.
- property control_state: bool
Whether the gate fires on \(|1\\rangle\) (
True) or \(|0\\rangle\) (False).
- property gates: list[Gate]
Return
[self]—ControlledGateis a terminal gate.
- invert() Self
Return a
ControlledGatethat is the inverse of this one.- Return type:
Self
- is_fully_specified() bool
Check if all parameters have been specified.
- Return type:
bool
- metadata_hash(*, max_number_of_decimals: int = 6) tuple[object, ...]
Return a hashable representation of the gate for metadata caching.
- Parameters:
max_number_of_decimals (int) – Maximum number of decimals for rounding float parameters.
- Return type:
tuple[object, …]
- property parameters: list[float | Parameter | ParameterExpression]
Return the parameters of the base gate.
- property qubit_indices: tuple[int, ...]
control qubit first, then base gate target qubits.
- Type:
All qubit indices
- relocate(new_indices: Mapping[int, int]) Self
Return a copy of this gate acting on remapped qubit indices.
- Parameters:
new_indices (Mapping[int, int]) – Mapping from current qubit indices to new qubit indices.
- Return type:
Self
- symbols(*, max_number_of_decimals: int | None = None) list[str]
Symbols for representing the gate in a circuit diagram.
- Parameters:
max_number_of_decimals (int | None) – Maximum number of decimals to use for floats in the symbols.
- Return type:
list[str]
- with_specified_parameters(parameter_value_pairs: dict[Parameter, float | ParameterExpression]) Self
Return a copy of this gate with the base gate parameters specified.
- Parameters:
parameter_value_pairs (dict[Parameter, float | ParameterExpression]) – Mapping between parameters and their values.
- Return type:
Self