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

Clifford does not use StabilizerTable as internal data and PendingDeprecation of PauliTable and StabilizerTable #7269

Merged
merged 27 commits into from
Sep 29, 2022

Conversation

ikkoham
Copy link
Contributor

@ikkoham ikkoham commented Nov 15, 2021

Summary

Clifford does not use StabilizerTable as internal data and PendingDeprecation of PauliTable and StabilizerTable.

Details and comments

Performance regression occurs due to stacking of x and z and tracking of phase.
We need to check the regression is acceptable or not.
=> Performance check: small regression for small qubits (acceptable?)

I updated the code not to use PauliList.
We don't have the performance regression now.
This is new benchmark result:

       before           after         ratio
     [3f9edfc8]       [0371d4f9]
     <main>           <pull/7269/head>
          443±7ms          409±3ms     0.92  quantum_info.CliffordComposeBench.time_compose('1,7000')
         506±20ms         494±10ms     0.98  quantum_info.CliffordComposeBench.time_compose('2,5000')
         731±40ms          716±6ms     0.98  quantum_info.CliffordComposeBench.time_compose('3,5000')
         533±10ms          523±7ms     0.98  quantum_info.CliffordComposeBench.time_compose('4,2500')
         612±10ms          592±4ms     0.97  quantum_info.CliffordComposeBench.time_compose('5,2000')
         56.8±1ms         55.6±3ms     0.98  quantum_info.CliffordDecomposeBench.time_decompose('1,1000')
-      1.14±0.01s       1.02±0.01s     0.90  quantum_info.CliffordDecomposeBench.time_decompose('2,500')
       1.58±0.02s       1.47±0.02s     0.93  quantum_info.CliffordDecomposeBench.time_decompose('3,100')
-        623±20ms          527±3ms     0.85  quantum_info.CliffordDecomposeBench.time_decompose('4,50')
          196±4ms          176±5ms    ~0.90  quantum_info.CliffordDecomposeBench.time_decompose('5,10')
-         729±6ms         570±20ms     0.78  quantum_info.RandomCliffordBench.time_random_clifford('1,3000')
-         665±5ms         525±20ms     0.79  quantum_info.RandomCliffordBench.time_random_clifford('2,2500')
-         599±4ms          487±2ms     0.81  quantum_info.RandomCliffordBench.time_random_clifford('3,2000')
-         507±4ms          416±4ms     0.82  quantum_info.RandomCliffordBench.time_random_clifford('4,1500')
-         492±4ms          429±4ms     0.87  quantum_info.RandomCliffordBench.time_random_clifford('5,1000')
-        408±10ms          346±3ms     0.85  quantum_info.RandomCliffordBench.time_random_clifford('6,700')

@coveralls
Copy link

coveralls commented Nov 15, 2021

Pull Request Test Coverage Report for Build 3149420026

  • 291 of 324 (89.81%) changed or added relevant lines in 7 files are covered.
  • 6 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.05%) to 84.503%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/quantum_info/synthesis/clifford_decompose.py 31 32 96.88%
qiskit/quantum_info/operators/symplectic/clifford.py 181 213 84.98%
Files with Coverage Reduction New Missed Lines %
qiskit/quantum_info/operators/symplectic/clifford.py 1 87.43%
qiskit/extensions/quantum_initializer/squ.py 2 79.78%
qiskit/quantum_info/operators/symplectic/stabilizer_table.py 3 87.33%
Totals Coverage Status
Change from base Build 3148975703: 0.05%
Covered Lines: 60389
Relevant Lines: 71464

💛 - Coveralls

@ShellyGarion
Copy link
Member

Perhaps it's also relevant to check the RB performance since it requires to generate and compose large sequences of random Cliffords.
There is a benchmark here: https://github.com/Qiskit/qiskit/blob/master/test/benchmarks/randomized_benchmarking.py
However, it's based on the old ignis code that is going to be deprecated soon, and not on the qiskit.experiments code
https://qiskit.org/documentation/experiments/tutorials/randomized_benchmarking.html

@ikkoham
Copy link
Contributor Author

ikkoham commented Nov 16, 2021

@ShellyGarion Thanks. I checked RB:

[  0.00%] ·· Benchmarking virtualenv-py3.8
[ 12.50%] ··· Running (randomized_benchmarking.RandomizedBenchmarkingBenchmark.time_ibmq_backend_transpile--).
[ 25.00%] ··· Running (randomized_benchmarking.RandomizedBenchmarkingBenchmark.time_ibmq_backend_transpile_single_thread--).
[ 37.50%] ··· randomized_benchmarking.RandomizedBenchmarkingBenchmark.time_ibmq_backend_transpile                                                                                                                                                                          ok
[ 37.50%] ··· =============== ============
                 rb_pattern
              --------------- ------------
                   [[0]]        846±20ms
                  [[0, 1]]     3.82±0.04s
               [[0, 1], [2]]   4.73±0.1s
              =============== ============

[ 50.00%] ··· randomized_benchmarking.RandomizedBenchmarkingBenchmark.time_ibmq_backend_transpile_single_thread                                                                                                                                                            ok
[ 50.00%] ··· =============== ============
                 rb_pattern
              --------------- ------------
                   [[0]]        814±20ms
                  [[0, 1]]     3.84±0.05s
               [[0, 1], [2]]   4.72±0.1s
              =============== ============

[ 50.00%] · For qiskit-terra commit e02119b2 <main>:
[ 50.00%] ·· Building for virtualenv-py3.8.......
[ 50.00%] ·· Benchmarking virtualenv-py3.8
[ 62.50%] ··· Running (randomized_benchmarking.RandomizedBenchmarkingBenchmark.time_ibmq_backend_transpile--).
[ 75.00%] ··· Running (randomized_benchmarking.RandomizedBenchmarkingBenchmark.time_ibmq_backend_transpile_single_thread--).
[ 87.50%] ··· randomized_benchmarking.RandomizedBenchmarkingBenchmark.time_ibmq_backend_transpile                                                                                                                                                                          ok
[ 87.50%] ··· =============== ===========
                 rb_pattern
              --------------- -----------
                   [[0]]        821±10ms
                  [[0, 1]]     4.10±0.3s
               [[0, 1], [2]]    9.60±3s
              =============== ===========

[100.00%] ··· randomized_benchmarking.RandomizedBenchmarkingBenchmark.time_ibmq_backend_transpile_single_thread                                                                                                                                                            ok
[100.00%] ··· =============== ============
                 rb_pattern
              --------------- ------------
                   [[0]]        881±60ms
                  [[0, 1]]     3.95±0.04s
               [[0, 1], [2]]   4.93±0.1s
              =============== ============

@ShellyGarion
Copy link
Member

Thanks @ikkoham - but now I think that this benchmark is only for the transpilation process, and does not benchmark the actual generation of the RB sequences themselves...

@ikkoham
Copy link
Contributor Author

ikkoham commented Nov 16, 2021

I see. then, we need to add more benchmarks to Qiskit repository.

EDITED: I'll add the benchmark for the tutorial here.

Copy link
Member

@chriseclectic chriseclectic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good approach to me. Left a few suggestions for some small improvements.

qiskit/quantum_info/operators/symplectic/clifford.py Outdated Show resolved Hide resolved
qiskit/quantum_info/operators/symplectic/pauli_list.py Outdated Show resolved Hide resolved
qiskit/quantum_info/operators/symplectic/pauli_list.py Outdated Show resolved Hide resolved
qiskit/quantum_info/operators/symplectic/pauli_list.py Outdated Show resolved Hide resolved
qiskit/quantum_info/operators/symplectic/pauli_list.py Outdated Show resolved Hide resolved
qiskit/quantum_info/operators/symplectic/clifford.py Outdated Show resolved Hide resolved
from qiskit.quantum_info.operators.symplectic.clifford_circuits import (
_append_x,
)
from qiskit.quantum_info.states.quantum_state import QuantumState


class StabilizerState(QuantumState):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be in this PR, but we should improve the init method of StabilizerState so it can also be constructed from a PauliList, or data format that can itself be used to initialize a PauliList.

@ShellyGarion
Copy link
Member

In clifford_circuits and stabilzer_state it may be good to add some comments to the reader of the code, since it's not the exact formulas from Aaronson-Gottesman.

@ikkoham ikkoham marked this pull request as ready for review November 22, 2021 15:13
@ikkoham ikkoham requested a review from a team as a code owner November 22, 2021 15:13
@ikkoham ikkoham changed the title [WIP] Deprecate StabilizerTable Deprecate StabilizerTable Nov 22, 2021
@ikkoham
Copy link
Contributor Author

ikkoham commented Nov 24, 2021

@ShellyGarion Thank you for your comments. It is true that the previous codes are hard to read. So, I added methods: stabilizer_tableau() and stabilizer_list(), and so on. I think now it's more readable.

ShellyGarion
ShellyGarion previously approved these changes Nov 25, 2021
ShellyGarion
ShellyGarion previously approved these changes Nov 25, 2021
@ikkoham ikkoham mentioned this pull request Nov 30, 2021
1 task
@chriseclectic chriseclectic added mod: quantum info Related to the Quantum Info module (States & Operators) Changelog: Deprecation Include in "Deprecated" section of changelog labels Nov 30, 2021
@kdk kdk added this to the 0.19 milestone Nov 30, 2021

# Validate table is a symplectic matrix
if validate and not Clifford._is_symplectic(self._table.array):
if validate and not Clifford._is_symplectic(self.tableau[:, :-1]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider defining a property and a setter for the symplectic part of the clifford tableau, say symplectic, instead of the previous cliff.table.array and not call tableau[:, :-1] (which appears several times in the code).

Copy link
Contributor Author

@ikkoham ikkoham Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The properties are nice. The property name symplectic is well used in the literature? I know that we check the symplectic inner product in the method _is_symplectic, but I don't know whether Z components and X components is called symplectic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 2nx2n array in the clifford tableau is a symplectic binary matrix, see e.g. https://arxiv.org/abs/1406.2170 (eq. 3 and 4) and https://en.wikipedia.org/wiki/Symplectic_group for the definition.
But of course, it's possible to choose a different name if you like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's an element of symplectic group. Thank you for the explanation. Then, I prefer Clifford.symplectic_matrix (a bit long).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add in c1a8f98. It is more readable.

release. Instead, the :class:`~qiskit.quantum_info.PauliList` should be used.
With this change, :attr:`.Clifford.table`, :attr:`.Clifford.stabilizer`, and
:attr:`.Clifford.destabilizer` have been deprecated so that you should use
:attr:`.Clifford.tableau`, :attr:`.Clifford.stabilizers`, :attr:`.Clifford.destabilizers`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The methods now are called Clifford.stab and Clifford.destab?
Also, there are other new methods added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just bumping this comment in my review too.

ShellyGarion
ShellyGarion previously approved these changes Sep 22, 2022
Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR LGTM. It makes significant changes in the Clifford class API, but it seems to still contain all the needed functionality of a Clifford class.

@ikkoham ikkoham requested a review from itoko September 27, 2022 05:43
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still concerned that some of the deprecations in Clifford tell users to used functions/attributes that are being added in the same PR, which breaks our deprecation policy. That said, this PR has been bounced from Terra releases so many times now (albeit in large part because it was breaking the deprecation policy...) that it may be more healthy for the development of the class to bend the rules this time. I'm concerned about affecting downstream users, but honestly, I think a large number of people are working around the Qiskit Clifford class right now because it's too slow, and we're currently blocking updates to that because of this PR.

Could you check through that all the deprecation notices are pointing to the right place, just one last time, and then I'll sign off on this.

release. Instead, the :class:`~qiskit.quantum_info.PauliList` should be used.
With this change, :attr:`.Clifford.table`, :attr:`.Clifford.stabilizer`, and
:attr:`.Clifford.destabilizer` have been deprecated so that you should use
:attr:`.Clifford.tableau`, :attr:`.Clifford.stabilizers`, :attr:`.Clifford.destabilizers`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just bumping this comment in my review too.

qiskit/quantum_info/operators/symplectic/clifford.py Outdated Show resolved Hide resolved
qiskit/quantum_info/operators/symplectic/clifford.py Outdated Show resolved Hide resolved
Comment on lines 201 to 208
@deprecate_function(
"Indexing or iterating through a Clifford object directly is deprecated as of "
"Qiskit Terra 0.22.0 and will be removed no sooner than 3 months after the release date. "
"Instead, index or iterate through the Clifford.tableau attribute."
)
def __getitem__(self, key):
"""Return a stabilizer Pauli row"""
return self._table.__getitem__(key)
return self.table.__getitem__(key)
Copy link
Member

@jakelishman jakelishman Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tableau attribute is new in this release, so we shouldn't really be issuing a DeprecationWarning telling users to use it unless there's already been a previous release with tableau in it. (See top review comment, though - I'm prepared to accept this PR despite breaking the deprecation policy, on somewhat pragmatic grounds of us having pushed this and held up development on the Clifford class for too long now.)

Comment on lines 215 to 217
def __setitem__(self, key, value):
"""Set a stabilizer Pauli row"""
self._table.__setitem__(key, value)
self.tableau.__setitem__(key, value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to do the right thing? I'm not 100% sure, but I didn't think the tableau representation was exactly the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it was wrong...

@ikkoham
Copy link
Contributor Author

ikkoham commented Sep 28, 2022

OK, then let's stop deprecation. It follows the deprecation policy.

In any case, the deprecation of PauliTable will not be ready in time for 0.22, and I would like to deprecate PauliTable and StabilizerTable at the same time.

@ikkoham ikkoham changed the title Deprecate StabilizerTable Clifford does not use StabilizerTable as internal data and PendingDeprecation of PauliTable and StabilizerTable Sep 28, 2022
@mtreinish mtreinish added the Changelog: New Feature Include in the "Added" section of the changelog label Sep 28, 2022
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I wasn't expecting you to actually swap them all over! Thank you! This does make me feel happier about the whole thing - I know it's a bit longer til we can fully remove StabilizerTable, but we still maintain our deprecation policy. Thanks a lot!

@mergify mergify bot merged commit 17de3b0 into Qiskit:main Sep 29, 2022
@ikkoham ikkoham deleted the qinfo/deprecate-stabilizer-table branch September 29, 2022 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Deprecation Include in "Deprecated" section of changelog Changelog: New Feature Include in the "Added" section of the changelog mod: quantum info Related to the Quantum Info module (States & Operators) priority: high
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants