qrunch.quantum.gates.spin_preserving_excitation_gates

Single-angle excitation gates that preserve total spin on a fermionic register with restricted orbitals.

Functions

expand_spin_preserving_excitation_gates(gates)

Replace spin-preserving excitation gates by the excitation gates they consist of.

Classes

SpinPreservingExcitationGate

Base class for single-angle spin-preserving gates built from excitation gates.

SpinPreservingPairExcitationGate

Spin-preserving pair excitation: move both electrons of spatial orbital \(i\) together to orbital \(a\).

SpinPreservingPairSeparationGate

Spin-preserving pair separation: split the pair in orbital \(i\) over orbitals \(a\) and \(b\).

SpinPreservingSingleExcitationGate

Spin-preserving single excitation: move one electron from spatial orbital \(q\) to \(p\).

class SpinPreservingExcitationGate

Bases: CompositeGate, GateEncodingMixin

Base class for single-angle spin-preserving gates built from excitation gates.

__init__(parameter: Parameter | ParameterExpression | float, qubit_indices: tuple[int, ...]) → None

Initialize a spin-preserving excitation gate.

Parameters:
  • parameter (Parameter | ParameterExpression | float) – The single angle of the gate.

  • qubit_indices (tuple[int, ...]) – Spin-orbital qubits the gate acts on.

Return type:

None

static active_qubits(gates: Iterable[Gate]) → set[int]

Return the active qubits in a sequence of gates.

Parameters:

gates (Iterable[Gate]) – Sequence of gates.

Return type:

set[int]

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() → list[Gate]

Flatten the gate into a list of primitive gates.

Return type:

list[Gate]

property gates: list[Gate]

List of gates that the composite gate is constructed from.

The list of gates are the immediate sub-gates that the composite gate is constructed from, not necessarily the primitive gates. To expand the gate down to primitive gates use the primitive_gates property instead.

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

is_identity(*, atol: float | None = 1e-12) → bool

Check for a numerically zero angle without expanding the gate.

Parameters:

atol (float | None) – Absolute tolerance for the rotation angle.

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, …]

name: str
property parameters: list[float | Parameter | ParameterExpression]

List of all parameters available.

property qubit_indices: tuple[int, ...]

Indices of the qubits that gate is working on.

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:

Gate

shift_by_one() → Self

Shift the gate’s qubit indices by one (+1).

Return type:

Self

static sorted_active_qubits(gates: Iterable[Gate]) → tuple[int, ...]

Return the active qubits in a sequence of gates, sorted, as a tuple.

Parameters:

gates (Iterable[Gate]) – Sequence of gates.

Return type:

tuple[int, …]

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

Assign parameters with the given float value.

Parameters:

parameter_value_pairs (dict[Parameter, float | ParameterExpression])

Return type:

Self

class SpinPreservingPairExcitationGate

Bases: SpinPreservingExcitationGate

Spin-preserving pair excitation: move both electrons of spatial orbital \(i\) together to orbital \(a\).

The gate rotates between “orbital \(i\) doubly occupied, orbital \(a\) empty” and “orbital \(i\) empty, orbital \(a\) doubly occupied” and leaves all other configurations of the four qubits unchanged,

\[U(\theta) = \mathrm{DEE}_{a\alpha, a\beta, i\alpha, i\beta}(\theta).\]

A doubly occupied orbital is a singlet, so moving the intact pair does not change the total spin. This holds for any spacing of the orbitals and with other singly occupied orbitals in the register, so no Jordan-Wigner parity strings are needed. It is the fermionic counterpart of a BEAST single excitation, which moves one pair.

The pair cannot be separated by this gate. Use SpinPreservingPairSeparationGate to put the two electrons in different orbitals.

__init__(parameter: Parameter | ParameterExpression | float, creation_alpha_qubit_index: int, creation_beta_qubit_index: int, annihilation_alpha_qubit_index: int, annihilation_beta_qubit_index: int) → None

Initialize a spin-preserving pair excitation gate.

Parameters:
  • parameter (Parameter | ParameterExpression | float) – Parameter \(\theta\) of the double excitation.

  • creation_alpha_qubit_index (int) – Qubit of spin orbital \(a\alpha\).

  • creation_beta_qubit_index (int) – Qubit of spin orbital \(a\beta\).

  • annihilation_alpha_qubit_index (int) – Qubit of spin orbital \(i\alpha\).

  • annihilation_beta_qubit_index (int) – Qubit of spin orbital \(i\beta\).

Return type:

None

static active_qubits(gates: Iterable[Gate]) → set[int]

Return the active qubits in a sequence of gates.

Parameters:

gates (Iterable[Gate]) – Sequence of gates.

Return type:

set[int]

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() → list[Gate]

Flatten the gate into a list of primitive gates.

Return type:

list[Gate]

classmethod from_spatial_orbitals(parameter: Parameter | ParameterExpression | float, creation_orbital: int, annihilation_orbital: int, number_of_spatial_orbitals: int) → Self

Create the gate on a block-spin register.

In a block-spin register \(p\alpha\) is qubit \(p\) and \(p\beta\) is qubit \(K + p\).

Parameters:
  • parameter (Parameter | ParameterExpression | float) – Parameter \(\theta\) of the gate.

  • creation_orbital (int) – Spatial orbital \(a\) receiving the pair.

  • annihilation_orbital (int) – Spatial orbital \(i\) losing the pair.

  • number_of_spatial_orbitals (int) – Number of spatial orbitals \(K\).

Return type:

Self

property gates: list[Gate]

List of gates that the composite gate is constructed from.

The list of gates are the immediate sub-gates that the composite gate is constructed from, not necessarily the primitive gates. To expand the gate down to primitive gates use the primitive_gates property instead.

invert() → Self

Get the inverse of the gate, which is the gate with the negated angle.

Return type:

Self

is_fully_specified() → bool

Check if all parameters have been specified.

Return type:

bool

is_identity(*, atol: float | None = 1e-12) → bool

Check for a numerically zero angle without expanding the gate.

Parameters:

atol (float | None) – Absolute tolerance for the rotation angle.

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, …]

name: str
property parameters: list[float | Parameter | ParameterExpression]

List of all parameters available.

property qubit_indices: tuple[int, ...]

Indices of the qubits that gate is working on.

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:

Gate

shift_by_one() → Self

Shift the gate’s qubit indices by one (+1).

Return type:

Self

static sorted_active_qubits(gates: Iterable[Gate]) → tuple[int, ...]

Return the active qubits in a sequence of gates, sorted, as a tuple.

Parameters:

gates (Iterable[Gate]) – Sequence of gates.

Return type:

tuple[int, …]

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

Assign parameters with the given float value.

Parameters:

parameter_value_pairs (dict[Parameter, float | ParameterExpression])

Return type:

Self

class SpinPreservingPairSeparationGate

Bases: SpinPreservingExcitationGate

Spin-preserving pair separation: split the pair in orbital \(i\) over orbitals \(a\) and \(b\).

Starting from orbital \(i\) doubly occupied and \(a, b\) empty, the gate mixes in the open-shell singlet with one electron in \(a\) and one in \(b\). In that singlet both spin assignments (alpha in \(a\) and beta in \(b\), or the reverse) appear with equal weight.

Separating a pair as a single double excitation needs the exponential of a sum of two double excitations. It cannot be built exactly from the existing excitation gates, and applying the two double excitations one after the other breaks spin preservation. This gate instead uses a circuit of four spin-preserving gates,

\[U(\theta) = R_{ab}(-\pi/4)\, D_{ai}(-\theta)\, D_{bi}(\theta)\, R_{ab}(\pi/4),\]

applied from right to left. Here \(R_{ab}\) is a SpinPreservingSingleExcitationGate and \(D_{ai}\) a DoubleFermionicExcitationGate moving the pair from \(i\) to \(a\). The surrounding rotations of \(a\) and \(b\) turn the difference of the two pair moves into the open-shell singlet.

The pair excitations keep their Jordan-Wigner parity strings. The QEB SpinPreservingPairExcitationGate would also preserve spin, but with an odd number of electrons between \(a\) and \(b\) the gate would then no longer separate the pair.

Every factor preserves spin, so the complete gate does too, for any spacing of the orbitals. To first order in \(\theta\) it equals the exponential of the fermionic pair-separation generator \(\hat{E}_{ai}\hat{E}_{bi} - \text{h.c.}\) with \(\hat{E}_{pq} = a_{p\alpha}^\dagger a_{q\alpha} + a_{p\beta}^\dagger a_{q\beta}\), but not beyond.

The gate cannot be inverted. Its inverse is not the gate with the negated angle, since the two pair excitations do not commute.

__init__(parameter: Parameter | ParameterExpression | float, creation_alpha_qubit_index_1: int, creation_beta_qubit_index_1: int, creation_alpha_qubit_index_2: int, creation_beta_qubit_index_2: int, annihilation_alpha_qubit_index: int, annihilation_beta_qubit_index: int) → None

Initialize a spin-preserving pair separation gate.

Parameters:
  • parameter (Parameter | ParameterExpression | float) – Parameter \(\theta\) of the gate.

  • creation_alpha_qubit_index_1 (int) – Qubit of spin orbital \(a\alpha\).

  • creation_beta_qubit_index_1 (int) – Qubit of spin orbital \(a\beta\).

  • creation_alpha_qubit_index_2 (int) – Qubit of spin orbital \(b\alpha\).

  • creation_beta_qubit_index_2 (int) – Qubit of spin orbital \(b\beta\).

  • annihilation_alpha_qubit_index (int) – Qubit of spin orbital \(i\alpha\).

  • annihilation_beta_qubit_index (int) – Qubit of spin orbital \(i\beta\).

Return type:

None

static active_qubits(gates: Iterable[Gate]) → set[int]

Return the active qubits in a sequence of gates.

Parameters:

gates (Iterable[Gate]) – Sequence of gates.

Return type:

set[int]

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() → list[Gate]

Flatten the gate into a list of primitive gates.

Return type:

list[Gate]

classmethod from_spatial_orbitals(parameter: Parameter | ParameterExpression | float, creation_orbital_1: int, creation_orbital_2: int, annihilation_orbital: int, number_of_spatial_orbitals: int) → Self

Create the gate on a block-spin register.

In a block-spin register \(p\alpha\) is qubit \(p\) and \(p\beta\) is qubit \(K + p\).

Parameters:
  • parameter (Parameter | ParameterExpression | float) – Parameter \(\theta\) of the gate.

  • creation_orbital_1 (int) – Spatial orbital \(a\).

  • creation_orbital_2 (int) – Spatial orbital \(b\).

  • annihilation_orbital (int) – Spatial orbital \(i\) holding the pair.

  • number_of_spatial_orbitals (int) – Number of spatial orbitals \(K\).

Return type:

Self

property gates: list[Gate]

List of gates that the composite gate is constructed from.

The list of gates are the immediate sub-gates that the composite gate is constructed from, not necessarily the primitive gates. To expand the gate down to primitive gates use the primitive_gates property instead.

invert() → Self

Raise, since the inverse is not a pair separation gate and could not be serialized.

Return type:

Self

is_fully_specified() → bool

Check if all parameters have been specified.

Return type:

bool

is_identity(*, atol: float | None = 1e-12) → bool

Check for a numerically zero angle without expanding the gate.

Parameters:

atol (float | None) – Absolute tolerance for the rotation angle.

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, …]

name: str
property parameters: list[float | Parameter | ParameterExpression]

List of all parameters available.

property qubit_indices: tuple[int, ...]

Indices of the qubits that gate is working on.

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:

Gate

shift_by_one() → Self

Shift the gate’s qubit indices by one (+1).

Return type:

Self

static sorted_active_qubits(gates: Iterable[Gate]) → tuple[int, ...]

Return the active qubits in a sequence of gates, sorted, as a tuple.

Parameters:

gates (Iterable[Gate]) – Sequence of gates.

Return type:

tuple[int, …]

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

Assign parameters with the given float value.

Parameters:

parameter_value_pairs (dict[Parameter, float | ParameterExpression])

Return type:

Self

class SpinPreservingSingleExcitationGate

Bases: SpinPreservingExcitationGate

Spin-preserving single excitation: move one electron from spatial orbital \(q\) to \(p\).

The electron keeps its spin. To treat both spins alike, the gate applies the same rotation to the alpha and the beta electrons,

\[U(\theta) = \mathrm{SFE}_{p\alpha, q\alpha}(\theta)\, \mathrm{SFE}_{p\beta, q\beta}(\theta) = e^{-\theta (\hat{E}_{pq} - \hat{E}_{qp})}, \qquad \hat{E}_{pq} = a_{p\alpha}^\dagger a_{q\alpha} + a_{p\beta}^\dagger a_{q\beta}.\]

This is an orbital rotation between \(p\) and \(q\), so it preserves the total spin. Rotating only one spin, or the two spins with different angles, generally does not.

Example: with orbital 0 doubly occupied and orbital 1 empty, the gate mixes in the states with one electron moved from orbital 0 to orbital 1, combined so that the result is still a singlet. Spin is preserved for any occupation of \(p\) and \(q\); the example only illustrates the effect.

Both SingleFermionicExcitationGate factors keep their Jordan-Wigner parity strings. These are needed when other orbitals lie between \(p\) and \(q\). Two SingleExcitationGate would then break spin preservation. For adjacent orbitals the strings are empty and each factor has the same 2-CNOT circuit as a SingleExcitationGate.

__init__(parameter: Parameter | ParameterExpression | float, creation_alpha_qubit_index: int, annihilation_alpha_qubit_index: int, creation_beta_qubit_index: int, annihilation_beta_qubit_index: int) → None

Initialize a spin-preserving single excitation gate.

Parameters:
  • parameter (Parameter | ParameterExpression | float) – Parameter \(\theta\) shared by the alpha and beta excitations.

  • creation_alpha_qubit_index (int) – Qubit of spin orbital \(p\alpha\).

  • annihilation_alpha_qubit_index (int) – Qubit of spin orbital \(q\alpha\).

  • creation_beta_qubit_index (int) – Qubit of spin orbital \(p\beta\).

  • annihilation_beta_qubit_index (int) – Qubit of spin orbital \(q\beta\).

Return type:

None

static active_qubits(gates: Iterable[Gate]) → set[int]

Return the active qubits in a sequence of gates.

Parameters:

gates (Iterable[Gate]) – Sequence of gates.

Return type:

set[int]

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() → list[Gate]

Flatten the gate into a list of primitive gates.

Return type:

list[Gate]

classmethod from_spatial_orbitals(parameter: Parameter | ParameterExpression | float, creation_orbital: int, annihilation_orbital: int, number_of_spatial_orbitals: int) → Self

Create the gate on a block-spin register.

In a block-spin register \(p\alpha\) is qubit \(p\) and \(p\beta\) is qubit \(K + p\).

Parameters:
  • parameter (Parameter | ParameterExpression | float) – Parameter \(\theta\) of the gate.

  • creation_orbital (int) – Spatial orbital \(p\).

  • annihilation_orbital (int) – Spatial orbital \(q\).

  • number_of_spatial_orbitals (int) – Number of spatial orbitals \(K\).

Return type:

Self

property gates: list[Gate]

List of gates that the composite gate is constructed from.

The list of gates are the immediate sub-gates that the composite gate is constructed from, not necessarily the primitive gates. To expand the gate down to primitive gates use the primitive_gates property instead.

invert() → Self

Get the inverse of the gate, which is the gate with the negated angle.

Return type:

Self

is_fully_specified() → bool

Check if all parameters have been specified.

Return type:

bool

is_identity(*, atol: float | None = 1e-12) → bool

Check for a numerically zero angle without expanding the gate.

Parameters:

atol (float | None) – Absolute tolerance for the rotation angle.

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, …]

name: str
property parameters: list[float | Parameter | ParameterExpression]

List of all parameters available.

property qubit_indices: tuple[int, ...]

Indices of the qubits that gate is working on.

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:

Gate

shift_by_one() → Self

Shift the gate’s qubit indices by one (+1).

Return type:

Self

static sorted_active_qubits(gates: Iterable[Gate]) → tuple[int, ...]

Return the active qubits in a sequence of gates, sorted, as a tuple.

Parameters:

gates (Iterable[Gate]) – Sequence of gates.

Return type:

tuple[int, …]

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

Assign parameters with the given float value.

Parameters:

parameter_value_pairs (dict[Parameter, float | ParameterExpression])

Return type:

Self

expand_spin_preserving_excitation_gates(gates: Iterable[Gate]) → list[Gate]

Replace spin-preserving excitation gates by the excitation gates they consist of.

Other gates are kept as they are.

Parameters:

gates (Iterable[Gate]) – Gates to expand.

Return type:

list[Gate]