-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 PauliList class #5993
Add PauliList class #5993
Conversation
9426957
to
27d8e76
Compare
2acd550
to
052bd08
Compare
"Index {} is greater than number of qubits" | ||
" in the PauliList ({})".format(ind, self.num_qubits) | ||
) | ||
# TODO: Fix phase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this TODO still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your pointing out. I forget fixing the phase.
|
||
# Convert quantum circuits to Cliffords | ||
if isinstance(other, Clifford): | ||
other = other.to_circuit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you maybe do it directly without decomposing the clifford? like its done in #6297
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I've moved the _evolve_clifford to the base class.
value = PauliList(target) | ||
value[0] = "II" | ||
self.assertEqual(value, target) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the init tests - maybe worth checking more phases with i
and -i
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I added the tests.
target = PauliList(labels1 + labels2) | ||
self.assertEqual(target, pauli1 + pauli2) | ||
|
||
def test_add_qargs(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can test also pseudo-random paulis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Why do we need the test for the random Paulis here?
target = PauliList(["IIII", "YYYY", "YIXI", "ZIYI"]) | ||
self.assertEqual(pauli1 + pauli2([3, 1]), target) | ||
|
||
def test_getitem_methods(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe test more phases, and also pseudo-random paulis
|
||
def test_from_labels_1q(self): | ||
"""Test 1-qubit from_labels method.""" | ||
labels = ["I", "Z", "Z", "X", "Y"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Z appears twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is as intended. We also see that the same Pauli is not omitted.
np.array([[False], [True], [True], [False], [True]]), | ||
np.array([[False], [False], [False], [True], [True]]), | ||
) | ||
target = ["I", "Z", "Z", "X", "Y"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Z appears twice
value = pauli.to_labels(array=True) | ||
self.assertTrue(np.all(value == target)) | ||
|
||
def test_labels_round_trip(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can try more phases as well as pseudo-random paulis
|
||
|
||
@ddt | ||
class TestPauliListOperator(QiskitTestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in operators tests can test more phases
|
||
|
||
@ddt | ||
class TestPauliListMethods(QiskitTestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in sorting tests can test with phases
value = PauliList(labels).unique() | ||
self.assertEqual(target, value) | ||
|
||
def test_delete(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in delete and insert tests - maybe add phases?
value = pauli.insert(1, PauliList(i), qubit=True) | ||
self.assertEqual(value, target1) | ||
|
||
def test_commutes(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in commute / anti-commute tests - maybe add phases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I missed it initially, this needs a release note documenting the new class. After that's added this is ready to go
@mtreinish Thank you. I made a PR to add the release note. chriseclectic#25 @chriseclectic Could you merge this PR if it's OK? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I just merged @ikkoham's commit with the release notes from chriseclectic#25
It looks like there is a conflict here now: https://dev.azure.com/qiskit-ci/qiskit-terra/_build/results?buildId=29265&view=logs&j=377f2c8d-8b6f-583f-e152-2ff025e2543a&t=28b3ff0d-9e76-5e94-89e9-eed7321a383e&l=12999 probably after #6442 merged |
OK. I'll fix this soon. |
Thank you. I think chriseclectic#26 fixes the error on CI. (I've tested on my local and it passed.) |
I believe this is what was intended when the example was originally added (Qiskit#5993), as this now matches the method signature, and the `phase` on the previous line is no longer an unused variable.
I believe this is what was intended when the example was originally added (#5993), as this now matches the method signature, and the `phase` on the previous line is no longer an unused variable. (cherry picked from commit 8e54baa) Co-authored-by: Jim Garrison <[email protected]>
Summary
Add
PauliList
to replacePauliTable
andStabilizerTable
Details and comments
This class functions as an optimized list of the new
Pauli
class (including phase).