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

Deprecate execute() #11044

Merged
merged 17 commits into from
Jan 13, 2024
Merged

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Oct 19, 2023

Summary

The execute() function is as old as the SDK and it was always a high-level combinant function to say "here, a circuit, do your thing". That is exactly what Qiskit Primitives are about. Time to deprecated it.

Closes #7892
Closes #7640

@1ucian0 1ucian0 requested a review from a team as a code owner October 19, 2023 05:53
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@1ucian0 1ucian0 added this to the 0.45.0 milestone Oct 19, 2023
@1ucian0 1ucian0 added the Changelog: Deprecation Include in "Deprecated" section of changelog label Oct 19, 2023
qiskit/execute_function.py Outdated Show resolved Hide resolved
Qiskit's :func:`~.execute_function.execute` function is deprecated.
This function served as a high-level wrapper around transpiling
a circuit with some transpile options and running it on a backend
with some run options. To do the same thing, you can explicitly
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to call out the sampler here too? The BackendSampler class is fairly straightforward mapping to what execute() does (although imo execute() or transpile() followed by backend.run() are much easier to work with).

Copy link
Member Author

Choose a reason for hiding this comment

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

I added an example in 0367d40

@1ucian0 1ucian0 requested a review from ikkoham as a code owner October 19, 2023 10:29
@jakelishman
Copy link
Member

(A minor note: CI's likely to be busy today, so if we're able to try and keep the number of commits we submit to CI down by doing more testing locally, it'll help keep the rc1 release more to time.)

@1ucian0 1ucian0 mentioned this pull request Oct 19, 2023
@mtreinish mtreinish modified the milestones: 0.45.0, 0.46.0 Oct 19, 2023
@1ucian0 1ucian0 changed the base branch from main to stable/0.45 November 1, 2023 14:51
@1ucian0 1ucian0 changed the base branch from stable/0.45 to main November 3, 2023 11:23
@1ucian0 1ucian0 changed the base branch from main to stable/0.46 November 3, 2023 20:28
@1ucian0 1ucian0 changed the base branch from stable/0.46 to main November 3, 2023 20:28
@1ucian0 1ucian0 changed the base branch from main to stable/0.46 November 3, 2023 20:32
@1ucian0 1ucian0 force-pushed the deprecate/execute/1 branch from f9c83b8 to c8e6f3c Compare November 3, 2023 20:34
Co-authored-by: Matthew Treinish <[email protected]>
@coveralls
Copy link

Pull Request Test Coverage Report for Build 6749790272

  • 4 of 4 (100.0%) changed or added relevant lines in 2 files are covered.
  • 182 unchanged lines in 20 files lost coverage.
  • Overall coverage decreased (-0.06%) to 86.915%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.76%
qiskit/primitives/backend_sampler.py 1 98.84%
qiskit/transpiler/passes/optimization/normalize_rx_angle.py 1 97.96%
qiskit/primitives/base/base_primitive.py 3 90.32%
qiskit/primitives/estimator.py 3 95.06%
qiskit/primitives/sampler.py 3 95.77%
qiskit/pulse/library/waveform.py 3 93.75%
crates/qasm2/src/lex.rs 4 91.92%
qiskit/execute_function.py 4 77.78%
qiskit/circuit/init.py 5 85.29%
Totals Coverage Status
Change from base Build 6749032211: -0.06%
Covered Lines: 74350
Relevant Lines: 85543

💛 - Coveralls

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.

Thanks for this, Luciano. A few more notes for consideration:

  • in examples/python, there's still uses of execute. I don't know if we still even want to keep that folder, but if so, we probably ought to change them to at least be backend.run/transpile if not Sampler.
  • test/randomized still has a couple of uses of execute
  • the docstring of qiskit.quantum_info.analysis.distance.hellinger_fidelity still uses execute in an example

I noticed there's a few places in the tests where execute was replaced only with backend.run (no transpile), typically for BasicAer backends. I suspect that's probably a fine change and won't affect anything, just pointing it out. There's a few of those changes that have left a spurious seed_transpiler argument in backend.run, though, which it looks like BasicAer just ignores. We should probably tidy those up.

Comment on lines -36 to +35
self._result1 = execute(self._qc1, self.backend).result()
self._result1 = self.backend.run(self._qc1).result()
Copy link
Member

Choose a reason for hiding this comment

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

Not that I imagine it will matter here, but technically this is a behavioural change due to the missing transpile. Same comment for most changes in the next two files.

test/python/basicaer/test_multi_registers_convention.py Outdated Show resolved Hide resolved
Comment on lines 491 to 492
backend = BasicAer.get_backend("unitary_simulator")
simulated = execute(qc, backend).result().get_unitary(qc)
simulated = backend.run(transpile(qc, backend)).result().get_unitary(qc)
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't mind just changing these into simulated = Operator(qc), but this is also fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 6ef382a

Comment on lines 105 to 108
job = execute(
self.circuit,
backend,
job = backend.run(
transpile(self.circuit, backend),
optimization_level=optimization_level,
seed_simulator=42,
seed_transpiler=42,
Copy link
Member

Choose a reason for hiding this comment

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

This, and the other test in this file, set seed_transpiler which ideally needs moving into the transpile call.

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed. Done in 2fa2580

@1ucian0
Copy link
Member Author

1ucian0 commented Jan 12, 2024

Good catches!

  • in examples/python, there's still uses of execute. I don't know if we still even want to keep that folder, but if so, we probably ought to change them to at least be backend.run/transpile if not Sampler.

Fixed in 39535b9

  • test/randomized still has a couple of uses of execute

Fixed in 1bea14b

  • the docstring of qiskit.quantum_info.analysis.distance.hellinger_fidelity still uses execute in an example

Fixed in 39535b9

I noticed there's a few places in the tests where execute was replaced only with backend.run (no transpile), typically for BasicAer backends. I suspect that's probably a fine change and won't affect anything, just pointing it out.

Yes. It was intentional for the cases where it was possible, as a way to minimize the changes.

There's a few of those changes that have left a spurious seed_transpiler argument in backend.run, though, which it looks like BasicAer just ignores. We should probably tidy those up.

done in 05dd686

jakelishman
jakelishman previously approved these changes Jan 12, 2024
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 pushed up a couple more commits just to squash a couple more places I spotted, or places where we using a warning skip when Operator(qc) was just as easy.

I found one place that was skipping warnings for bind_parameters with a module='test\.python\.circuit\.test_parameters' (or something) that was causing an execute to get missed, but that's actually a good think - it shows the stacklevel was set correctly, otherwise it wouldn't have been skipped by that! (I fixed the skip by adding a regex match for messages mentioning the intended target.)

There's a couple of places that still use execute in tests along with other deprecated or dead code that's being tidied up elsewhere, so I've just left them. Let's get this into the merge queue.

@jakelishman jakelishman enabled auto-merge January 13, 2024 02:50
@jakelishman jakelishman added this pull request to the merge queue Jan 13, 2024
Merged via the queue into Qiskit:stable/0.46 with commit 112ae8d Jan 13, 2024
12 checks passed
@1ucian0 1ucian0 deleted the deprecate/execute/1 branch January 15, 2024 13:11
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

qiskit.execute() does not use the scheduling_method argument
5 participants