Beispiel #1
0
 def run_with_api(self, api):
     """Creates a new ``IBMQJob`` running with the provided API object."""
     backend = IBMQBackend(mock.Mock(), mock.Mock(), mock.Mock(), api=api)
     self._current_api = api
     self._current_qjob = backend.run(qobj=FakeQobj(), validate_qobj=True)
     self._current_qjob.refresh = mock.Mock()
     return self._current_qjob
 def run_with_api(self, api):
     """Creates a new ``IBMQJob`` running with the provided API object."""
     backend = IBMQBackend(mock.Mock(),
                           mock.Mock(),
                           mock.Mock(),
                           api_client=api)
     self._current_api = api
     self._current_qjob = backend.run(qobj=FakeQobj())  # pylint: disable=no-value-for-parameter
     self._current_qjob.refresh = mock.Mock()
     return self._current_qjob
Beispiel #3
0
def submit_and_cancel(backend: IBMQBackend) -> IBMQJob:
    """Submit and cancel a job.

    Args:
        backend: Backend to submit the job to.

    Returns:
        Cancelled job.
    """
    qobj = bell_in_qobj(backend=backend)
    job = backend.run(qobj, validate_qobj=True)
    cancel_job(job, True)
    return job
Beispiel #4
0
def submit_job_bad_shots(backend: IBMQBackend) -> IBMQJob:
    """Submit a job that will fail due to too many shots.

    Args:
        backend: Backend to submit the job to.

    Returns:
        Submitted job.
    """
    qobj = bell_in_qobj(backend=backend)
    qobj.config.shots = 10000  # Modify the number of shots to be an invalid amount.
    job_to_fail = backend.run(qobj, validate_qobj=True)
    return job_to_fail
Beispiel #5
0
def submit_job_one_bad_instr(backend: IBMQBackend) -> IBMQJob:
    """Submit a job that contains one good and one bad instruction.

    Args:
        backend: Backend to submit the job to.

    Returns:
        Submitted job.
    """
    qc_new = transpile(ReferenceCircuits.bell(), backend)
    qobj = assemble([qc_new] * 2, backend=backend)
    qobj.experiments[1].instructions[1].name = 'bad_instruction'
    job = backend.run(qobj, validate_qobj=True)
    return job
Beispiel #6
0
def submit_bad_job(backend: IBMQBackend) -> IBMQJob:
    """Submit a job that is destined to fail.

    Args:
        backend: Backend to submit the job to.

    Returns:
        Failed job.
    """
    # Submit a job that will fail.
    qobj = bell_in_qobj(backend=backend)
    qobj.config.shots = 10000  # Modify the number of shots to be an invalid amount.
    job_to_fail = backend.run(qobj, validate_qobj=True)
    job_to_fail.wait_for_final_state()
    return job_to_fail
Beispiel #7
0
def submit_job_one_bad_instr(backend: IBMQBackend) -> IBMQJob:
    """Submit a job that contains one good and one bad instruction.

    Args:
        backend: Backend to submit the job to.

    Returns:
        Submitted job.
    """
    qc_new = transpile(ReferenceCircuits.bell(), backend)
    if backend.configuration().simulator:
        # Specify method so it doesn't fail at method selection.
        qobj = assemble([qc_new] * 2, backend=backend, method="statevector")
    else:
        qobj = assemble([qc_new] * 2, backend=backend)
    qobj.experiments[1].instructions[1].name = 'bad_instruction'
    job = backend.run(qobj)
    return job