-
Notifications
You must be signed in to change notification settings - Fork 127
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 job splitting information to the experiment class #1247
Comments
Hey @coruscating I wanna work on this issue. |
@nayan2167 Great! If you're on the Qiskit Slack, I can add you to the experiments-dev channel where we discuss development on Qiskit Experiments. |
yup I already joined Qiskit Slack |
Hi @coruscating can you review it please def _max_circuits(self):
"""Calculate the maximum number of circuits per job for the experiment."""
# Get max circuits for job splitting
max_circuits_option = getattr(self.experiment_options, "max_circuits", None)
max_circuits_backend = self._backend_data.max_circuits
if max_circuits_option and max_circuits_backend:
return min(max_circuits_option, max_circuits_backend)
elif max_circuits_option:
return max_circuits_option
else:
return max_circuits_backend
def job_info(self, backend=None):
"""Get information about job distribution for the experiment on a specific backend."""
if backend is None:
backend = self.backend
max_circuits = self._max_circuits()
total_circuits = len(self.circuits)
if total_circuits <= max_circuits:
return {
"circuits_per_job": total_circuits,
"num_jobs": 1
}
else:
num_jobs = (total_circuits + max_circuits - 1) // max_circuits
return {
"circuits_per_job": max_circuits,
"num_jobs": num_jobs
}
def _run_jobs(self, circuits: List[QuantumCircuit], **run_options) -> List[Job]:
"""Run circuits on backend as 1 or more jobs."""
max_circuits = self._max_circuits()
if len(circuits) <= max_circuits:
job_circuits = [circuits]
else:
job_circuits = [
circuits[i:i + max_circuits] for i in range(0, len(circuits), max_circuits)
]
jobs = [self.backend.run(circs, **run_options) for circs in job_circuits]
return jobs |
This is a good start, thanks @nayan2167. A few comments:
Please open a pull request after making these changes so it will be easier to make comments. |
Hi @coruscating I am not quite understanding A test should be added to check that |
This PR aims to solve issue #1247 als the changes are similar to PR #1248 ### Summary: This pull request aims to enhance the user experience by providing clearer insights into the structure of experiments and their distribution across backends. It introduces two new public methods, `_max_circuits()` and `job_info(backend)`, while also refactoring the existing `_run_jobs()` method for better code organization and reuse of logic. ### Proposed Changes: Add` _max_circuits()` Method: This method will calculate the maximum number of circuits that can be included in a single job. This method will encapsulate the logic previously present in the ` _run_jobs()` method to determine the maximum circuits per job. Add `job_info(backend)` Method: This method will utilize the `_max_circuits()` method to provide users with information about the experiment's configuration for a specific backend. If the backend argument is provided, the method will return the number of circuits and the number of jobs the experiment will be split into on that backend. If the backend argument is not provided, the method will rely on the backend already specified in the experiment. Refactor `_run_jobs()` Method: The existing `_run_jobs()` method will be refactored to make use of the `_max_circuits()` method. This change will enhance code readability and maintainability by segregating the logic related to job distribution from the actual job execution logic. ### Testing Added `test_max_circuits` for testing of `_max_circuits()` and `test_job_info` for testing of `job_info(backend)` these tests ensure that methods functioning correctly --------- Co-authored-by: Helena Zhang <[email protected]>
…kit-community#1281) This PR aims to solve issue qiskit-community#1247 als the changes are similar to PR qiskit-community#1248 ### Summary: This pull request aims to enhance the user experience by providing clearer insights into the structure of experiments and their distribution across backends. It introduces two new public methods, `_max_circuits()` and `job_info(backend)`, while also refactoring the existing `_run_jobs()` method for better code organization and reuse of logic. ### Proposed Changes: Add` _max_circuits()` Method: This method will calculate the maximum number of circuits that can be included in a single job. This method will encapsulate the logic previously present in the ` _run_jobs()` method to determine the maximum circuits per job. Add `job_info(backend)` Method: This method will utilize the `_max_circuits()` method to provide users with information about the experiment's configuration for a specific backend. If the backend argument is provided, the method will return the number of circuits and the number of jobs the experiment will be split into on that backend. If the backend argument is not provided, the method will rely on the backend already specified in the experiment. Refactor `_run_jobs()` Method: The existing `_run_jobs()` method will be refactored to make use of the `_max_circuits()` method. This change will enhance code readability and maintainability by segregating the logic related to job distribution from the actual job execution logic. ### Testing Added `test_max_circuits` for testing of `_max_circuits()` and `test_job_info` for testing of `job_info(backend)` these tests ensure that methods functioning correctly --------- Co-authored-by: Helena Zhang <[email protected]>
Suggested feature
Users often want to know how many circuits are in the experiment and whether the experiment will be split into multiple jobs if run on a specific backend. This logic is currently handled in
_run_jobs()
, but we would like there to be a public method that provides the user with this information.I propose the following change:
experiment._max_circuits()
which splits out the logic in_run_jobs()
that calculates the maximum number of circuits per jobexperiment.job_info(backend)
which uses_max_circuits()
to tell the user how many circuits and how many jobs their experiment will consist of on a particular backend. If the backend is not provided in the run parameters, the experiment must already have a backend specified._run_jobs()
to use_max_circuits()
.The text was updated successfully, but these errors were encountered: