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

Add private primitive attributes removed by qiskit #2048

Merged
merged 6 commits into from
Feb 2, 2024

Conversation

ihincks
Copy link
Contributor

@ihincks ihincks commented Feb 2, 2024

Summary

Qiskit/qiskit#11051 removed some private attributes from Sampler and Estimator in the process of streamlining the API. This PR adds them back in because super() no longer does so.

Details and comments

@jakelishman
Copy link
Member

Using Qiskit 1.0.0rc1, this gets me further through the Aer test suite, but then all the primitives tests fail with an error like this:

{6} test.terra.primitives.test_sampler.TestSampler.test_multiple_cregs [0.011242s] ... FAILED

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):

      File "/Users/jake/code/qiskit/aer/test/terra/primitives/test_sampler.py", line 270, in test_multiple_cregs
    result = Sampler().run(qc, shots=100).result()

      File "/Users/jake/code/qiskit/terra/qiskit/primitives/base/base_sampler.py", line 200, in run
    return self._run(

      File "/Users/jake/code/qiskit/aer/qiskit_aer/primitives/sampler.py", line 165, in _run
    job.submit()

    AttributeError: 'PrimitiveJob' object has no attribute 'submit'

@1ucian0
Copy link
Member

1ucian0 commented Feb 2, 2024

PrimitiveJob.submit was remove in Qiskit/qiskit#11552

@jakelishman
Copy link
Member

Also there's two tests that do this, but I think that's it for the differences:

test.terra.primitives.test_estimator.TestEstimator.test_init_observable_from_operator_1_True
--------------------------------------------------------------------------------------------

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):

      File "/Users/jake/code/qiskit/venv310/lib/python3.10/site-packages/ddt.py", line 225, in wrapper
    return func(self, *args, **kwargs)

      File "/Users/jake/code/qiskit/aer/test/terra/primitives/test_estimator.py", line 100, in test_init_observable_from_operator
    result = est.run([circuit], [matrix], seed=15, shots=8192).result()

      File "/Users/jake/code/qiskit/terra/qiskit/primitives/base/base_estimator.py", line 246, in run
    circuits, observables, parameter_values = validation._validate_estimator_args(

      File "/Users/jake/code/qiskit/terra/qiskit/primitives/base/validation.py", line 56, in _validate_estimator_args
    observables = _validate_observables(observables)

      File "/Users/jake/code/qiskit/terra/qiskit/primitives/base/validation.py", line 175, in _validate_observables
    return tuple(init_observable(obs) for obs in observables)

      File "/Users/jake/code/qiskit/terra/qiskit/primitives/base/validation.py", line 175, in <genexpr>
    return tuple(init_observable(obs) for obs in observables)

      File "/Users/jake/code/qiskit/terra/qiskit/primitives/utils.py", line 64, in init_observable
    raise QiskitError(f"observable type not supported: {type(observable)}")

    qiskit.exceptions.QiskitError: "observable type not supported: <class 'qiskit.quantum_info.operators.operator.Operator'>"


test.terra.primitives.test_estimator.TestEstimator.test_init_observable_from_operator_2_False
---------------------------------------------------------------------------------------------

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):

      File "/Users/jake/code/qiskit/venv310/lib/python3.10/site-packages/ddt.py", line 225, in wrapper
    return func(self, *args, **kwargs)

      File "/Users/jake/code/qiskit/aer/test/terra/primitives/test_estimator.py", line 100, in test_init_observable_from_operator
    result = est.run([circuit], [matrix], seed=15, shots=8192).result()

      File "/Users/jake/code/qiskit/terra/qiskit/primitives/base/base_estimator.py", line 246, in run
    circuits, observables, parameter_values = validation._validate_estimator_args(

      File "/Users/jake/code/qiskit/terra/qiskit/primitives/base/validation.py", line 56, in _validate_estimator_args
    observables = _validate_observables(observables)

      File "/Users/jake/code/qiskit/terra/qiskit/primitives/base/validation.py", line 175, in _validate_observables
    return tuple(init_observable(obs) for obs in observables)

      File "/Users/jake/code/qiskit/terra/qiskit/primitives/base/validation.py", line 175, in <genexpr>
    return tuple(init_observable(obs) for obs in observables)

      File "/Users/jake/code/qiskit/terra/qiskit/primitives/utils.py", line 64, in init_observable
    raise QiskitError(f"observable type not supported: {type(observable)}")

    qiskit.exceptions.QiskitError: "observable type not supported: <class 'qiskit.quantum_info.operators.operator.Operator'>"

@ihincks
Copy link
Contributor Author

ihincks commented Feb 2, 2024

all the primitives tests fail with an error like this

submit() was removed as a public method on our base job class, so the most direct solution is to call _submit().

@jakelishman
Copy link
Member

As of 71f4ca8, with the merge of #2047, this passes the test suite on 1.0.0rc1 except for the two things about Operator in my previous comment, but lint appears to be saying that PrimitiveJob._submit didn't exist in 0.45/0.46, so we need a fix such that Aer works with both.

@ihincks
Copy link
Contributor Author

ihincks commented Feb 2, 2024

Thanks, I'm doing the wrong thing and trying to get away without setting up my test env locally, as I've never worked on aer.

@jakelishman
Copy link
Member

Yeah no worries, I suspected that might be the case, and I have an environment to hand here already.

@ihincks ihincks marked this pull request as ready for review February 2, 2024 17:25
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.

This passes the test suite locally for me for Qiskits 0.45.3, 0.46.0 and 1.0.0rc1. Thanks Ian!

This should be reviewed by a member of the primitives team before more.

@jakelishman jakelishman added the automerge This PR will automatically merge once its CI has passed label Feb 2, 2024
@mergify mergify bot merged commit 9f45068 into Qiskit:main Feb 2, 2024
37 checks passed
@ihincks ihincks deleted the fix-prim-deprecations branch February 2, 2024 18:26
doichanj pushed a commit to doichanj/qiskit-aer that referenced this pull request Feb 6, 2024
* Add private primitive attributes removed by qiskit

* wrong url

* call private submit method

* Make submission compatible with qiskit <=0.45

* Skip Operator test is qiskit >=1.0

* grr lint
@doichanj doichanj mentioned this pull request Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge This PR will automatically merge once its CI has passed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants