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

Backend argument in experiment constructors #1020

Closed
yaelbh opened this issue Jan 22, 2023 · 6 comments · Fixed by #1115
Closed

Backend argument in experiment constructors #1020

yaelbh opened this issue Jan 22, 2023 · 6 comments · Fixed by #1115
Assignees

Comments

@yaelbh
Copy link
Collaborator

yaelbh commented Jan 22, 2023

BaseExperiment has an optional backend parameter. Do we want to make it mandatory, and remove the backend parameter from the run method?

If no: some experiments don't have a backend parameter in their constructors. Do we want, for the sake of uniformity, to instruct that all the experiments have this parameter? How can we enforce this instruction?

@yaelbh
Copy link
Collaborator Author

yaelbh commented Jan 22, 2023

Also readout error experiments and tomography experiments.
In the case of tomography, the base class has the backend parameter, but this in practice has no effect since the state tomography and process tomography classes don't.

@wshanks
Copy link
Collaborator

wshanks commented Jan 22, 2023

Personally, I would prefer that backend were an __init__ argument. It is needed for core functionality of the experiment class and with it optional we have to jump through extra hoops to check if a backend is set or not and substitute default values when they can't be pulled from the backend. There is some case for building an experiment and then running it on different backends but I think the more common workflow is to focus on one backend at a time, and in that case passing the backend at initialization is not a burden.

If we want to preserve the ability to initialize an experiment instance and inspect it without setting up a specific backend, I wonder if we could define a generic backend and set it as the default argument for when a backend is not passed by the user (def __init__(self, qubits, backend=GenericBackend(), ...).

@yaelbh
Copy link
Collaborator Author

yaelbh commented Jan 22, 2023

Note that, with the generic experiment, we again don't catch cases where experiment developers simply forget backend in their expeiment __init__. Like what seems to be the case with tomography.

@chriseclectic
Copy link
Collaborator

@yaelbh readout error and tomography now all take backend kwargs in init since #1019 #998. I personally like having backend as an optional kwarg in all experiments, so you can either set it at init, or you can set it at run. So in principle you can configure an experiment and run it an on multiple backends.

That said it would likely allow some simplifying of the base experiment if backend could only be set at init (you could remove the backend setter and set_backend method). The purpose of the set_backend method in base experiment was so that any functionality that depended on a backend could be specified here, but its still up to person writing an experiment to do validation for if backend is not set where it might be needed (ie in circuit generation). I suppose we could automate that exception handling by making the backend getter raise an exception if its None.

@yaelbh
Copy link
Collaborator Author

yaelbh commented Feb 1, 2023

In a meeting we decided:

  1. We will add the parameter to our existing experiment constructors where it is missing.
  2. We will not enforce it to be present in experiment constructors.

@yaelbh
Copy link
Collaborator Author

yaelbh commented Feb 1, 2023

One of the considerations to not enforcing was related to the fact backends are not serializable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants