Quantum SDK Interop#

Various software development kits implement some form of Fermion-qubit encoding. To interface with these, it is easiest to transform the outputs of ferrmion to the native format of the SDK.

The two main formats that you are likely to need are dictionary format Pauli-string Hamiltonians, which are obtained from ferrmion.hamiltonian functions, or the fill_template function where a template has been used:

from ferrmion.hamiltonians import molecular_hamiltonian, hubbard_hamiltonian
...

ferrmion_qham: dict[str, float] = molecular_hamiltonian(encoding, ones, twos, constant)

and even fermionic operators, obtained from .number_opertor, .edge_operator and ferrmion.encode.base.double_fermionic_operator

from ferrmion.encode.base import double_fermionic_operator
from ferrmion.encode import JordanWigner
encoding = JordanWigner(4)

n_0 = encoding.number_operator(0)
edge_0_2 = encoding.edge_operator((0,2))
create_0_create_1 = double_fermionic_operator(encoding, (0,1), "++")

Qiskit-Nature#

Optional dependencies for qiskit can be installed with

pip install ferrmion[qiskit]

Once you’ve done this, any FermionQubitEncoding can be converted to a QubitMapper (see qiskit_nature.second_q.mappers).

Defines the interface to Qiskit-Nature.

class ferrmion.interop.qiskit_mapper.QiskitAdapter(encoding: FermionQubitEncoding)[source]#

Bases: FermionicMapper

Wrapper class enabling the use of ferrmion in qiskit.

In qiskit_nature, encodings are handled by a general QubitMapper class, and a FermionMapper for Fermion to Qubit encodings.

These classes have an abstract method _map_single which transforms a single qiskit operator into a qiskit.SparsePauliOp.

NOTE: You must have installed the optional dependencies with

pip install ferrmion[qiskit] for this functionality to be available.

Example: >>> from ferrmion.encode import JordanWigner >>> from ferrmion.interop.qiskit import QiskitAdapter >>> from qiskit_nature.second_q.operators import FermionOp >>> fop = FermionicOp( >>> { >>> “+_0 -_0”: 1.0, >>> “+_1 -_1”: -1.0, >>> }, >>> num_spin_orbitals=2, >>> ) >>> mapper = QiskitAdapter(JordanWigner(2)) >>> mapper.map(fop)

)

Qiskit#

Operators defined in ferrmion can be used in the core qiskit package by creating a SparsePauliOp

from qiskit.circuit.library import SparsePauliOp
from ferrmion.hamiltonians import molecular_hamiltonian

qham = molecular_hamiltonian(encoding, ones, twos, constant)
qiskit_op = SparsePauliOp.from_list([(k, v) for k,v in qham.items()])

Symmer#

The main operator type in Symmer which is relevant is the PauliWordOp. This can be generated straightforwardly from ferrmion by creating a dict mapping pauli operators to coefficients.

from symmer import PauliWordOp
from ferrmion.hamiltonians import molecular_hamiltonian

qham = molecular_hamiltonian(encoding, ones, twos, constant)
pwop = PauliWordOp.from_dict(qham)