Skip to content

Commit

Permalink
Merge branch 'master' into ad/level-in-draw
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiro-Raven authored Jun 19, 2024
2 parents f3a18c7 + ab8b6d5 commit 399ee53
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
optional argument to specify a list of measurements to be performed at the end of the circuit, just like `from_qiskit`.
[(#5818)](https://github.com/PennyLaneAI/pennylane/pull/5818)

* Add more fermionic-to-qubit tests to cover cases when the mapped operator is different for various mapping schemes.
[(#5873)](https://github.com/PennyLaneAI/pennylane/pull/5873)

<h4>Mid-circuit measurements and dynamic circuits</h4>

* The `default.qubit` device implements a depth-first tree-traversal algorithm to
Expand Down
31 changes: 31 additions & 0 deletions tests/fermi/test_bravyi_kitaev.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ def test_bravyi_kitaev_for_null_operator_fermi_word_ps(operator):
fw3 = FermiWord({(0, 0): "+", (1, 3): "-", (2, 0): "+", (3, 4): "-"})
fw4 = FermiWord({})
fw5 = FermiWord({(0, 3): "+", (1, 2): "-"})
fw6 = FermiWord({(0, 1): "+", (1, 4): "-"})


def test_empty_fermi_sentence():
Expand Down Expand Up @@ -1012,6 +1013,36 @@ def test_fermi_sentence_identity():
}
),
),
(
FermiSentence({fw6: 1, fw2: 2}),
5,
PauliSentence(
{
PauliWord({0: "I"}): 1.0,
PauliWord({0: "Z"}): -1.0,
PauliWord({0: "Z", 1: "X", 3: "Y", 4: "X"}): -0.25j,
PauliWord({0: "Z", 1: "X", 3: "Y", 4: "Y"}): 0.25,
PauliWord({1: "Y", 3: "Y", 4: "X"}): -0.25,
PauliWord({1: "Y", 3: "Y", 4: "Y"}): -0.25j,
}
),
),
(
FermiSentence({fw5: 1, fw6: 1}),
5,
PauliSentence(
{
PauliWord({0: "Z", 1: "X", 3: "Y", 4: "X"}): -0.25j,
PauliWord({0: "Z", 1: "X", 3: "Y", 4: "Y"}): 0.25,
PauliWord({1: "Y", 3: "Y", 4: "X"}): -0.25,
PauliWord({1: "Y", 3: "Y", 4: "Y"}): -0.25j,
PauliWord({1: "Z", 2: "X", 3: "Z"}): -0.25,
PauliWord({1: "Z", 2: "Y", 3: "Z"}): -0.25j,
PauliWord({2: "X"}): 0.25,
PauliWord({2: "Y"}): 0.25j,
}
),
),
]


Expand Down
45 changes: 45 additions & 0 deletions tests/fermi/test_fermi_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ def test_jordan_wigner_for_null_operator_fermi_word_ps(operator):
fw2 = FermiWord({(0, 0): "+", (1, 0): "-"})
fw3 = FermiWord({(0, 0): "+", (1, 3): "-", (2, 0): "+", (3, 4): "-"})
fw4 = FermiWord({})
fw5 = FermiWord({(0, 3): "+", (1, 2): "-"})
fw6 = FermiWord({(0, 1): "+", (1, 4): "-"})


def test_empty_fermi_sentence():
Expand Down Expand Up @@ -839,6 +841,49 @@ def test_fermi_sentence_identity():
}
),
),
(
FermiSentence({fw1: -2, fw5: 1j}),
PauliSentence(
{
PauliWord({0: "X", 1: "X"}): -0.5,
PauliWord({0: "X", 1: "Y"}): -0.5j,
PauliWord({0: "Y", 1: "X"}): 0.5j,
PauliWord({0: "Y", 1: "Y"}): -0.5,
PauliWord({2: "X", 3: "X"}): 0.25j,
PauliWord({2: "X", 3: "Y"}): 0.25,
PauliWord({2: "Y", 3: "X"}): -0.25,
PauliWord({2: "Y", 3: "Y"}): 0.25j,
}
),
),
(
FermiSentence({fw6: 1, fw2: 2}),
PauliSentence(
{
PauliWord({0: "I"}): 1.0,
PauliWord({0: "Z"}): -1.0,
PauliWord({1: "X", 2: "Z", 3: "Z", 4: "X"}): 0.25,
PauliWord({1: "X", 2: "Z", 3: "Z", 4: "Y"}): 0.25j,
PauliWord({1: "Y", 2: "Z", 3: "Z", 4: "X"}): -0.25j,
PauliWord({1: "Y", 2: "Z", 3: "Z", 4: "Y"}): 0.25,
}
),
),
(
FermiSentence({fw5: 1, fw6: 1}),
PauliSentence(
{
PauliWord({1: "X", 2: "Z", 3: "Z", 4: "X"}): 0.25,
PauliWord({1: "X", 2: "Z", 3: "Z", 4: "Y"}): 0.25j,
PauliWord({1: "Y", 2: "Z", 3: "Z", 4: "X"}): -0.25j,
PauliWord({1: "Y", 2: "Z", 3: "Z", 4: "Y"}): 0.25,
PauliWord({2: "X", 3: "X"}): 0.25,
PauliWord({2: "X", 3: "Y"}): -0.25j,
PauliWord({2: "Y", 3: "X"}): 0.25j,
PauliWord({2: "Y", 3: "Y"}): 0.25,
}
),
),
]


Expand Down
48 changes: 48 additions & 0 deletions tests/fermi/test_parity_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,8 @@ def test_parity_transform_for_null_operator_fermi_word_ps(operator):
fw2 = FermiWord({(0, 0): "+", (1, 0): "-"})
fw3 = FermiWord({(0, 0): "+", (1, 3): "-", (2, 0): "+", (3, 4): "-"})
fw4 = FermiWord({})
fw5 = FermiWord({(0, 3): "+", (1, 2): "-"})
fw6 = FermiWord({(0, 1): "+", (1, 4): "-"})


def test_empty_fermi_sentence():
Expand Down Expand Up @@ -1015,6 +1017,52 @@ def test_fermi_sentence_identity():
}
),
),
(
FermiSentence({fw1: -2, fw5: 1j}),
4,
PauliSentence(
{
PauliWord({0: "X"}): -0.5,
PauliWord({0: "X", 1: "Z"}): 0.5,
PauliWord({0: "Y"}): 0.5j,
PauliWord({0: "Y", 1: "Z"}): -0.5j,
PauliWord({1: "Z", 2: "X", 3: "Z"}): -0.25j,
PauliWord({1: "Z", 2: "Y"}): -0.25,
PauliWord({2: "X"}): 0.25j,
PauliWord({2: "Y", 3: "Z"}): 0.25,
}
),
),
(
FermiSentence({fw6: 1, fw2: 2}),
5,
PauliSentence(
{
PauliWord({0: "I"}): 1.0,
PauliWord({0: "Z"}): -1.0,
PauliWord({0: "Z", 1: "X", 2: "X", 3: "X", 4: "Z"}): -0.25,
PauliWord({0: "Z", 1: "X", 2: "X", 3: "Y"}): -0.25j,
PauliWord({1: "Y", 2: "X", 3: "X", 4: "Z"}): 0.25j,
PauliWord({1: "Y", 2: "X", 3: "Y"}): -0.25,
}
),
),
(
FermiSentence({fw5: 1, fw6: 1}),
5,
PauliSentence(
{
PauliWord({0: "Z", 1: "X", 2: "X", 3: "X", 4: "Z"}): -0.25,
PauliWord({0: "Z", 1: "X", 2: "X", 3: "Y"}): -0.25j,
PauliWord({1: "Y", 2: "X", 3: "X", 4: "Z"}): 0.25j,
PauliWord({1: "Y", 2: "X", 3: "Y"}): -0.25,
PauliWord({1: "Z", 2: "X", 3: "Z"}): -0.25,
PauliWord({1: "Z", 2: "Y"}): 0.25j,
PauliWord({2: "X"}): 0.25,
PauliWord({2: "Y", 3: "Z"}): -0.25j,
}
),
),
]


Expand Down

0 comments on commit 399ee53

Please sign in to comment.