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 Christiansen mapping for mapping christiansen bosons #6623

Merged
merged 105 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
a488e29
bosonic ops
austingmhuang Nov 5, 2024
fe6a264
refactor
austingmhuang Nov 5, 2024
7ef89ff
ordering fix
austingmhuang Nov 5, 2024
57e55d0
small
austingmhuang Nov 5, 2024
844c04f
Added christiansen boson and fixed the bug
ddhawan11 Nov 7, 2024
180e26b
tests? could revert
austingmhuang Nov 5, 2024
59459a9
ascending order
austingmhuang Nov 7, 2024
d5f82d3
Apply suggestions from code review
austingmhuang Nov 8, 2024
67873a1
Merge branch 'master' into bose_operators
austingmhuang Nov 8, 2024
06ae4ec
test fragments
austingmhuang Nov 8, 2024
07b8d96
small fixes, and tests
austingmhuang Nov 8, 2024
d39a3d3
[skip ci] black
austingmhuang Nov 8, 2024
c210ada
tests
austingmhuang Nov 8, 2024
f33f120
Update pennylane/labs/tests/vibrational_ham/test_bosonic.py
austingmhuang Nov 8, 2024
f0819be
Update pennylane/labs/vibrational_ham/bosonic.py
austingmhuang Nov 8, 2024
86fc4d6
Update pennylane/labs/vibrational_ham/bosonic.py
austingmhuang Nov 8, 2024
82a366a
Update pennylane/labs/vibrational_ham/bosonic.py
austingmhuang Nov 8, 2024
09f9981
Update pennylane/labs/vibrational_ham/bosonic.py
austingmhuang Nov 8, 2024
6bc979d
Merge branch 'master' into bose_operators
austingmhuang Nov 8, 2024
18762b5
Merge branch 'master' into bose_operators
austingmhuang Nov 8, 2024
4beccf1
[skip ci] black
austingmhuang Nov 8, 2024
c493be4
Merge branch 'master' into bose_operators
austingmhuang Nov 12, 2024
718fe06
change name to vibrational
austingmhuang Nov 8, 2024
4141d05
shift operator draft
austingmhuang Nov 11, 2024
fefa2cf
shift operator
austingmhuang Nov 12, 2024
a94e0c4
raise error tests for shift operator
austingmhuang Nov 13, 2024
3a7769b
Merge branch 'master' into bose_operators
austingmhuang Nov 13, 2024
1ea0e01
address codefactor
austingmhuang Nov 13, 2024
f748685
black
austingmhuang Nov 13, 2024
3aa8003
some more tests
austingmhuang Nov 13, 2024
afcf8a1
ready for review
austingmhuang Nov 13, 2024
8667f8f
ready for review
austingmhuang Nov 13, 2024
604095b
Merge branch 'master' into bose_operators
austingmhuang Nov 13, 2024
8abb82c
ready for review
austingmhuang Nov 13, 2024
6cb18ac
black
austingmhuang Nov 13, 2024
7f6fc01
cleaner, but not completely ideal
austingmhuang Nov 13, 2024
3651a1e
cleaner, but not completely ideal
austingmhuang Nov 13, 2024
b03ccb8
Update pennylane/labs/vibrational/bosonic.py
austingmhuang Nov 14, 2024
5ab62c6
Update pennylane/labs/vibrational/bosonic.py
austingmhuang Nov 14, 2024
b33075e
Update pennylane/labs/vibrational/bosonic.py
austingmhuang Nov 14, 2024
2291262
Update pennylane/labs/vibrational/bosonic.py
austingmhuang Nov 14, 2024
45488e7
Update pennylane/labs/vibrational/bosonic.py
austingmhuang Nov 14, 2024
96fbbcb
Update pennylane/labs/vibrational/bosonic.py
austingmhuang Nov 14, 2024
1157ccc
Update pennylane/labs/vibrational/bosonic.py
austingmhuang Nov 14, 2024
ef88820
Update pennylane/labs/vibrational/bosonic.py
austingmhuang Nov 14, 2024
1dc167d
remove useless loc
austingmhuang Nov 14, 2024
5c59617
black
austingmhuang Nov 14, 2024
66b7efc
dont know
austingmhuang Nov 14, 2024
ee79fa0
missing tests
austingmhuang Nov 14, 2024
67dca52
move to qchem main
austingmhuang Nov 15, 2024
9c92076
remove path from labs init
austingmhuang Nov 15, 2024
f077acb
move stuff around
austingmhuang Nov 15, 2024
f07008f
fix
austingmhuang Nov 15, 2024
0470d2c
import properly
austingmhuang Nov 15, 2024
63d3b25
import properly
austingmhuang Nov 15, 2024
4a69f95
[WIP] Tests for bose operators (#6559)
austingmhuang Nov 15, 2024
411eb42
Merge branch 'master' into bose_operators
austingmhuang Nov 15, 2024
9f96c91
pylint
austingmhuang Nov 15, 2024
ebd95bf
fix
austingmhuang Nov 15, 2024
fb9d8ff
fix tests
austingmhuang Nov 15, 2024
2eee3eb
fixes
austingmhuang Nov 15, 2024
168e82b
black
austingmhuang Nov 15, 2024
fd655b5
Merge branch 'master' into bose_operators
austingmhuang Nov 15, 2024
9ce98c5
new tests
austingmhuang Nov 18, 2024
efbc771
all tests
austingmhuang Nov 18, 2024
f913894
Merge branch 'master' into bose_operators
austingmhuang Nov 18, 2024
7ac1781
black and one more test
austingmhuang Nov 18, 2024
bab20d2
does this need to change?
austingmhuang Nov 18, 2024
200f3e4
honestly not sure what isort wants
austingmhuang Nov 18, 2024
499f0b0
Merge branch 'master' into bose_operators
austingmhuang Nov 18, 2024
2fe5cd6
address comments
austingmhuang Nov 19, 2024
86f7ad3
address comments
austingmhuang Nov 19, 2024
cf31530
address comments
austingmhuang Nov 19, 2024
1eaeab1
Update tests/qchem/vibrational_tests/test_bosonic.py
austingmhuang Nov 20, 2024
9278497
Update pennylane/qchem/vibrational/bosonic.py
austingmhuang Nov 20, 2024
260690c
remove redundant code in normal_order()
austingmhuang Nov 20, 2024
775e901
rename l r
austingmhuang Nov 20, 2024
f4df568
rename l r
austingmhuang Nov 20, 2024
06b238c
additional changes to hardcore check
austingmhuang Nov 20, 2024
a0653e8
Fix hardcore
austingmhuang Nov 20, 2024
a19fe78
tests for mul
austingmhuang Nov 20, 2024
2522868
remove hardcore stuff
austingmhuang Nov 20, 2024
9fdd1a5
update docs
austingmhuang Nov 20, 2024
b39ff66
Merge branch 'master' into bose_operators
austingmhuang Nov 20, 2024
e246966
docs
austingmhuang Nov 20, 2024
777a656
Apply suggestions from code review
austingmhuang Nov 20, 2024
47c5b1b
address comments
austingmhuang Nov 20, 2024
c7f2fe8
two changelogs
austingmhuang Nov 20, 2024
b2f2ee9
two changelogs
austingmhuang Nov 20, 2024
f49a4b3
two changelogs
austingmhuang Nov 20, 2024
475aa94
Added christiansen mapping
ddhawan11 Nov 21, 2024
5ab05cf
docstring fixes
ddhawan11 Nov 21, 2024
86a7e6c
[skip ci] removed bose operators code
ddhawan11 Nov 21, 2024
60822e2
Added error message
ddhawan11 Nov 25, 2024
0f1a617
Merge branch 'master' into christiansen_mapping
ddhawan11 Nov 25, 2024
6512d10
Minor docstring fixes
ddhawan11 Nov 25, 2024
2bc7840
Black fix
ddhawan11 Nov 25, 2024
4963573
Update pennylane/bose/bosonic_mapping.py
ddhawan11 Nov 25, 2024
6c4ece2
Update pennylane/bose/bosonic_mapping.py
ddhawan11 Nov 25, 2024
fa106a6
Update pennylane/bose/bosonic_mapping.py
ddhawan11 Nov 25, 2024
4ed0414
Added test
ddhawan11 Nov 25, 2024
5548837
Removed test
ddhawan11 Nov 26, 2024
598b194
Resolved conflicts
ddhawan11 Nov 27, 2024
e48e59e
Resolved conflicts
ddhawan11 Nov 27, 2024
b16e61c
Fix unwanted changes
ddhawan11 Nov 27, 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
2 changes: 1 addition & 1 deletion doc/code/qml_bose.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ Mapping to qubit operators

~binary_mapping
~unary_mapping

~christiansen_mapping

4 changes: 4 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
* Added a second class `DefaultMixedNewAPI` to the `qml.devices.qubit_mixed` module, which is to be the replacement of legacy `DefaultMixed` which for now to hold the implementations of `preprocess` and `execute` methods.
[(#6607)](https://github.com/PennyLaneAI/pennylane/pull/6507)

* Added `christiansen_mapping()` function to map `BoseWord` and `BoseSentence` to qubit operators, using christiansen mapping.
[(#6623)](https://github.com/PennyLaneAI/pennylane/pull/6623)

* Added `unary_mapping()` function to map `BoseWord` and `BoseSentence` to qubit operators, using unary mapping.
[(#6576)](https://github.com/PennyLaneAI/pennylane/pull/6576)

Expand Down Expand Up @@ -286,6 +289,7 @@ This release contains contributions from (in alphabetical order):
Shiwen An,
Astral Cai,
Yushao Chen,
Diksha Dhawan,
Pietropaolo Frisoni,
Austin Huang,
Korbinian Kottmann,
Expand Down
1 change: 1 addition & 0 deletions pennylane/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
BoseWord,
binary_mapping,
unary_mapping,
christiansen_mapping,
)
from pennylane.qchem import (
taper,
Expand Down
2 changes: 1 addition & 1 deletion pennylane/bose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"""A module containing utility functions and mappings for working with bosonic operators. """

from .bosonic import BoseSentence, BoseWord
from .bosonic_mapping import unary_mapping, binary_mapping
from .bosonic_mapping import binary_mapping, christiansen_mapping, unary_mapping
103 changes: 103 additions & 0 deletions pennylane/bose/bosonic_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,106 @@ def _(bose_operator: BoseSentence, n_states, tol=None):
qubit_operator.simplify(tol=1e-16)

return qubit_operator


def christiansen_mapping(
bose_operator: Union[BoseWord, BoseSentence],
ps: bool = False,
wire_map: dict = None,
tol: float = None,
):
r"""Convert a bosonic operator to a qubit operator using the Christiansen mapping.

This mapping assumes that the maximum number of allowed bosonic states is 2 and works only for
Christiansen bosons defined in `J. Chem. Phys. 120, 2140 (2004)
<https://pubs.aip.org/aip/jcp/article-abstract/120/5/2140/534128/A-second-quantization-formulation-of-multimode?redirectedFrom=fulltext>`_.
The bosonic creation and annihilation operators are mapped to the Pauli operators as

.. math::

b^{\dagger}_0 = \left (\frac{X_0 - iY_0}{2} \right ), \:\: \text{...,} \:\:
b^{\dagger}_n = \frac{X_n - iY_n}{2},

and

.. math::

b_0 = \left (\frac{X_0 + iY_0}{2} \right ), \:\: \text{...,} \:\:
b_n = \frac{X_n + iY_n}{2},

where :math:`X`, :math:`Y`, and :math:`Z` are the Pauli operators.

Args:
bose_operator(BoseWord, BoseSentence): the bosonic operator
ps (bool): Whether to return the result as a PauliSentence instead of an
operator. Defaults to False.
wire_map (dict): A dictionary defining how to map the states of
the Bose operator to qubit wires. If None, integers used to
label the bosonic states will be used as wire labels. Defaults to None.
tol (float): tolerance for discarding the imaginary part of the coefficients

Returns:
Union[PauliSentence, Operator]: A linear combination of qubit operators.
"""

qubit_operator = _christiansen_mapping_dispatch(bose_operator, tol)

wires = list(bose_operator.wires) or [0]
identity_wire = wires[0]
if not ps:
qubit_operator = qubit_operator.operation(wire_order=[identity_wire])

if wire_map:
return qubit_operator.map_wires(wire_map)

return qubit_operator


@singledispatch
def _christiansen_mapping_dispatch(bose_operator, tol):
"""Dispatches to appropriate function if bose_operator is a BoseWord or BoseSentence."""
raise ValueError(f"bose_operator must be a BoseWord or BoseSentence, got: {bose_operator}")
austingmhuang marked this conversation as resolved.
Show resolved Hide resolved


@_christiansen_mapping_dispatch.register
def _(bose_operator: BoseWord, tol=None):

qubit_operator = PauliSentence({PauliWord({}): 1.0})

coeffs = {"+": -0.5j, "-": 0.5j}

for (_, b_idx), sign in bose_operator.items():

qubit_operator @= PauliSentence(
{
PauliWord({**{b_idx: "X"}}): 0.5,
PauliWord({**{b_idx: "Y"}}): coeffs[sign],
}
)

for pw in qubit_operator:
if tol is not None and abs(qml.math.imag(qubit_operator[pw])) <= tol:
qubit_operator[pw] = qml.math.real(qubit_operator[pw])

qubit_operator.simplify(tol=1e-16)

return qubit_operator


@_christiansen_mapping_dispatch.register
def _(bose_operator: BoseSentence, tol=None):

qubit_operator = PauliSentence()

for bw, coeff in bose_operator.items():
bose_word_as_ps = christiansen_mapping(bw, ps=True)

for pw in bose_word_as_ps:
qubit_operator[pw] = qubit_operator[pw] + bose_word_as_ps[pw] * coeff

if tol is not None and abs(qml.math.imag(qubit_operator[pw])) <= tol:
qubit_operator[pw] = qml.math.real(qubit_operator[pw])

qubit_operator.simplify(tol=1e-16)

return qubit_operator
Loading