def run_on_backend(backend, qobj, backend_options=None, noise_config=None, skip_qobj_validation=False): if skip_qobj_validation: job_id = str(uuid.uuid4()) if is_simulator_backend(backend): if is_aer_provider(backend): job = backend.run(qobj, **backend_options, **noise_config) else: job = SimulatorsJob(backend, job_id, backend._run_job, qobj) job._future = job._executor.submit(job._fn, job._job_id, job._qobj) elif is_ibmq_provider(backend): job = IBMQJob(backend, None, backend._api, not is_simulator_backend(backend), qobj=qobj) job._future = job._executor.submit(job._fn, job._job_id, job._qobj) else: logger.info( "Can not skip qobj validation for the third-party provider.") job = backend.run(qobj, **backend_options, **noise_config) return job else: job = backend.run(qobj, **backend_options, **noise_config) return job
def run(self, qobj, backend_options=None): """Run qobj asynchronously. Args: qobj (Qobj): payload of the experiment backend_options (dict): backend options Returns: SimulatorsJob: derived from BaseJob Additional Information: backend_options: Is a dict of options for the backend. It may contain * "initial_statevector": vector_like The "initial_statevector" option specifies a custom initial initial statevector for the simulator to be used instead of the all zero state. This size of this vector must be correct for the number of qubits in all experiments in the qobj. Example:: backend_options = { "initial_statevector": np.array([1, 0, 0, 1j]) / np.sqrt(2), } """ self._set_options(qobj_config=qobj.config, backend_options=backend_options) job_id = str(uuid.uuid4()) job = SimulatorsJob(self, job_id, self._run_job, qobj) job.submit() return job
def run_on_backend(backend, qobj, backend_options=None, noise_config=None, skip_qobj_validation=False): if skip_qobj_validation: job_id = str(uuid.uuid4()) if backend.configuration().simulator: if type(backend.provider()).__name__ == 'AerProvider': from qiskit.providers.aer.aerjob import AerJob job = AerJob(backend, job_id, backend._run_job, qobj, backend_options, noise_config) job._future = job._executor.submit(job._fn, job._job_id, job._qobj, backend_options, noise_config) else: job = SimulatorsJob(backend, job_id, backend._run_job, qobj) job._future = job._executor.submit(job._fn, job._job_id, job._qobj) else: job = IBMQJob(backend, None, backend._api, not backend.configuration().simulator, qobj=qobj) job._future = job._executor.submit(job._fn, job._job_id, job._qobj) return job else: job = backend.run(qobj, **backend_options, **noise_config) return job
def run(self, qobj): """Run a Qobj on the backend. Args: qobj (dict): job description Returns: SimulatorsJob: derived from BaseJob """ job_id = str(uuid.uuid4()) job = SimulatorsJob(self, job_id, self._run_job, qobj) job.submit() return job
def run_on_backend(backend, qobj, backend_options=None, noise_config=None, skip_qobj_validation=False): if skip_qobj_validation: job_id = str(uuid.uuid4()) if is_simulator_backend(backend): if is_aer_provider(backend): from qiskit.providers.aer.aerjob import AerJob temp_backend_options = backend_options[ 'backend_options'] if backend_options != {} else None temp_noise_config = noise_config[ 'noise_model'] if noise_config != {} else None job = AerJob(backend, job_id, backend._run_job, qobj, temp_backend_options, temp_noise_config, False) job._future = job._executor.submit(job._fn, job._job_id, job._qobj, *job._args) else: backend._set_options(qobj_config=qobj.config, **backend_options) job = SimulatorsJob(backend, job_id, backend._run_job, qobj) job._future = job._executor.submit(job._fn, job._job_id, job._qobj) elif is_ibmq_provider(backend): # TODO: IBMQJob performs validation during the constructor. the following lines deos not # skip validation but run as is. from qiskit.providers.ibmq.ibmqjob import IBMQJob job = IBMQJob(backend, None, backend._api, not is_simulator_backend(backend), qobj=qobj) job._future = job._executor.submit(job._fn, job._job_id, job._qobj) else: logger.info( "Can not skip qobj validation for the third-party provider.") job = backend.run(qobj, **backend_options, **noise_config) return job else: job = backend.run(qobj, **backend_options, **noise_config) return job
def run(self, qobj, backend_options=None): """Run qobj asynchronously. Args: qobj (Qobj): payload of the experiment backend_options (dict): backend options Returns: SimulatorsJob: derived from BaseJob Additional Information:: backend_options: Is a dict of options for the backend. It may contain * "initial_unitary": matrix_like * "chop_threshold": double The "initial_unitary" option specifies a custom initial unitary matrix for the simulator to be used instead of the identity matrix. This size of this matrix must be correct for the number of qubits inall experiments in the qobj. The "chop_threshold" option specifies a trunctation value for setting small values to zero in the output unitary. The default value is 1e-15. Example:: backend_options = { "initial_unitary": np.array([[1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0]]) "chop_threshold": 1e-15 } """ self._set_options(qobj_config=qobj.config, backend_options=backend_options) job_id = str(uuid.uuid4()) job = SimulatorsJob(self, job_id, self._run_job, qobj) job.submit() return job
def run(self, qobj): """Run a qobj on the backend.""" job_id = str(uuid.uuid4()) job = SimulatorsJob(self, job_id, self._run_job, qobj) job.submit() return job