pauliarray.mapping package#

Submodules#

pauliarray.mapping.fermion module#

class pauliarray.mapping.fermion.BravyiKitaev(num_qubits: int)[source]#

Bases: FermionMapping

__init__(num_qubits: int)[source]#

Initialize the Bravyi-Kitaev mapping for a given number of qubits. Maps fermionic operators to qubit operators.

Parameters:

num_qubits (int) – The number of qubits to be used in the mapping.

_build_bravyi_kitaev_mapping_matrix(num_qubits: int) np.ndarray[np.bool][source]#

Constructs the Bravyi-Kitaev mapping matrix for the given number of qubits.

Parameters:

num_qubits (int) – The number of qubits.

Returns:

The Bravyi-Kitaev mapping matrix.

Return type:

“np.ndarray[np.bool]”

class pauliarray.mapping.fermion.FermionMapping(mapping_matrix: np.ndarray[np.bool], name: str = 'mapping')[source]#

Bases: object

Base class to represent a Fermion-to-qubit mapping.

mapping_matrix#

A boolean numpy array representing the mapping matrix.

Type:

“np.ndarray[np.bool]”

name#

A name identifier for the mapping (default is “mapping”).

Type:

str

_mapping_matrix_inv#

The inverse of the mapping matrix, initially None

Type:

“np.ndarray[np.bool]”, optional

and computed on demand.
_heavyside_matrix#

The Heavyside matrix, initially None and computed

Type:

“np.ndarray[np.bool]”, optional

on demand.
_parity_matrix#

The parity matrix, initially None and computed on demand.

Type:

“np.ndarray[np.bool]”, optional

__init__(mapping_matrix: np.ndarray[np.bool], name: str = 'mapping')[source]#

Constructs all the necessary attributes for the FermionMapping object.

Parameters:
  • mapping_matrix – “np.ndarray[np.bool]” A boolean numpy array representing the mapping matrix.

  • name – str, optional A name identifier for the mapping (default is “mapping”).

static _flip_factors(i_orbitals: np.ndarray[np.int], j_orbitals: np.ndarray[np.int], *args: Tuple[np.ndarray[np.int]]) ndarray[Any, dtype[float64]][source]#

Computes flip factors of the type

\[f_\mu = (-1)^{\delta_{i_\mu j_\mu} + \delta_{i_\mu k_\mu} + \ldots}.\]
Parameters:
  • i_orbitals ("np.ndarray[np.int]") – The indices of the orbital i the operator is acting on.

  • j_orbitals ("np.ndarray[np.int]") – The indices of the orbital i the operator is acting on.

  • etc...

Returns:

The factors.

Return type:

NDArray[float]

_flip_operators(i_orbitals: np.ndarray[np.int], factors: ndarray[Any, dtype[float64]]) OperatorArrayType1[source]#

Constructs an OperatorArray with the \(\mu^\text{th}\) flip operators acting on the orbitals \(i_\mu\)

\[\hat{F}_\mu = \frac{1}{2}(1 + f_\mu \hat{Z}_q^{[\mathsf{M}^{-1}]_{i_\mu q}]})\]

where \(f_\mu\) is a factor (+1 or -1) associted with the creation and annihilation operators.

Parameters:
  • i_orbitals (NDArray[int]) – The indices of the orbital i the operator is acting on

  • factors (NDArray[float]) – The factors (+1 or -1) defining if a creation or an annihilation operator is

  • applied.

Returns:

The array of flip operators.

Return type:

OperatorArrayType1

_update_factors(i_orbitals: np.ndarray[np.int], j_orbitals: np.ndarray[np.int], *args: Tuple[np.ndarray[np.int]]) ndarray[Any, dtype[float64]][source]#

Computes update factors of the type

\[f_\mu = (-1)^{\theta_{i_\mu j_\mu} - \theta_{j_\mu i_\mu} + \ldots}.\]
Parameters:
  • i_orbitals ("np.ndarray[np.int]") – The indices of the orbital i the operator is acting on.

  • j_orbitals ("np.ndarray[np.int]") – The indices of the orbital i the operator is acting on.

  • etc...

Returns:

The factors.

Return type:

NDArray[float]

_update_operators(i_orbitals: np.ndarray[np.int], j_orbitals: np.ndarray[np.int], *args: Tuple[np.ndarray[np.int]]) OperatorArrayType1[source]#

Updates the operators based on the given orbitals, using the Heaviside matrix, the inverse mapping matrix, and the transposed mapping matrix. The function processes the input orbitals to generate updated Z and X strings, used to create new Pauli operators.

Parameters:
  • i_orbitals ("np.ndarray[np.int]") – The first set of orbitals.

  • j_orbitals ("np.ndarray[np.int]") – The second set of orbitals.

  • *args (Tuple["np.ndarray[np.int]"]) – Additional sets of orbitals.

Returns:

The updated operators as an OperatorArrayType1 object.

Return type:

opa.OperatorArrayType1

_update_operators_2(i_orbitals: np.ndarray[np.int], j_orbitals: np.ndarray[np.int]) OperatorArrayType1[source]#

Constructs an OperatorArray with the \(\mu^\text{th}\) main operators acting on the orbitals \(i_\mu\) and \(j_\mu\) in a one-body fermionic operator

\[\hat{U}^{(2)}_{\mu} = (-1)^{\theta_{i_\mu j_ \mu}} \hat{X}_q^{M_{qi_\mu} + M_{qj_\mu}}.\]
Parameters:
  • i_orbitals (NDArray[int]) – The indices of the orbital i the operator is acting on.

  • j_orbitals (NDArray[int]) – The indices of the orbital j the operator is acting on.

Returns:

The array of operators.

Return type:

OperatorArrayType1

_update_operators_4(i_orbitals: np.ndarray[np.int], j_orbitals: np.ndarray[np.int], k_orbitals: np.ndarray[np.int], l_orbitals: np.ndarray[np.int]) OperatorArrayType1[source]#

Constructs an OperatorArray with the \(\mu^\text{th}\) main operators acting on the orbitals \(i_\mu\), \(j_\mu\), \(k_\mu\) and \(l_\mu\) in a two-body fermionic operator.

\[(-1)^{\theta_{ij} + \theta_{i_\mu k_\mu} + \theta_{i_\mu l_\mu} + \theta_{j_\mu k_\mu} + \theta_{j_\mu l_\mu} + \theta_{k_\mu l_\mu}} \hat{X}_q^{M_{qi_\mu} + M_{qj_\mu} + M_{qk_\mu} + M_{ql_\mu}} \hat{Z}_q^{(\theta_{i_\mu p} + \theta_{j_\mu p} + \theta_{k_\mu p} + \theta_{l_\mu p})[\mathsf{M}^{-1}]_{pq}}\]
Parameters:
  • i_orbitals (NDArray[int]) – The indices of the orbital i the operator is acting on.

  • j_orbitals (NDArray[int]) – The indices of the orbital j the operator is acting on.

  • k_orbitals (NDArray[int]) – The indices of the orbital k the operator is acting on.

  • l_orbitals (NDArray[int]) – The indices of the orbital l the operator is acting on.

Returns:

The array of operators.

Return type:

OperatorArrayType1

assemble_creation_annihilation_operators() Tuple[OperatorArrayType1, OperatorArrayType1][source]#

Constructs the creation and annihilation operators for all available states and returns them as OperatorArrays.

Returns:

The creation operators OperatorArrayType1: The annihilation operators

Return type:

OperatorArrayType1

assemble_one_body_operator_array() OperatorArrayType1[source]#

Assembles an array of one-body operators.

Returns:

An operator array of one-body operators.

Return type:

opa.OperatorArrayType1

assemble_qubit_hamiltonian_from_arrays(one_body: np.ndarray[np.complex], two_body: np.ndarray[np.complex]) Operator[source]#

Assemble the whole qubit Hamiltonian as an Operator using fermionic integrals given as arrays.

Parameters:
  • one_body ("np.ndarray[np.complex]") – The one-body fermionic integrals as a 2d array

  • two_body ("np.ndarray[np.complex]") – The two-body fermionic integrals as a 4d array (in physicist order)

Returns:

The qubit Hamiltonia

Return type:

Operator

assemble_qubit_hamiltonian_from_sparses(one_body_tuple: Tuple, two_body_tuple: Tuple) Operator[source]#

Assemble the whole qubit Hamiltonian as an Operator using fermionic integrals given in sparse representations.

Parameters:
  • one_body_tuple (Tuple) – Contains the argument for the one_body_operator_from_sparse method.

  • two_body_tuple (Tuple) – Contains the argument for the two_body_operator_from_sparse method.

Returns:

The qubit Hamiltonian

Return type:

op.Operator

assemble_two_body_operator_array() OperatorArrayType1[source]#

Assembles an array of two-body operators.

Returns:

An operator array of two-body operators.

Return type:

opa.OperatorArrayType1

property heavyside_matrix: np.ndarray[np.bool]#

Returns the Heavyside matrix. Computes it if not already computed.

Returns:

The Heavyside matrix.

Return type:

“np.ndarray[np.bool]”

majoranas() Tuple[PauliArray, PauliArray][source]#

In a fermion-to-qubit mapping, each creation/annihilation operator is a sum of two majorana operators,

\[0.5 * (P_\text{real} + P_\text{imag})\]

each being a Pauli string. This methods construct these majorana operators.

Returns:

The Pauli strings for \(P_\text{real}\) PauliArray: The Pauli strings for \(P_\text{imag}\)

Return type:

PauliArray

property mapping_matrix_inv#

Returns the inverse of the mapping matrix. Computes it if not already computed.

Returns:

The inverse of the mapping matrix.

Return type:

“np.ndarray[np.bool]”

property num_qubits: int#

Returns the number of qubits based on the shape of the mapping matrix.

Returns:

The number of qubits.

Return type:

int

occupation_operators() OperatorArrayType1[source]#

Constructs the occupation operators for all available states and returns them as OperatorArray.

Returns:

An Operator array with all the occupation operators.

Return type:

opa.OperatorArrayType1

one_body_operator_from_array(one_body: np.ndarray[np.complex]) Operator[source]#

Converts a one-body array to an operator object.

Parameters:

one_body ("np.ndarray[np.complex]") – A complex numpy array representing the one-body operator.

Returns:

The corresponding operator object.

Return type:

op.Operator

Raises:
  • AssertionError. If the input array is not 2-dimensional or if its dimensions do not match the

  • number of qubits.

one_body_operator_from_sparse(locations: List[np.ndarray[np.int]], values: np.ndarray[np.complex], signs: List[int] | np.ndarray[np.int] | List[np.ndarray[np.int]] = (1, -1)) Operator[source]#

Assemble a one body fermionic operator as an Operator using fermionic integrals given in sparse representations.

Parameters:
  • locations (List["np.ndarray[np.int]"]) – Pairs of orbital indices

  • values ("np.ndarray[np.complex]") – Values of the integral for the pairs of orbitals

  • signs (the operators are creation or annihilation. Can be a list of two) – Values +1 or -1 determining if

  • signs

  • sign. (or two arrays of)

  • [1 (Defaults to)

  • -1].

Returns:

The qubit operator

Return type:

op.Operator

property parity_matrix: np.ndarray[np.bool]#

Returns the parity matrix. Computes it if not already computed.

Returns:

The parity matrix.

Return type:

“np.ndarray[np.bool]”

two_body_operator_from_array(two_body: np.ndarray[np.complex]) Operator[source]#

Converts a two-body array to an operator object.

Parameters:

two_body ("np.ndarray[np.complex]") – A complex numpy array representing the two-body operator.

Returns:

The corresponding operator object.

Return type:

op.Operator

Raises:
  • AssertionError. If the input array's dimensions do not match the number of qubits or if it does not satisfy

  • the required symmetries.

two_body_operator_from_sparse(locations: List[np.ndarray[np.int]], values: np.ndarray[np.complex], signs: List[int] | np.ndarray[np.int] | List[np.ndarray[np.int]] = (1, 1, -1, -1)) Operator[source]#

Assemble a two-body fermionic operator as an Operator using fermionic integrals given in sparse representations.

Parameters:
  • locations (List["np.ndarray[np.int]"]) – Quartet of orbital indices

  • values ("np.ndarray[np.complex]") – Values of the integral for the quartets of orbitals

  • signs (the operators are creation or annihilation. Can be a list of two) – Values +1 or -1 determining if

  • signs

  • sign. (or two arrays of)

  • [+1 (Defaults to)

  • +1

  • -1

  • -1].

Returns:

The qubit operator

Return type:

op.Operator

class pauliarray.mapping.fermion.JordanWigner(num_qubits: int)[source]#

Bases: FermionMapping

__init__(num_qubits: int)[source]#

Initializes the Jordan-Wigner mapping for a given number of qubits. Maps fermionic operators to qubit operators.

Parameters:

num_qubits (int) – The number of qubits to be used in the mapping.

class pauliarray.mapping.fermion.Parity(num_qubits: int)[source]#

Bases: FermionMapping

__init__(num_qubits: int)[source]#

Initializes the Parity mapping for a given number of qubits. Maps fermionic operators to qubit operators.

Parameters:

num_qubits (int) – The number of qubits to be used in the mapping.

Module contents#

Mapping module. Implements mapping of operators into qubit operators.