qrunch.quantum.gates.universal_gates
Module with implementations of universal quantum gates.
Classes
Two qubit controlled X-gate (CX or CNOT). |
|
Phase gate. |
|
Single qubit X-rotation. |
|
Single qubit Y-rotation. |
|
Single qubit Z-rotation. |
- class CXGate
Bases:
UniversalGateTwo qubit controlled X-gate (CX or CNOT). The CX gate acts on two qubits as.
\[\begin{split}\text{CX} |00\rangle = |00\rangle, \\ \text{CX} |01\rangle = |01\rangle, \\ \text{CX} |10\rangle = |11\rangle, \\ \text{CX} |11\rangle = |01\rangle.\end{split}\]Circuit form:
────●──── │ ┌─┴─┐ ──┤ X ├── └───┘Matrix representation in the basis \((|00\rangle, |01\rangle, |10\rangle, |11\rangle)\):
\[\begin{split}\text{CX} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix}\end{split}\]- __init__(control_qubit_index: int, target_qubit_index: int) None
Initialize a CX-gate for a control and target qubit.
Indices control_qubit_index and target_qubit_index, respectively.
- Parameters:
control_qubit_index (int) – Index of the control qubit.
target_qubit_index (int) – Index of the qubit for the X-gate to be conditionally applied on.
- 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
- classmethod decode(data: dict[str, Any]) CXGate
Decode a dictionary.
- Parameters:
data (dict[str, Any]) – The dictionary representation.
- Return type:
- encode() dict[str, Any]
Encode the instance into a dictionary.
- Return type:
dict[str, Any]
- flatten() Iterator[Gate]
Flatten the gate into a list of primitive gates.
- Return type:
Iterator[Gate]
- invert() Self
Get the inverse of the gate.
- Return type:
Self
- is_fully_specified() bool
Check if all parameters have been specified.
- Return type:
bool
- property parameters: list[float | Parameter | ParameterExpression]
List of all parameters available.
- property qubit_indices: tuple[int, int]
Tuple containing the qubit indices for the gate as (control_qubit_index, target_qubit_index).
- relocate(new_indices: Mapping[int, int]) Self
Relocate the gate to new qubit indices.
- Parameters:
new_indices (Mapping[int, int]) – Mapping between current qubit indices and new qubit indices.
- Returns:
New gate with the qubit indices updated.
- Return type:
- symbols(*, max_number_of_decimals: int | None = None) list[str]
Symbols for represent the gate in a circuit.
- Parameters:
max_number_of_decimals (int | None) – Maximum number of decimals to use for floats in the symbols. Defaults to None.
- Return type:
list[str]
- with_specified_parameters(parameter_value_pairs: dict[Parameter, float | ParameterExpression]) Self
Create a new gate with the specified parameters.
- Parameters:
parameter_value_pairs (dict[Parameter, float | ParameterExpression]) – Mapping between parameters and their values.
- Returns:
New gate with the parameters specified.
- Return type:
Self
- class PGate
Bases:
UniversalGate,GateEncodingMixinPhase gate.
\[\begin{split}P(\phi) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\phi} \end{bmatrix}\end{split}\]Circuit form:
┌─────┐ ──┤P(φ) ├── └─────┘
- __init__(parameter: Parameter | ParameterExpression | float, qubit_index: int) None
Initialize a P-gate for a qubit with the given index qubit_index.
- Parameters:
parameter (Parameter | ParameterExpression | float) – Parameter of the gate.
qubit_index (int) – Index of the qubit for the P-gate to act on.
- 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
- classmethod decode(data: dict[str, Any]) T
Decode a dictionary.
- Parameters:
data (dict[str, Any]) – The dictionary representation.
- Return type:
T
- encode() dict[str, Any]
Encode the instance into a dictionary.
- Return type:
dict[str, Any]
- flatten() Iterator[Gate]
Flatten the gate into a list of primitive gates.
- Return type:
Iterator[Gate]
- invert() Self
Get the inverse of the gate.
- Return type:
Self
- is_fully_specified() bool
Check if all parameters have been specified.
- Return type:
bool
- property parameters: list[float | Parameter | ParameterExpression]
List of parameters for the gate.
- property qubit_indices: tuple[int]
Tuple containing the qubit indices for the gate as (qubit_index).
- relocate(new_indices: Mapping[int, int]) Self
Relocate the gate to new qubit indices.
- Parameters:
new_indices (Mapping[int, int]) – Mapping between current qubit indices and new qubit indices.
- Returns:
New gate with the qubit indices updated.
- Return type:
- symbols(*, max_number_of_decimals: int | None = None) list[str]
Symbols for represent the gate in a circuit.
- Parameters:
max_number_of_decimals (int | None) – Maximum number of decimals to use for floats in the symbols. Defaults to None.
- Return type:
list[str]
- class RXGate
Bases:
UniversalGate,GateEncodingMixinSingle qubit X-rotation. The operator form of the Rx-gate is.
\[R_x(\theta) = \cos \theta/2 I -i \sin \theta/2 X ,\]where X is the pauli X operator from
XGate.Circuit form:
┌─────┐ ──┤Rx(θ)├── └─────┘
Matrix representation in the basis \((|0\rangle, |1\rangle)\):
\[\begin{split}R_x(\theta) = \begin{bmatrix} \cos \theta/2 & -i\sin \theta/2 \\ -i\sin \theta/2 & \cos \theta/2 \end{bmatrix}\end{split}\]- __init__(parameter: Parameter | ParameterExpression | float, qubit_index: int) None
Initialize an RX-gate for a qubit with the given index qubit_index.
- Parameters:
parameter (Parameter | ParameterExpression | float) – Parameter of the gate.
qubit_index (int) – Index of the qubit for the RX-gate to act on.
- 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
- classmethod decode(data: dict[str, Any]) T
Decode a dictionary.
- Parameters:
data (dict[str, Any]) – The dictionary representation.
- Return type:
T
- encode() dict[str, Any]
Encode the instance into a dictionary.
- Return type:
dict[str, Any]
- flatten() Iterator[Gate]
Flatten the gate into a list of primitive gates.
- Return type:
Iterator[Gate]
- invert() Self
Get the inverse of the gate.
- Return type:
Self
- is_fully_specified() bool
Check if all parameters have been specified.
- Return type:
bool
- property parameters: list[float | Parameter | ParameterExpression]
List of parameters for the gate.
- property qubit_indices: tuple[int]
Tuple containing the qubit indices for the gate as (qubit_index).
- relocate(new_indices: Mapping[int, int]) Self
Relocate the gate to new qubit indices.
- Parameters:
new_indices (Mapping[int, int]) – Mapping between current qubit indices and new qubit indices.
- Returns:
New gate with the qubit indices updated.
- Return type:
- symbols(*, max_number_of_decimals: int | None = None) list[str]
Symbols for represent the gate in a circuit.
- Parameters:
max_number_of_decimals (int | None) – Maximum number of decimals to use for floats in the symbols. Defaults to None.
- Return type:
list[str]
- class RYGate
Bases:
UniversalGate,GateEncodingMixinSingle qubit Y-rotation. The operator form of the Ry-gate is.
\[R_Y(\theta) = \cos \theta/2 I -i \sin \theta/2 Y ,\]where Y is the pauli Y operator which acts on qubits as
\[\begin{split}Y|0\rangle &= i|1\rangle, \\ Y|1\rangle &= -i|0\rangle.\end{split}\]Circuit form:
┌─────┐ ──┤Ry(θ)├── └─────┘
Matrix representation in the basis \((|0\rangle, |1\rangle)\):
\[\begin{split}R_y(\theta) = \begin{bmatrix} \cos \theta/2 & -\sin \theta/2 \\ \sin \theta/2 & \cos \theta/2 \end{bmatrix}\end{split}\]- __init__(parameter: Parameter | ParameterExpression | float, qubit_index: int) None
Initialize an RY-gate for a qubit with the given index qubit_index.
- Parameters:
parameter (Parameter | ParameterExpression | float) – Parameter of the gate.
qubit_index (int) – Index of the qubit for the RY-gate to act on.
- 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
- classmethod decode(data: dict[str, Any]) T
Decode a dictionary.
- Parameters:
data (dict[str, Any]) – The dictionary representation.
- Return type:
T
- encode() dict[str, Any]
Encode the instance into a dictionary.
- Return type:
dict[str, Any]
- flatten() Iterator[Gate]
Flatten the gate into a list of primitive gates.
- Return type:
Iterator[Gate]
- invert() Self
Get the inverse of the gate.
- Return type:
Self
- is_fully_specified() bool
Check if all parameters have been specified.
- Return type:
bool
- property parameters: list[float | Parameter | ParameterExpression]
List of parameters for the gate.
- property qubit_indices: tuple[int]
Tuple containing the qubit indices for the gate as (qubit_index).
- relocate(new_indices: Mapping[int, int]) Self
Relocate the gate to new qubit indices.
- Parameters:
new_indices (Mapping[int, int]) – Mapping between current qubit indices and new qubit indices.
- Returns:
New gate with the qubit indices updated.
- Return type:
- symbols(*, max_number_of_decimals: int | None = None) list[str]
Symbols for represent the gate in a circuit.
- Parameters:
max_number_of_decimals (int | None) – Maximum number of decimals to use for floats in the symbols. Defaults to None.
- Return type:
list[str]
- class RZGate
Bases:
UniversalGate,GateEncodingMixinSingle qubit Z-rotation. The operator form of the Rz-gate is.
\[R_Z(\theta) = \cos \theta/2 I -i \sin \theta/2 Z ,\]where Z is the pauli Z operator which acts on qubits as
\[\begin{split}Z|0\rangle &= |0\rangle, \\ Z|1\rangle &= -|1\rangle.\end{split}\]Circuit form:
┌─────┐ ──┤Rz(θ)├── └─────┘
Matrix representation in the basis \((|0\rangle, |1\rangle)\):
\[\begin{split}R_z(\theta) = \begin{bmatrix} e^{-i\theta/2} & 0 \\ 0 & e^{i\theta/2} \end{bmatrix}\end{split}\]- __init__(parameter: Parameter | ParameterExpression | float, qubit_index: int) None
Initialize a RZ-gate for a qubit with the given index qubit_index.
- Parameters:
parameter (Parameter | ParameterExpression | float) – Parameter of the gate.
qubit_index (int) – Index of the qubit for the RZ-gate to act on.
- 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
- classmethod decode(data: dict[str, Any]) T
Decode a dictionary.
- Parameters:
data (dict[str, Any]) – The dictionary representation.
- Return type:
T
- encode() dict[str, Any]
Encode the instance into a dictionary.
- Return type:
dict[str, Any]
- flatten() Iterator[Gate]
Flatten the gate into a list of primitive gates.
- Return type:
Iterator[Gate]
- invert() Self
Get the inverse of the gate.
- Return type:
Self
- is_fully_specified() bool
Check if all parameters have been specified.
- Return type:
bool
- property parameters: list[float | Parameter | ParameterExpression]
List of parameters for the gate.
- property qubit_indices: tuple[int]
Tuple containing the qubit indices for the gate as (qubit_index).
- relocate(new_indices: Mapping[int, int]) Self
Relocate the gate to new qubit indices.
- Parameters:
new_indices (Mapping[int, int]) – Mapping between current qubit indices and new qubit indices.
- Returns:
New gate with the qubit indices updated.
- Return type:
- symbols(*, max_number_of_decimals: int | None = None) list[str]
Symbols for represent the gate in a circuit.
- Parameters:
max_number_of_decimals (int | None) – Maximum number of decimals to use for floats in the symbols. Defaults to None.
- Return type:
list[str]