quri_parts.openfermion.transforms package#

OpenFermionQubitOperatorMapper#

Interface for a function that maps a openfermion.ops.FermionOperator, openfermion.ops.InteractionOperator or openfermion.ops.MajoranaOperator to a Operator.

alias of Callable[[Union[FermionOperator, InteractionOperator, MajoranaOperator]], Operator]

class OpenFermionQubitMapping(n_spin_orbitals, n_fermions=None, sz=None)#

Bases: FermionQubitMapping, ABC

Mapping object that holds the configuration of a state you want to transform or act operators onto. Operator mapper, state mapper and inverse state mapper are retrieved as properties.

Parameters:
  • n_spin_orbitals (int) – The number of spin orbitals to be mapped to qubits.

  • n_fermions (Optional[int]) – When specified, restrict the mapping to a subspace spanned by states containing the fixed number of Fermions. Some mappings require this argument (e.g. symmetry-conserving Bravyi-Kitaev transformation) while the others ignore it.

  • sz (Optional[float]) – The spin along the z-axis of the state you want to transform. Some mappings require this argument (e.g. symmetry-conserving Bravyi-Kitaev transformation) while the others ignore it.

property n_spin_orbitals: int#

Number of spin orbitals this mapping object works with.

property n_fermions: int | None#
property sz: float | None#
abstract property of_operator_mapper: openfermion.transforms.OpenFermionQubitOperatorMapper#

Returns a function that maps an OpenFermion FermionOperator, InteractionOperator or MajoranaOperator to a openfermion.ops.QubitOperator.

property state_mapper: chem.transforms.FermionQubitStateMapper#

Returns a function that maps occupied spin orbital indices to a computational basis state of qubits.

property inv_state_mapper: chem.transforms.QubitFermionStateMapper#

Returns a function that maps a computational basis state of qubits to the set of occupied spin orbital indices.

class OpenFermionQubitMapperFactory(*args, **kwargs)#

Bases: FermionQubitMapperFactory

Mapping from Fermionic operators and states to :class:`Operator`s and states using OpenFermion.

get_of_operator_mapper(n_spin_orbitals, n_fermions=None, sz=None)#

Returns a function that maps an OpenFermion FermionOperator, InteractionOperator or MajoranaOperator to a openfermion.ops.QubitOperator.

Parameters:
  • n_spin_orbitals (int) – The number of spin orbitals to be mapped to qubits.

  • n_fermions (int | None) – When specified, restrict the mapping to a subspace spanned by states containing the fixed number of Fermions. Some mappings require this argument (e.g. symmetry-conserving Bravyi-Kitaev transformation) while the others ignore it.

  • sz (float | None) – The spin along the z-axis of the state you want to transform. Some mappings require this argument (e.g. symmetry-conserving Bravyi-Kitaev transformation) while the others ignore it.

Return type:

openfermion.transforms.OpenFermionQubitOperatorMapper

get_state_mapper(n_spin_orbitals, n_fermions=None, sz=None)#

Returns a function that maps occupied spin orbital indices to a computational basis state of qubits.

Parameters:
  • n_spin_orbitals (int) – The number of spin orbitals to be mapped to qubits.

  • n_fermions (int | None) – When specified, restrict the mapping to a subspace spanned by states containing the fixed number of Fermions. Some mappings require this argument (e.g. symmetry-conserving Bravyi-Kitaev transformation) while the others ignore it.

  • sz (float | None) – The spin along the z-axis of the state you want to transform. Some mappings require this argument (e.g. symmetry-conserving Bravyi-Kitaev transformation) while the others ignore it.

Return type:

chem.transforms.FermionQubitStateMapper

get_inv_state_mapper(n_spin_orbitals, n_fermions=None, sz=None)#

Returns a function that maps computational basis state of qubits to an occupied spin orbital indices.

Parameters:
  • n_spin_orbitals (int) – The number of spin orbitals to be mapped to qubits.

  • n_fermions (int | None) – When specified, restrict the mapping to a subspace spanned by states containing the fixed number of Fermions. Some mappings require this argument (e.g. symmetry-conserving Bravyi-Kitaev transformation) while the others ignore it.

  • sz (float | None) – The spin along the z-axis of the state you want to transform. Some mappings require this argument (e.g. symmetry-conserving Bravyi-Kitaev transformation) while the others ignore it.

Return type:

chem.transforms.QubitFermionStateMapper

class OpenFermionJordanWigner(n_spin_orbitals, n_fermions=None, sz=None)#

Bases: JordanWigner, OpenFermionQubitMapping

Jordan-Wigner transformation using OpenFermion.

Parameters:
  • n_spin_orbitals (int) – The number of spin orbitals to be mapped to qubits.

  • n_fermions (Optional[int]) – This is not used in the transformation thus being ignored.

  • sz (Optional[float]) – This is not used in the transformation thus being ignored.

property of_operator_mapper: openfermion.transforms.OpenFermionQubitOperatorMapper#

Returns a function that maps a FermionOperator, InteractionOperator or MajoranaOperator to a openfermion.ops.QubitOperator with Jordan-Wigner transformation.

class OpenFermionJordanWignerFactory#

Bases: JordanWignerMapperFactory, OpenFermionQubitMapperFactory

Jordan-Wigner transformation using OpenFermion.

jordan_wigner = <quri_parts.openfermion.transforms.OpenFermionJordanWignerFactory object>#

An object that performs Jordan-Wigner mapping in various ways.

Example

You may create mappers out of jordan_wigner

>>> operator_mapper = jordan_wigner.get_of_operator_mapper(8)
>>> operator_mapper(FermionOperator("1^ 1"))
(0.5+0j)*I + (-0.5+0j)*Z1
>>> state_mapper = jordan_wigner.get_state_mapper(8)
>>> state_mapper([0, 1])
ComputationalBasisState(qubit_count=8, bits=0b11, phase=0π/2)
>>> inv_state_mapper = jordan_wigner.get_inv_state_mapper(8)
>>> inv_state_mapper(ComputationalBasisState(8, bits=0b11))
[0, 1]

You may create a mapping object with specified number of spin orbials.

>>> jw_mapping = jordan_wigner(8)
>>> operator_mapper = jw_mapping.of_operator_mapper
>>> operator_mapper(FermionOperator("1^ 1"))
(0.5+0j)*I + (-0.5+0j)*Z1
>>> state_mapper = jw_mapping.state_mapper
>>> state_mapper([0, 1])
ComputationalBasisState(qubit_count=8, bits=0b11, phase=0π/2)
>>> inv_state_mapper = jw_mapping.inv_state_mapper
>>> inv_state_mapper(ComputationalBasisState(8, bits=0b11))
[0, 1]
Parameters:
  • n_spin_orbitals (int) –

  • n_fermions (Optional[int]) –

  • sz (Optional[float]) –

Return type:

OpenFermionQubitMapping

class OpenFermionBravyiKitaev(n_spin_orbitals, n_fermions=None, sz=None)#

Bases: BravyiKitaev, OpenFermionQubitMapping

Bravyi-Kitaev transformation using OpenFermion.

Parameters:
  • n_spin_orbitals (int) – The number of spin orbitals to be mapped to qubits.

  • n_fermions (Optional[int]) – This is not used in the transformation thus being ignored.

  • sz (Optional[float]) – This is not used in the transformation thus being ignored.

property of_operator_mapper: openfermion.transforms.OpenFermionQubitOperatorMapper#

Returns a function that maps a FermionOperator, InteractionOperator or MajoranaOperator to a openfermion.ops.QubitOperator with Bravyi-Kitaev transformation.

class OpenFermionBravyiKitaevFactory#

Bases: BravyiKitaevMapperFactory, OpenFermionQubitMapperFactory

Bravyi-Kitaev transformation using OpenFermion.

bravyi_kitaev = <quri_parts.openfermion.transforms.OpenFermionBravyiKitaevFactory object>#

An object that performs Bravyi-Kitaev mapping in various ways.

Example

You may create mappers out of bravyi_kitaev

>>> operator_mapper = bravyi_kitaev.get_of_operator_mapper(8)
>>> print(operator_mapper(FermionOperator("1^ 1")))
(0.5+0j)*I + (-0.5+0j)*Z0 Z1
>>> state_mapper = bravyi_kitaev.get_state_mapper(8)
>>> state_mapper([0, 1])
ComputationalBasisState(qubit_count=8, bits=0b1, phase=0π/2)
>>> inv_state_mapper = bravyi_kitaev.get_inv_state_mapper(8)
>>> inv_state_mapper(ComputationalBasisState(8, bits=0b10111))
[0, 2, 4, 5]

You may create a mapping object with specified number of spin orbials.

>>> bk_mapping = bravyi_kitaev(8)
>>> operator_mapper = bk_mapping.of_operator_mapper
>>> print(operator_mapper(FermionOperator("1^ 1")))
(0.5+0j)*I + (-0.5+0j)*Z0 Z1
>>> state_mapper = bk_mapping.state_mapper
>>> state_mapper([0, 1])
ComputationalBasisState(qubit_count=8, bits=0b1, phase=0π/2)
>>> inv_state_mapper = bk_mapping.inv_state_mapper
>>> inv_state_mapper(ComputationalBasisState(8, bits=0b10111))
[0, 2, 4, 5]
Parameters:
  • n_spin_orbitals (int) –

  • n_fermions (Optional[int]) –

  • sz (Optional[float]) –

Return type:

OpenFermionQubitMapping

class OpenFermionSymmetryConservingBravyiKitaev(n_spin_orbitals, n_fermions=None, sz=None)#

Bases: SymmetryConservingBravyiKitaev, OpenFermionQubitMapping

Symmetry-conserving Bravyi-Kitaev transformation described in arXiv:1701.08213, using OpenFermion.

Note that in this mapping the spin orbital indices are first reordered to all spin-up orbitals, then all spin-down orbitals. Bravyi-Kitaev transoformation is applied after the reordering and then two qubits are dropped using conservation of particle number and spin.

Any operators which don’t have particle number and spin symmetry are converted to Operator(), whose expectation value is zero for all states.

Parameters:
  • n_spin_orbitals (int) – The number of spin orbitals to be mapped to qubits.

  • n_fermions (Optional[int]) – The number of fermions the state should contain.

  • sz (Optional[float]) – Spin along the z-axis of the state. Currently, only sz = 0 and 0.5 are supported.

property of_operator_mapper: openfermion.transforms.OpenFermionQubitOperatorMapper#

Returns a function that maps a FermionOperator, InteractionOperator or MajoranaOperator to a openfermion.ops.QubitOperator with symmetry-conserving Bravyi-Kitaev transformation.

Both the arguments (n_spin_orbitals and n_fermions) are required.

class OpenFermionSymmetryConservingBravyiKitaevFactory#

Bases: SymmetryConservingBravyiKitaevMapperFactory, OpenFermionQubitMapperFactory

Symmetry-conserving Bravyi-Kitaev transformation described in arXiv:1701.08213, using OpenFermion.

Note that in this mapping the spin orbital indices are first reordered to all spin-up orbitals, then all spin-down orbitals. Bravyi-Kitaev transoformation is applied after the reordering and then two qubits are dropped using conservation of particle number and spin.

Any operators which don’t have particle number and spin symmetry are converted to Operator(), whose expectation value is zero for all states.

symmetry_conserving_bravyi_kitaev = <quri_parts.openfermion.transforms.OpenFermionSymmetryConservingBravyiKitaevFactory object>#

An object that performs spin-symmetric Bravyi-Kitaev mapping in various ways.

Example

You may create mappers out of symmetry_conserving_bravyi_kitaev

>>> scbk = symmetry_conserving_bravyi_kitaev
>>> operator_mapper = scbk.get_of_operator_mapper(8, 4, 0)
>>> print(operator_mapper(FermionOperator("1^ 1")))
0.5*I + -0.5*Z3
>>> state_mapper = scbk.get_state_mapper(8, 4, 0)
>>> state_mapper([0, 1, 2, 3])
ComputationalBasisState(qubit_count=6, bits=0b1001, phase=0π/2)
>>> inv_state_mapper = scbk.get_inv_state_mapper(8, 4, 0)
>>> inv_state_mapper(ComputationalBasisState(qubit_count=6, bits=0b1001))
[0, 1, 2, 3]

You may create a mapping object with specified number of spin orbials, number of electrons and sz of the state.

>>> scbk_mapping = scbk(8, 4, 0)
>>> operator_mapper = scbk_mapping.of_operator_mapper
>>> print(operator_mapper(FermionOperator("1^ 1")))
0.5*I + -0.5*Z3
>>> state_mapper = scbk_mapping.state_mapper
>>> state_mapper([0, 1, 2, 3])
ComputationalBasisState(qubit_count=6, bits=0b1001, phase=0π/2)
>>> inv_state_mapper = scbk_mapping.inv_state_mapper
>>> inv_state_mapper(ComputationalBasisState(qubit_count=6, bits=0b1001))
[0, 1, 2, 3]
Parameters:
  • n_spin_orbitals (int) –

  • n_fermions (Optional[int]) –

  • sz (Optional[float]) –

Return type:

OpenFermionQubitMapping