Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ternary Tree Mapper #1313

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7d1134d
Add MajoranaOp class
grossardt Nov 11, 2023
08e0983
Merge branch 'main' into addfeature-majoranaop-issue1257
grossardt Nov 12, 2023
812653e
Merge branch 'main' into addfeature-majoranaop-issue1257
grossardt Nov 14, 2023
922eca3
New style of MajoranaOp.terms(), some new tests
grossardt Nov 18, 2023
51633b0
Merge branch 'main' into addfeature-majoranaop-issue1257
grossardt Nov 18, 2023
29600dd
Merge branch 'main' into addfeature-majoranaop-issue1257
grossardt Nov 27, 2023
97625dd
Update majorana_op.py
grossardt Nov 27, 2023
e2e9803
Merge branch 'main' into addfeature-majoranaop-issue1257
grossardt Nov 27, 2023
4c84cec
Update majorana_op.py
grossardt Nov 27, 2023
700aa59
Some easier reviews done. More will follow.
grossardt Nov 28, 2023
0ea65bf
Update releasenotes/notes/add-majoranaop-1cbf9d4a1d4c264e.yaml
grossardt Nov 28, 2023
2e1dd95
Update releasenotes/notes/add-majoranaop-1cbf9d4a1d4c264e.yaml
grossardt Nov 28, 2023
8d3987d
Merge branch 'main' into addfeature-majoranaop-issue1257
grossardt Nov 28, 2023
60e6473
Update qiskit_nature/second_q/operators/majorana_op.py
grossardt Dec 1, 2023
48661fa
Merge branch 'main' into addfeature-majoranaop-issue1257
grossardt Dec 1, 2023
d72af53
Reviewed changes
grossardt Dec 1, 2023
f73a068
Merge branch 'main' into addfeature-majoranaop-issue1257
grossardt Dec 4, 2023
d23cb86
Implement ModeBasedMapper no caching
grossardt Dec 11, 2023
3e318ba
Added caching and release note
grossardt Dec 12, 2023
f38cd64
Merge branch 'main' into fix-improve-mappers-issue1289
grossardt Dec 12, 2023
3b837d5
Merge branch 'fix-improve-mappers-issue1289' into addfeature-ternaryt…
grossardt Dec 12, 2023
d268913
Update release note to pass spell check
grossardt Dec 12, 2023
61042e0
fix typing
grossardt Dec 12, 2023
1a4b2e0
fix typing for Python <3.10
grossardt Dec 12, 2023
1b43a10
Merge branch 'main' into addfeature-majoranaop-issue1257
grossardt Dec 13, 2023
72ffda7
final suggestions by mrossinek
grossardt Dec 13, 2023
d77c269
Merge branch 'fix-improve-mappers-issue1289' into addfeature-ternaryt…
grossardt Jan 27, 2024
bc4e8ad
Merge branch 'addfeature-majoranaop-issue1257' into addfeature-ternar…
grossardt Jan 27, 2024
89f9114
Add TernaryTreeMapper
grossardt Jan 28, 2024
0f9416c
Lint/spellcheck
grossardt Jan 28, 2024
0b83db0
Merge branch 'main' into addfeature-ternarytreemap-issue582
grossardt Jan 28, 2024
343da0e
Copyright years fixed
grossardt Jan 28, 2024
2744801
copyright years (missed one)
grossardt Jan 28, 2024
eae1e2d
Make pauli_table for TernaryTreeMapper compatible
grossardt Jan 28, 2024
23b2f45
Merge branch 'main' into addfeature-ternarytreemap-issue582
woodsp-ibm Feb 20, 2024
83eee12
Merge branch 'main' into addfeature-ternarytreemap-issue582
grossardt Feb 26, 2024
386a579
fixes deprecation to pass tests
grossardt Feb 26, 2024
22b8c26
Merge branch 'main' into addfeature-ternarytreemap-issue582
grossardt Apr 19, 2024
b6d9a26
Update mode_based_mapper.py
grossardt Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .pylintdict
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ chkfile
cholesky
chuang
ci
classmethod
clbit
clbits
clifford
Expand Down Expand Up @@ -280,6 +281,7 @@ jcf
jcp
jernigan
ji
jiang
jk
jl
jordan
Expand All @@ -289,6 +291,7 @@ json
jupyter
jw
kagome
kalev
kanav
ket
kitaev
Expand All @@ -301,6 +304,7 @@ kwargs
kwds
labelled
langle
lbl
lbrace
lda
ldots
Expand All @@ -326,6 +330,7 @@ lvert
lysine
macos
majorana
majoranaop
makefile
matmul
matplotlib
Expand Down Expand Up @@ -357,6 +362,7 @@ moller
molssi
morse
mpl
mruczkiewicz
mul
multi
multigraph
Expand All @@ -377,6 +383,7 @@ neq
networkx
neuropeptide
neutron
neven
nicholas
nielsen
nisq
Expand Down Expand Up @@ -453,6 +460,7 @@ pxd
py
pydata
pyquante
pyright
pyscf
qarg
qargs
Expand Down Expand Up @@ -658,11 +666,16 @@ xcfun
xdata
xy
xyz
xzy
ydata
yx
yxz
yy
yzx
zeitschrift
zi
zmatrix
zsh
zxy
zyx
zz
15 changes: 14 additions & 1 deletion qiskit_nature/second_q/mappers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2022, 2023.
# (C) Copyright IBM 2022, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -25,6 +25,7 @@
:nosignatures:

QubitMapper
ModeBasedMapper

FermionicOp Mappers
+++++++++++++++++++
Expand All @@ -37,6 +38,14 @@
BravyiKitaevSuperFastMapper
JordanWignerMapper
ParityMapper
TernaryTreeMapper

**Note:** :class:`~qiskit_nature.second_q.mappers.TernaryTreeMapper` maps
:class:`~qiskit_nature.second_q.operators.MajoranaOp` to
:class:`~qiskit.quantum_info.SparsePauliOp`. In order to use it on a
:class:`~qiskit_nature.second_q.operators.FermionicOp`, convert to a
:class:`~qiskit_nature.second_q.operators.MajoranaOp` first using
:code:`MajoranaOp.from_fermionic_op()`.

**Interleaved Qubit-Ordering:** If you want to generate qubit operators where the alpha-spin and
beta-spin components are mapped to the qubit register in an interleaved (rather than the default
Expand Down Expand Up @@ -96,11 +105,13 @@
from .bravyi_kitaev_mapper import BravyiKitaevMapper
from .jordan_wigner_mapper import JordanWignerMapper
from .parity_mapper import ParityMapper
from .ternary_tree_mapper import TernaryTreeMapper
from .linear_mapper import LinearMapper
from .bosonic_linear_mapper import BosonicLinearMapper
from .logarithmic_mapper import LogarithmicMapper
from .direct_mapper import DirectMapper
from .qubit_mapper import QubitMapper
from .mode_based_mapper import ModeBasedMapper
from .interleaved_qubit_mapper import InterleavedQubitMapper
from .tapered_qubit_mapper import TaperedQubitMapper

Expand All @@ -110,10 +121,12 @@
"DirectMapper",
"JordanWignerMapper",
"ParityMapper",
"TernaryTreeMapper",
"LinearMapper",
"BosonicLinearMapper",
"LogarithmicMapper",
"QubitMapper",
"InterleavedQubitMapper",
"TaperedQubitMapper",
"ModeBasedMapper",
]
4 changes: 2 additions & 2 deletions qiskit_nature/second_q/mappers/bosonic_linear_mapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2023.
# (C) Copyright IBM 2023, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -29,7 +29,7 @@ class BosonicLinearMapper(BosonicMapper):
"""The Linear boson-to-qubit mapping.

This mapper generates a linear encoding of the Bosonic operator :math:`b_k^\\dagger, b_k` to qubit
operators (linear combinations of pauli strings).
operators (linear combinations of Pauli strings).
In this linear encoding each bosonic mode is represented via :math:`n_k^{max} + 1` qubits, where
:math:`n_k^{max}` is the max occupation of the mode (meaning the number of states used in the
expansion of the mode, or equivalently the state at which the maximum excitation can take place).
Expand Down
2 changes: 1 addition & 1 deletion qiskit_nature/second_q/mappers/bosonic_mapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2023.
# (C) Copyright IBM 2023, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down
11 changes: 7 additions & 4 deletions qiskit_nature/second_q/mappers/bravyi_kitaev_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
from qiskit.quantum_info.operators import Pauli

from .fermionic_mapper import FermionicMapper
from .mode_based_mapper import ModeBasedMapper, PauliType


class BravyiKitaevMapper(FermionicMapper):
class BravyiKitaevMapper(FermionicMapper, ModeBasedMapper):
"""The Bravyi-Kitaev fermion-to-qubit mapping."""

@classmethod
def pauli_table(self, register_length: int) -> list[tuple[PauliType, PauliType]]:
return self._pauli_table(register_length)

@staticmethod
@lru_cache(maxsize=32)
def pauli_table(cls, register_length: int) -> list[tuple[Pauli, Pauli]]:
# pylint: disable=unused-argument
def _pauli_table(register_length: int) -> list[tuple[PauliType, PauliType]]:
def parity_set(j, n):
"""
Computes the parity set of the j-th orbital in n modes.
Expand Down
11 changes: 7 additions & 4 deletions qiskit_nature/second_q/mappers/direct_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@
from qiskit.quantum_info.operators import Pauli

from .vibrational_mapper import VibrationalMapper
from .mode_based_mapper import ModeBasedMapper, PauliType


class DirectMapper(VibrationalMapper):
class DirectMapper(VibrationalMapper, ModeBasedMapper):
"""The Direct mapper.

This mapper maps a :class:`~.VibrationalOp` to a qubit operator. In doing so, each modal of the
``VibrationalOp`` gets mapped to a single qubit.
"""

@classmethod
def pauli_table(self, register_length: int) -> list[tuple[PauliType, PauliType]]:
return self._pauli_table(register_length)

@staticmethod
@lru_cache(maxsize=32)
def pauli_table(cls, register_length: int) -> list[tuple[Pauli, Pauli]]:
# pylint: disable=unused-argument
def _pauli_table(register_length: int) -> list[tuple[PauliType, PauliType]]:
pauli_table = []

for i in range(register_length):
Expand Down
11 changes: 7 additions & 4 deletions qiskit_nature/second_q/mappers/jordan_wigner_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
from qiskit.quantum_info.operators import Pauli

from .fermionic_mapper import FermionicMapper
from .mode_based_mapper import ModeBasedMapper, PauliType


class JordanWignerMapper(FermionicMapper):
class JordanWignerMapper(FermionicMapper, ModeBasedMapper):
"""The Jordan-Wigner fermion-to-qubit mapping."""

@classmethod
def pauli_table(self, register_length: int) -> list[tuple[PauliType, PauliType]]:
return self._pauli_table(register_length)

@staticmethod
@lru_cache(maxsize=32)
def pauli_table(cls, register_length: int) -> list[tuple[Pauli, Pauli]]:
# pylint: disable=unused-argument
def _pauli_table(register_length: int) -> list[tuple[PauliType, PauliType]]:
pauli_table = []

for i in range(register_length):
Expand Down
2 changes: 1 addition & 1 deletion qiskit_nature/second_q/mappers/logarithmic_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _logarithmic_encoding(
op.chop()
spin_op_encoding.append(op)

return tuple(spin_op_encoding)
return (spin_op_encoding[0], spin_op_encoding[1], spin_op_encoding[2], spin_op_encoding[3])

def _embed_matrix(
self,
Expand Down
33 changes: 33 additions & 0 deletions qiskit_nature/second_q/mappers/majorana_mapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Majorana Mapper."""

from __future__ import annotations

from qiskit.quantum_info import SparsePauliOp

from qiskit_nature.second_q.operators import MajoranaOp

from .qubit_mapper import ListOrDictType, QubitMapper


class MajoranaMapper(QubitMapper):
"""Mapper of Majorana Operator to Qubit Operator"""

def map(
self,
second_q_ops: MajoranaOp | ListOrDictType[MajoranaOp],
*,
register_length: int | None = None,
) -> SparsePauliOp | ListOrDictType[SparsePauliOp]:
return super().map(second_q_ops, register_length=register_length)
Loading
Loading