-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 option to run MLAE circuits separately #7428
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty sensible to me, though the algorithms code is far outside my domain. Please could you also add a release note briefly explaining the addition?
(By the way, you don't need to update the PR when there are changes on main - it'll get updated automatically during the merge process.)
run_circuits_as_one_job: If set to True, the necessary circuits will be submitted as | ||
one job. Otherwise, each circuit will be run separately. This is useful for | ||
backends that don't support multi-circuit experiments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use_separate_jobs=False
? (I have very little preference here - just suggesting alternatives.)
A minor wording nitpick: "If set to True" implies to me that that's not the default. It'd perhaps be best to use the words "If set to ..." to talk about the non-default setting.
self._run_circuits_as_one_job = run_circuits_as_one_job | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that backend can be changed after object instantiation, you may want to make this a public attribute so it can be set if the value of the switch isn't known til later.
mlae = MaximumLikelihoodAmplitudeEstimation( | ||
evaluation_schedule=5, | ||
quantum_instance=quantum_instance, | ||
run_circuits_as_one_job=False, | ||
) | ||
|
||
# run the algo | ||
result = mlae.estimate(problem) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to use a mock object to wrap your quantum_instance
's execute
method, and ensure that it's called the number of times you expect - as it stands, this test only ensures that the option is valid, not that it actually separates the circuits.
The QuantumInstance class is supposed to take care of any backend specific requirements in this regard and should be splitting what the algorithm emits in order to meet the backend requirements. I recall there was an earlier issue around this but I thought it was resolved to allow the algorithms to work correctly. Update - just searched for it #6391- I see that refers to the old V1 backend path but I thought the V2 path was ok. Maybe @mtreinish has some thought here? |
Right, I wasn't sure if this repo had up-to-date merge checks ;) Thanks for letting me know!
Huh, it definitely doesn't work with the I know the story is pretty much the same in qiskit-ionq. A while ago they added the option to handle single-element circuit lists (qiskit-community/qiskit-ionq#71). If |
Ok, understood. But I think the right approach is to figure where/why the mismatch is occuring. The QI code uses a run_circuits function which looks for max_experiments property from the backend - maybe that is not being set correctly https://github.com/Qiskit/qiskit-terra/blob/0d85bfe3f4765a64f8e018514daa3898d9cf32af/qiskit/utils/run_circuits.py#L478-L484 It is, as you see, also influenced by an environment variable as retrieved here https://github.com/Qiskit/qiskit-terra/blob/0d85bfe3f4765a64f8e018514daa3898d9cf32af/qiskit/utils/run_circuits.py#L38 Maybe try setting the env var to 1 and see if things work. Then perhaps we cab figure what needs changing to make things work. I would rather not have algorithm specific setting for this aspect since others, like VQE etc etc will produce lists of circuits and all should work with any backend where the QuantumInstance and its use of run_circuits correctly fragments this list into one or more jobs according to any backend limits. |
I was just looking at this bit of code :) MLAE does work if I set it to 1 (and I use the version of azure-quantum from my PR). Is having to set the variable manually on one's machine the intended approach? |
No, that was intended as a manual override that could be used. Ideally of course things should "just work". In that regard the run_circuits was designed to be able to configure itself via information about the backend. This is the other path in the |
My bad, it looks like it does work even without setting this variable! Apologies, I was focusing on the fact that the Note: I only verified this for azure-quantum. I don't think I have the IonQ token that would be necessary to use the qiskit-ionq provider. |
Summary
Certain backends, such as
IonQBackend
in qiskit-ionq, don't support circuit lists in therun
method (see here). In this case, lists that contain a single element are allowed, but not lists with multiple elements. With MLAE it shouldn't matter if the independent circuits are submitted as one job or as several separate job jobs. The latter will probably take more time in most cases, so I kept the current behavior as the default and added an optional argument that splits the circuits into separate jobs.Details and comments
run_circuits_as_one_job
is a bit of an awkward name, but I couldn't think of anything better.