Fermion-qubit mappings
In order to simulate the dynamics of physical systems with a quantum computer, it is necessary to map the Hamiltonian of an electron to the qubit counterpart. Hamiltonians for fermionic systems, as typically used in quantum chemistry, are often expressed using anti-commuting creation and annihilation operators: , under second quantization. If we can rewrite the creation and annihilation operators as Pauli operators that can act on qubits, we can represent them on a quantum computer.
Here, , satisfy the anti-commutation relations:
and , denote the label of degree of freedom the operator acts on.
Fermionic wavefunctions exhibit antisymmetry, but when mapping directly from spin orbitals to qubits on a quantum computer, where the presence of an electron in a spin orbital is represented as and the absence as , this antisymmetry is not maintained. This discrepancy arises because electrons are indistinguishable particles, whereas qubits are distinguishable. To correctly emulate the behavior of fermions, several mapping techniques have been developed that preserve the necessary anti-commutation relations.
In this tutorial, we explain how to perform mapping from OpenFermion
's FermionOperator
to QURI Parts Operator
, where we provide 3 types of mapping:
- Jordan-Wigner mapping
- Bravyi-Kitaev mapping
- Symmetry-conserving Bravyi-Kitaev mapping
Prerequisite
QURI Parts modules used in this tutorial: quri-parts-core
, and quri-parts-openfermion
. You can install them as follows:
!pip install "quri_parts[openfermion]"
Requirement already satisfied: quri_parts[openfermion] in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (0.20.3)
``````output
Requirement already satisfied: quri-parts-algo in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from quri_parts[openfermion]) (0.20.3)
Requirement already satisfied: quri-parts-chem in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from quri_parts[openfermion]) (0.20.3)
Requirement already satisfied: quri-parts-circuit in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from quri_parts[openfermion]) (0.20.3)
Requirement already satisfied: quri-parts-core in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from quri_parts[openfermion]) (0.20.3)
Requirement already satisfied: quri-parts-openfermion in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from quri_parts[openfermion]) (0.20.3)
Requirement already satisfied: scipy<2.0.0,>=1.9.1 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from quri-parts-algo->quri_parts[openfermion]) (1.11.4)
Requirement already satisfied: typing-extensions<5.0.0,>=4.1.1 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from quri-parts-algo->quri_parts[openfermion]) (4.12.2)
Requirement already satisfied: numpy>=1.22.0 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from quri-parts-circuit->quri_parts[openfermion]) (1.26.4)
Requirement already satisfied: quri-parts-rust in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from quri-parts-circuit->quri_parts[openfermion]) (0.20.2)
Requirement already satisfied: networkx in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from quri-parts-core->quri_parts[openfermion]) (3.4.2)
Requirement already satisfied: openfermion<2.0.0,>=1.5.1 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from quri-parts-openfermion->quri_parts[openfermion]) (1.6.1)
Requirement already satisfied: cirq-core~=1.0 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (1.4.1)
Requirement already satisfied: deprecation in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (2.1.0)
Requirement already satisfied: h5py>=2.8 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (3.12.1)
Requirement already satisfied: pubchempy in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (1.0.4)
Requirement already satisfied: requests>=2.18 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (2.32.3)
``````output
Requirement already satisfied: sympy in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (1.13.3)
Requirement already satisfied: attrs>=21.3.0 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (24.2.0)
Requirement already satisfied: duet>=0.2.8 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (0.2.9)
Requirement already satisfied: matplotlib~=3.0 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (3.9.2)
Requirement already satisfied: pandas in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (2.2.3)
Requirement already satisfied: sortedcontainers~=2.0 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (2.4.0)
``````output
Requirement already satisfied: tqdm in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (4.66.5)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from requests>=2.18->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (3.4.0)
Requirement already satisfied: idna<4,>=2.5 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from requests>=2.18->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from requests>=2.18->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (2.2.3)
Requirement already satisfied: certifi>=2017.4.17 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from requests>=2.18->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (2024.8.30)
Requirement already satisfied: packaging in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from deprecation->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (24.1)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from sympy->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (1.3.0)
``````output
Requirement already satisfied: contourpy>=1.0.1 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (1.3.0)
Requirement already satisfied: cycler>=0.10 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (4.54.1)
Requirement already satisfied: kiwisolver>=1.3.1 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (1.4.7)
Requirement already satisfied: pillow>=8 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (11.0.0)
Requirement already satisfied: pyparsing>=2.3.1 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (3.2.0)
Requirement already satisfied: python-dateutil>=2.7 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (2.9.0.post0)
``````output
Requirement already satisfied: pytz>=2020.1 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from pandas->cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (2024.2)
Requirement already satisfied: tzdata>=2022.7 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from pandas->cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (2024.2)
``````output
Requirement already satisfied: six>=1.5 in /home/drokles/.cache/pypoetry/virtualenvs/quri-sdk-notebooks-l1kMe6Lz-py3.11/lib/python3.11/site-packages (from python-dateutil>=2.7->matplotlib~=3.0->cirq-core~=1.0->openfermion<2.0.0,>=1.5.1->quri-parts-openfermion->quri_parts[openfermion]) (1.16.0)
``````output
[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m A new release of pip is available: [0m[31;49m24.0[0m[39;49m -> [0m[32;49m24.3.1[0m
[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m To update, run: [0m[32;49mpip install --upgrade pip[0m
Overview
Here we set up a Fermi-Hubbard hamiltonian for demonstration:
from openfermion import fermi_hubbard
n_site = 2
hamiltonian = fermi_hubbard(x_dimension=n_site, y_dimension=1, tunneling=1, coulomb=2)
print("Fermi-Hubbard Hamiltonian:")
print(hamiltonian)
Fermi-Hubbard Hamiltonian:
2.0 [0^ 0 1^ 1] +
-1.0 [0^ 2] +
-1.0 [1^ 3] +
-1.0 [2^ 0] +
2.0 [2^ 2 3^ 3] +
-1.0 [3^ 1]
where ^ denotes and denotes in [・]. For example, [0^ 2] denotes . Note that this is a Hamiltonian written in the form of second quantization.
In QURI Parts, we provide mapping objects that generates:
-
OpenFermion
operator mapper: a function that mapsopenfermion.ops.FermionOperator
openfermion.ops.InteractionOperator
openfermion.ops.MajoranaOperator
to QURI Parts
Operator
. -
state mapper: A function that maps the occupation number state: