Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dcmckayibm committed Oct 7, 2024
1 parent f7f7c73 commit 032abbf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
13 changes: 7 additions & 6 deletions qiskit_experiments/framework/base_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from qiskit.exceptions import QiskitError
from qiskit.qobj.utils import MeasLevel
from qiskit.providers.options import Options
from qiskit.primitives.base import BaseSamplerV2
from qiskit_ibm_runtime import SamplerV2 as Sampler
from qiskit_experiments.framework import BackendData
from qiskit_experiments.framework.store_init_args import StoreInitArgs
Expand Down Expand Up @@ -199,7 +200,7 @@ def from_config(cls, config: Union[ExperimentConfig, Dict]) -> "BaseExperiment":

def run(
self,
run_obj: Optional[Union[Backend, Sampler]] = None,
run_obj: Optional[Union[Backend, BaseSamplerV2]] = None,
analysis: Optional[Union[BaseAnalysis, None]] = "default",
timeout: Optional[float] = None,
backend_run: Optional[bool] = None,
Expand Down Expand Up @@ -229,6 +230,9 @@ def run(
ExperimentData container.
"""

if backend_run is not None:
self._backend_run = backend_run

if isinstance(run_obj, Backend) or analysis != "default" or run_options:
# Make a copy to update analysis or backend if one is provided at runtime
experiment = self.copy()
Expand All @@ -241,9 +245,6 @@ def run(
else:
experiment = self

if backend_run is not None:
self._backend_run = backend_run

if experiment.backend is None:
raise QiskitError("Cannot run experiment, no backend has been set.")

Expand All @@ -260,7 +261,7 @@ def run(
run_opts = experiment.run_options.__dict__

# see if sampler was sent in
if isinstance(run_obj, Sampler):
if isinstance(run_obj, BaseSamplerV2):
sampler = run_obj
else:
sampler = None
Expand Down Expand Up @@ -349,7 +350,7 @@ def job_info(self, backend: Backend = None):
}

def _run_jobs(
self, circuits: List[QuantumCircuit], sampler: Sampler = None, **run_options
self, circuits: List[QuantumCircuit], sampler: BaseSamplerV2 = None, **run_options
) -> List[Job]:
"""Run circuits on backend as 1 or more jobs."""
max_circuits = self._max_circuits(self.backend)
Expand Down
33 changes: 18 additions & 15 deletions qiskit_experiments/framework/experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from qiskit.exceptions import QiskitError
from qiskit.providers import Job, Backend, Provider
from qiskit.utils.deprecation import deprecate_arg
from qiskit.primitives import BitArray, SamplerPubResult
from qiskit.primitives import BitArray, SamplerPubResult, BasePrimitiveJob

from qiskit_ibm_experiment import (
IBMExperimentService,
Expand Down Expand Up @@ -740,7 +740,7 @@ def add_data(

def add_jobs(
self,
jobs: Union[Job, List[Job]],
jobs: Union[Job, List[Job], BasePrimitiveJob, List[BasePrimitiveJob]],
timeout: Optional[float] = None,
) -> None:
"""Add experiment data.
Expand Down Expand Up @@ -771,19 +771,22 @@ def add_jobs(
# Add futures for extracting finished job data
timeout_ids = []
for job in jobs:
if self.backend is not None:
backend_name = BackendData(self.backend).name
job_backend_name = BackendData(job.backend()).name
if self.backend and backend_name != job_backend_name:
LOG.warning(
"Adding a job from a backend (%s) that is different "
"than the current backend (%s). "
"The new backend will be used, but "
"service is not changed if one already exists.",
job.backend(),
self.backend,
)
self.backend = job.backend()
if hasattr(job, "backend"):
if self.backend is not None:
backend_name = BackendData(self.backend).name
job_backend_name = BackendData(job.backend()).name
if self.backend and backend_name != job_backend_name:
LOG.warning(
"Adding a job from a backend (%s) that is different "
"than the current backend (%s). "
"The new backend will be used, but "
"service is not changed if one already exists.",
job.backend(),
self.backend,
)
self.backend = job.backend()
else:
self.backend = None

jid = job.job_id()
if jid in self._jobs:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ numpy>=1.17
scipy>=1.4
qiskit>=0.45
qiskit-ibm-experiment>=0.4.6
qiskit_ibm_runtime>=0.29.0
matplotlib>=3.4
uncertainties
lmfit
Expand Down

0 comments on commit 032abbf

Please sign in to comment.