Skip to content

Conversation

@debasmita2102
Copy link
Contributor

Summary

  • Add ASV benchmarks to track performance of the BasicSimulator Clifford (StabilizerState) path versus the existing statevector path.

  • The benchmarks are split out from PR Add Clifford circuit optimization to BasicSimulator #15159 so that code changes and performance tracking can be reviewed independently.

Details and comments

  • Add BasicSimulatorGHZBenchmark to compare Clifford vs statevector performance on GHZ-like Clifford circuits (two output bitstrings) for n_qubits = [4, 8, 12, 16].
  • Add BasicSimulatorRandomCliffordBenchmark to compare Clifford vs statevector performance on random Clifford circuits generated via random_clifford(n_qubits) for the same qubit sizes.

@debasmita2102 debasmita2102 requested a review from a team as a code owner December 16, 2025 11:03
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@coveralls
Copy link

Pull Request Test Coverage Report for Build 20265672539

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 7 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.004%) to 88.301%

Files with Coverage Reduction New Missed Lines %
crates/transpiler/src/passes/unitary_synthesis.rs 1 93.32%
crates/qasm2/src/lex.rs 6 91.77%
Totals Coverage Status
Change from base Build 20225348384: 0.004%
Covered Lines: 96635
Relevant Lines: 109438

💛 - Coveralls

Copy link
Member

@alexanderivrii alexanderivrii left a comment

Choose a reason for hiding this comment

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

Thanks for adding these well thought-out set of benchmarks @debasmita2102. A few minor comments, but otherwise LGTM.

def setup(self, n_qubits):
"""Setup random Clifford circuit for given n_qubits."""

cliff = random_clifford(n_qubits)
Copy link
Member

Choose a reason for hiding this comment

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

This call to random_clifford is not deterministic, consider providing an explicit seed, for example:

Suggested change
cliff = random_clifford(n_qubits)
cliff = random_clifford(n_qubits, seed=0)

I now see that there are other ASV tests that use random_clifford with non-deterministic results, I think we also fix those (but in a separate PR).

Comment on lines +74 to +76
def time_statevector(self, n_qubits):
"""Time statevector simulation of random Clifford circuit."""
_ = n_qubits # ASV parameter
Copy link
Member

Choose a reason for hiding this comment

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

Would something like this work as well?

Suggested change
def time_statevector(self, n_qubits):
"""Time statevector simulation of random Clifford circuit."""
_ = n_qubits # ASV parameter
def time_statevector(self, _n_qubits):
"""Time statevector simulation of random Clifford circuit."""

Comment on lines +84 to +86
def time_clifford(self, n_qubits):
"""Time Clifford-optimized simulation of random Clifford circuit."""
_ = n_qubits # ASV parameter
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as before.

"""Time Clifford-optimized simulation of random Clifford circuit."""
_ = n_qubits # ASV parameter
backend = BasicSimulator()
backend.run(
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to add _ = here for readability, expressing that the call returns a result (which is however ignored)?

Suggested change
backend.run(
_ = backend.run(

If you think it does, then this comment applies to other similar calls in this file.

from qiskit.providers.basic_provider import BasicSimulator
from qiskit.quantum_info import random_clifford

# pylint: disable=attribute-defined-outside-init
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if it matters (and most probably it does not), but in all other tests the # pylint: disable line appears before the module dostring/imports. Feel free to change this or leave it as is.

def time_statevector(self, n_qubits):
"""Time statevector simulation of GHZ circuit."""
_ = n_qubits # ASV parameter
backend = BasicSimulator()
Copy link
Member

Choose a reason for hiding this comment

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

This is fast, right (otherwise, you could also move this construction to setup as well).

@alexanderivrii
Copy link
Member

alexanderivrii commented Dec 16, 2025

Note that we are able merge this PR before #15159: calling BasicSimulator().run(..., use_clifford_optimization=...) works, because BasicSimulator().run accepts a generic dict-style run_options. In fact, it might be interesting to merge this first, to quantify the slowdown we get with the above for simulating Clifford circuits with a small number of qubits.

@ShellyGarion ShellyGarion added the type: qa Issues and PRs that relate to testing and code quality label Dec 17, 2025
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.

@debasmita2102 - Thanks for adding ASV tests!
Are there similar tests for the BasicSimulator for non-Clifford circuits? If not, maybe it's worth adding them in a seperate PR.

My main comment is that with a Clifford simulator we can extend the number of qubits in the tests for more than 24. But this can be done only after we merge #15159.

class BasicSimulatorGHZBenchmark:
"""Benchmark BasicSimulator on GHZ Clifford circuits."""

params = ([4, 8, 12, 16],)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if after we merge #15159, we could extend the number of qubits here

class BasicSimulatorRandomCliffordBenchmark:
"""Benchmark BasicSimulator on random Clifford circuits."""

params = ([4, 8, 12, 16],)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if after we merge #15159, we could extend the number of qubits here

@ShellyGarion ShellyGarion added the mod: quantum info Related to the Quantum Info module (States & Operators) label Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod: quantum info Related to the Quantum Info module (States & Operators) type: qa Issues and PRs that relate to testing and code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants