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

Refactor T2HahnBackend to use qiskit-aer #1040

Merged
merged 15 commits into from
Mar 26, 2023
Merged

Conversation

wshanks
Copy link
Collaborator

@wshanks wshanks commented Feb 10, 2023

Summary

This commit refactors T2HahnBackend to use qiskit-aer for improved performance.

Details and comments

The T2 tests were quite slow, taking around 149 seconds of run time in testing. T2HahnBackend was doing a form of simple Monte Carlo simulation, stepping through each circuit and flipping the qubit based on error probabilities. This behavior scales linearly with number of shots which is not good when running 1000 shots on around 100 circuits for each test. This commit switches T2HahnBackend to use AerSimulator which simulates each circuit only one time to determine the final output probability. It can then produce as many shot results as needed quickly by sampling from this distribution.

With the switch to AerSimulator, the run time of the T2 tests dropped from 149 seconds to 12 seconds. The simulation speed up was more significant than that because the test time is now not limited by simulation (simulation is around 0.5 seconds now).

}
else:
for circuit in circuits:
if circuit.num_qubits > self.num_qubits:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test doesn't help too much for experiments because by the time an experiment gets to run() it has already done a transpile and if there are more qubits in the circuit than in the Target there would have been a transpile error.

@wshanks wshanks added the Changelog: API Change Include in the "Changed" section of the changelog label Feb 12, 2023
@wshanks
Copy link
Collaborator Author

wshanks commented Feb 12, 2023

Waiting for #1042. If that one won't be reviewed quickly, we could ignore the issues pylint is flagging.

@wshanks
Copy link
Collaborator Author

wshanks commented Mar 16, 2023

Comment moved out of the PR description since it shouldn't end up in the commit message:

Since T2HahnBackend is used in a tutorial, I tried to maintain its previous API (otherwise, the class could be a bit simpler by being less flexible about the arguments it accepts). I did make slight changes which I put in a release note (you can't pass a single element list for a parameter when simulating multiple qubits, only a bare float or a list matching the number of qubits; if you pass only float parameters, you must pass the number of qubits; we could relax these conditions at the expense of more code checking and reformatting the inputs but it didn't seem worth it to me).

I have not done that much with qiskit-aer. There might be a different way to set up the simulator without adding the extra transpiler passes for preparation error and qubit frequency drift.

Copy link
Contributor

@yaelbh yaelbh left a comment

Choose a reason for hiding this comment

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

Thanks @wshanks! It's a nice PR. I wrote only three minor cosmetic comments.

qiskit_experiments/test/t2hahn_backend.py Outdated Show resolved Hide resolved
qiskit_experiments/test/t2hahn_backend.py Outdated Show resolved Hide resolved
qiskit_experiments/test/t2hahn_backend.py Outdated Show resolved Hide resolved
@wshanks wshanks requested a review from yaelbh March 23, 2023 15:23
@wshanks
Copy link
Collaborator Author

wshanks commented Mar 23, 2023

@yaelbh Your comments were straightforward, but I went a little further. Do you want to check my new changes?

@yaelbh yaelbh added this pull request to the merge queue Mar 26, 2023
Merged via the queue into qiskit-community:main with commit 1bac9cd Mar 26, 2023
wshanks added a commit that referenced this pull request Mar 27, 2023
### Summary

This change set updates the `FakeBackend` used by some tests to derive
from `BackendV2` rather than `BackendV1`

### Details and comments

When combined with
[#900](#900) which
updates some calibration tests and
[#1040](#1040) which
updates `T2HahnBackend`, this change results in almost all the tests in
the test suite using `BackendV2`. The remaining tests using a `Backend`
that is not `BackendV2` use the `AerSimulator` which will be updated to
`BackendV2` in the future (tracked in
Qiskit/qiskit-aer#1681). The check for backend
type was performed by merging the calibration and `T2HahnBackend`
branches into this branch and running the tests with
`BaseExperiment.run()`, `BaseExperiment._set_backend()`, and
`Calibrations.from_backend()` updated to error if the `backend` argument
was not `BackendV2` or `AerSimulator` and confirming that all the tests
passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants