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

Update BaseEstimator import to support qiskit 2.0 #2327

Merged
merged 33 commits into from
Mar 13, 2025
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e3d9383
Use versioned base class for BaseEstimatorV1 instead of deprecated un…
ElePT Mar 5, 2025
cf942c3
Vendor removed V1 utils
ElePT Mar 11, 2025
d51aee6
Fix black
ElePT Mar 11, 2025
e877fc0
Replace bit with qubit
ElePT Mar 11, 2025
e2d93d5
Remove assemble test, as assemble was deprecated in 1.4 and removed i…
ElePT Mar 11, 2025
1695710
Merge branch 'main' of https://github.com/Qiskit/qiskit-aer into upda…
ElePT Mar 11, 2025
9fc42d1
Treat header as dict
ElePT Mar 11, 2025
6da91ff
Handle header conditionally
ElePT Mar 11, 2025
2f4d880
c_if is removed in 2.0, keep functionality for compatibility with 1.4…
ElePT Mar 11, 2025
69c8825
Fix access to header in tests
ElePT Mar 11, 2025
e36e160
Remove use of instruction_durations in transpile
ElePT Mar 11, 2025
18344cb
Attempt at fixing custom gate mapping. Not sure if gate = None is acc…
ElePT Mar 11, 2025
f6546e8
IfElseOp is not supported by statevector simulator. Reverted uni test…
ElePT Mar 11, 2025
2d0b1bb
Remove wrong import
ElePT Mar 11, 2025
983bafb
Fix failed target construction
ElePT Mar 12, 2025
c5865df
Only run tests with c_if with qiskit<2
ElePT Mar 12, 2025
17f9c34
Address leftover custom basis gates in transpiler
ElePT Mar 12, 2025
fabca5e
Attempt at addressing .duration removal
ElePT Mar 12, 2025
f7617b8
Add unittest import missing in previous commit
ElePT Mar 12, 2025
9cf7191
Use new target arg in tests for relaxation noise pass
ElePT Mar 12, 2025
07b652f
Fix lint
ElePT Mar 12, 2025
edc89aa
Don't use target with backend props
ElePT Mar 12, 2025
bb1869a
Attempt at fixing relaxation pass
ElePT Mar 12, 2025
a643439
use hashable type
ElePT Mar 12, 2025
0d57cfd
Fix issue with pickle/dill (temporary skip of fractional gates)
ElePT Mar 12, 2025
4d9cdd8
Add missing c_if skip
ElePT Mar 12, 2025
e38f0d0
Skip transpilation to avoid qiskit bug in test
ElePT Mar 12, 2025
41ac5a2
Skipping transpilation affects results
ElePT Mar 12, 2025
db5a011
Update truncation test. This test was relying on the transpiler blowi…
ElePT Mar 12, 2025
8f78f29
Apply suggestion to use shots None
ElePT Mar 12, 2025
5375346
Get rid of shot noise
ElePT Mar 12, 2025
7d554c3
Improve truncation test
ElePT Mar 13, 2025
4fe916c
Assert number of active qubits
ElePT Mar 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/terra/primitives/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def test_result_order(self):
qc2.ry(np.pi / 2 * param, 0)
qc2.measure_all()

estimator = Estimator(approximation=True)
estimator = Estimator(approximation=True, skip_transpilation=True)
Copy link

@AlbertJP AlbertJP Mar 12, 2025

Choose a reason for hiding this comment

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

Try run_options = {'shots': None} to get exact values for the circuits that result in 0.

Alternative: change qc2 to give -1 instead of 0, then you won't have shot noise either. This can be done by changing np.pi / 2 to np.pi in the circuit, or [1] to [2] in the parameter.
(Estimator has no shot noise when the expectation value is exactly -1 or 1)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! I haven't used the aer estimator in a while and forgot how to set these.

Choose a reason for hiding this comment

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

This option is documented at

When combined with the approximation option, we get the expectation values as follows:
* shots is None and approximation=False: Return an expectation value with sampling-noise w/
warning.
* shots is int and approximation=False: Return an expectation value with sampling-noise.
* shots is None and approximation=True: Return an exact expectation value.
* shots is int and approximation=True: Return expectation value with sampling-noise using a
normal distribution approximation.
. Honestly, I don't understand why it did not work. I suspect a bug in the Estimator class in combination with skip_transpilation=True.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's likely. Something to look at in a follow-up.

job = estimator.run([qc1, qc2, qc1, qc1, qc2], ["Z"] * 5, [[], [1], [], [], [1]])
result = job.result()
np.testing.assert_allclose(result.values, [1, 0, 1, 1, 0], atol=1e-10)
Expand Down
Loading