diff --git a/README.md b/README.md index cfd4cd36f7..770a172177 100755 --- a/README.md +++ b/README.md @@ -134,13 +134,13 @@ provider = QiskitRuntimeService(channel='ibm_quantum', token="set your own token backend = provider.get_backend("ibm_kyoto") # create sampler from the actual backend -sampler.from_backend(backend) +sampler = SamplerV2.from_backend(backend) # run a sampler job on the parameterized circuits with noise model of the actual hardware -job3 = sampler.run([(pqc, theta1), (pqc2, theta2)]) +bell_t = transpile(bell, AerSimulator(basis_gates=["ecr", "id", "rz", "sx"]), optimization_level=0) +job3 = sampler.run([bell_t], shots=128) job_result = job3.result() -print(f"Parameterized for Bell circuit w/noise: {job_result[0].data.meas.get_counts()}") - +print(f"counts for Bell circuit w/noise: {job_result[0].data.meas.get_counts()}") ``` ## Contribution Guidelines diff --git a/qiskit_aer/primitives/estimator_v2.py b/qiskit_aer/primitives/estimator_v2.py index a4bdb4da68..bfeeca73c5 100644 --- a/qiskit_aer/primitives/estimator_v2.py +++ b/qiskit_aer/primitives/estimator_v2.py @@ -70,12 +70,14 @@ def __init__( the runtime options (``run_options``). """ self._options = Options(**options) if options else Options() - method = "density_matrix" if "noise_model" in self.options.backend_options else "automatic" - self._backend = AerSimulator(method=method, **self.options.backend_options) - - def from_backend(self, backend, **options): - """use external backend""" - self._backend.from_backend(backend, **options) + self._backend = AerSimulator(**self.options.backend_options) + + @classmethod + def from_backend(cls, backend, **options): + """make new sampler that uses external backend""" + estimator = cls(**options) + estimator._backend = AerSimulator.from_backend(backend) + return estimator @property def options(self) -> Options: diff --git a/qiskit_aer/primitives/sampler_v2.py b/qiskit_aer/primitives/sampler_v2.py index 006fd1a5ff..55a80f405a 100644 --- a/qiskit_aer/primitives/sampler_v2.py +++ b/qiskit_aer/primitives/sampler_v2.py @@ -100,9 +100,12 @@ def __init__( self._options = Options(**options) if options else Options() self._backend = AerSimulator(**self.options.backend_options) - def from_backend(self, backend, **options): - """use external backend""" - self._backend.from_backend(backend, **options) + @classmethod + def from_backend(cls, backend, **options): + """make new sampler that uses external backend""" + sampler = cls(**options) + sampler._backend = AerSimulator.from_backend(backend) + return sampler @property def default_shots(self) -> int: diff --git a/releasenotes/notes/fix_primitiveV2_init-afe7b331ddbef538.yaml b/releasenotes/notes/fix_primitiveV2_init-afe7b331ddbef538.yaml new file mode 100644 index 0000000000..ba319729a9 --- /dev/null +++ b/releasenotes/notes/fix_primitiveV2_init-afe7b331ddbef538.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed init function of EstimatorV2 and SamplerV2 to set `method` in + its option property if there is no `method` in input parameter