-
Notifications
You must be signed in to change notification settings - Fork 64
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 open batches to pulser-pasqal #701
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.
Thanks for this first draft @oliver-gordon ! I have a left few comments, but let me focus on a design question here.
Does it make sense to use the same run()
method for both starting a submission and adding jobs to one? I suggested below that it made more sense as a separate backend method, but it would also work as a method of the RemoteResults
class you get after you call run()
.
EDIT: That was a bad idea, let's please disregard it.
Should we not introduce the notion of batch at all in this lib? If it becomes the main entrypoint to submit jobs, shouldn't we use the same language as on other components of our platform - where the notion of batch is central. I am worried it would create some confusion for users when switching from pulser-pasqal to the user portal. Curious what you guys think on that front |
My main suggestion for the user interface compared to what is done here is to not ask the user for the submission_id explicitly but handle it for them; we only need the user to let us know when they want to open the batch and when they want to close it. We could provide a Example snippet Open batch backend = QPUBackend(seq, connection)
backend.start_session()
# these jobs are automatically added to the batch
results = backend.run(job_params, wait=True)
# some more jobs added to the same batch
results_2 = backend.run(job_params_2, wait=True)
backend.stop_session() Closed batch (no change) backend = QPUBackend(seq, connection)
# Create a closed batch with some jobs
results = backend.run(job_params, wait=True)
# Create another batch with some jobs
results_2 = session.run(job_params_2, wait=True) We could also provide a context manager to handle the batch lifecycle Starting the context manager would create a batch and store the associated If the run method is used outside the context manager, it creates a closed batch with the jobs passed as argument. e.g the user interface would look something like Open batch example: backend = QPUBackend(seq, connection)
# opening the context manager creates a batch.
# Here I used the wording "start session" but it could be called "open_batch"
with backend.start_session():
# these jobs are automatically added to the batch
results = backend.run(job_params, wait=True)
# some more jobs added to the same batch
results_2 = backend.run(job_params_2, wait=True)
#we exited the context manager so the batch is now closed Closed batch (no change) backend = QPUBackend(seq, connection)
# Create a closed batch with some jobs
results = backend.run(job_params, wait=True)
# Create another batch with some jobs
results_2 = session.run(job_params_2, wait=True) Thoughts about this general interface? What about the context manager? It's simply syntactic sugar but it can help prevent users forgetting to close their batch |
@MatthieuMoreau0 |
Indeed, I have avoided referring to "batches" so far, but in reality "submission" is still only an internal parameter too, so we could start calling it "batch" from the get go. However, I'm not sure about this because it seems to me that the way the user will interact with the |
I quite like this, I find it elegant, relatively simple and it meets the criteria of having the actions performed by the backend. One question though: when you call |
I personally would welcome having the concept of Batch in Pulser. However it would be in a way that I can re-use in downstreams libraries, and ideally we'd have it consistent with the cloud backend and emulation backends (even if that means usually wrapping the results of the emulator as a single job in a batch). Due to that, I think I Agree with Oliver that it might be out of scope here. |
I was not suggesting to introduce batches in this MR specifically either; and definitely not as an object the user should manipulate. I was wondering mostly about the wording because as Henrique mentioned |
I don't know tbh. Whatever makes most sense given the current implementation of backends in Pulser |
In Henriques example with open batches what if we do: backend = QPUBackend(seq, connection)
# opening the context manager creates a batch.
with batch as backend.start_session():
# we can (optionally?) pass the context to run
results = backend.run(job_params, wait=True, batch=batch)
# some more jobs added to the same batch, and the results
# are just the results from that single run
results_2 = backend.run(job_params_2, wait=True, batch) With the actual batch implementation could come in a followup, so that we can think of that interface a bit/not scope creep this mr |
*Matthieu's example, I don't want to take away his credit 🙂
I'm not convinced with exposing a batch object here, I feel like it strays away from the backend interface philosophy and it defeats the purpose of trying to simplify things for the more "junior" Pulser users. Let's remember that For the purposes of this PR (ie just allowing an open batch/submission), I feel like we can get away with the backend storing internally the open batch ID and just adding jobs to it on every |
I suppose there are some assumptions that the runtime doesn't end for us to retain an ID as a class property? What if a user is running incredibly short lived scripts? or executing something again to add another job after already creating and submitting a batch? We would be missing the submission_id property I can't speak for the regular usecases of pulser-pasqal users but, this one seems rather plausible? |
I would go back to the argument that using |
I can live with this. I'll push my change to the draft today to see if we're aligned on how it will look |
To cover this the I think we can start without that optional argument in this MR and wait for user feedback. |
8a79168
to
3f3a07c
Compare
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.
Looks good to me.
I would like to reiterate the question about naming things submission
vs batch
especially now that these are public attributes/methods using these names. imo calling things batch
makes the most sense.
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.
Ok, this still needs some work.
Apart from the comments I just left, I would suggest that the open submission functionality is moved to RemoteBackend
instead of being defined just in QPUBackend
. Also, the ability to use open submissions should depend on whether the RemoteConnection
supports it
fix rebase, and linting fix rebase, and linting
fix rebase, and linting fix rebase, and linting fix rebase, and linting fix rebase, and linting
MR feedback
Still needed:
|
@oliver-gordon @MatthieuMoreau0 I managed to replace Submission -> Batch in a backwards compatible way everywhere except in |
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.
A few suggestions to deprecate "submission" but otherwise lgtm
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.
Thanks for the changes!
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
**Main changes:** - Reworking the NoiseModel interface (#710) - Allow modification of the EOM setpoint without disabling EOM mode (#708) - Enable definition of effective noise operators in all basis (#716) - Add leakage (#720) - Support differentiability through Torch tensors (#703) - Add from_abstract_repr to Device and VirtualDevice (#727) - [FEAT] Handle batches with partial results (#707) - Add open batches to pulser-pasqal (#701)
On the PCS we support open batches, to continuously add new jobs and there is support for this in the SDK but this has not been translated over to pulser-pasqal yet.
Due to the abstraction of batches in this lib I've attempted to keep away the term batch and just flow with open_submission, since our known reference is a submission_id.
When creating a new submission, a user is to either pass the submission_id and we can append new jobs to an existing batch or a boolean flag to indicate whether or not we want the submission being created to be left as open