コード例 #1
0
 def test_job_qobj(self):
     """Test job.qobj()."""
     for backend in BasicAer.backends():
         with self.subTest(backend=backend):
             qobj = assemble_circuits(self.qc1, TranspileConfig(backend=backend))
             job = backend.run(qobj)
             self.assertEqual(job.qobj(), qobj)
コード例 #2
0
    def test_job_qobj(self):
        """Test job.qobj()."""
        for backend in qiskit.providers.aer.Aer.backends():
            with self.subTest(backend=backend):
                qc1_new = transpile(self.qc1, TranspileConfig(backend=backend))
                qobj = assemble_circuits(qc1_new, RunConfig(shots=1000))

                job = backend.run(qobj)
                self.assertEqual(job.qobj(), qobj)
コード例 #3
0
    def setUp(self):
        super(TestBasicAerQasmSimulator, self).setUp()

        self.seed = 88
        qasm_filename = self._get_resource_path('example.qasm', Path.QASMS)
        transpiled_circuit = QuantumCircuit.from_qasm_file(qasm_filename)
        transpiled_circuit.name = 'test'
        transpiled_circuit = transpile(transpiled_circuit,
                                       TranspileConfig(backend=self.backend))
        self.qobj = assemble_circuits(transpiled_circuit,
                                      RunConfig(shots=1000))
コード例 #4
0
ファイル: execute.py プロジェクト: jagunnels/qiskit-sdk-py
def execute_circuits(circuits,
                     backend,
                     qobj_header=None,
                     transpile_config=None,
                     run_config=None,
                     **kwargs):
    """Executes a list of circuits.

    Args:
        circuits (QuantumCircuit or list[QuantumCircuit]): circuits to execute
        backend (BaseBackend): a backend to execute the circuits on
        qobj_header (QobjHeader): User input to go in the header
        transpile_config (TranspileConfig): Configurations for the transpiler
        run_config (RunConfig): Run Configuration
        kwargs: extra arguments used by AER for running configurable backends.
                Refer to the backend documentation for details on these arguments

    Returns:
        BaseJob: returns job instance derived from BaseJob
    """

    # TODO: a hack, remove when backend is not needed in transpile
    # ------
    transpile_config = transpile_config or TranspileConfig()
    transpile_config.backend = backend
    # ------

    # filling in the header with the backend name the qobj was run on
    qobj_header = qobj_header or QobjHeader()
    qobj_header.backend_name = backend.name()

    # default values
    if not run_config:
        # TODO remove max_credits from the default when it is not
        # required by by the backend.
        run_config = RunConfig(shots=1024, max_credits=10, memory=False)

    # transpiling the circuits using the transpiler_config
    new_circuits = transpile(circuits, transpile_config=transpile_config)

    # assembling the circuits into a qobj to be run on the backend
    qobj = assemble_circuits(new_circuits,
                             qobj_header=qobj_header,
                             run_config=run_config)

    # executing the circuits on the backend and returning the job
    return backend.run(qobj, **kwargs)
コード例 #5
0
    def test_qobj_headers_in_result(self):
        """Test that the qobj headers are passed onto the results."""
        custom_qobj_header = {'x': 1, 'y': [1, 2, 3], 'z': {'a': 4}}
        for backend in qiskit.providers.aer.Aer.backends():
            with self.subTest(backend=backend):
                qc1_new = transpile(self.qc1, TranspileConfig(backend=backend))
                qobj = assemble_circuits(qc1_new, RunConfig(shots=1000))

                # Update the Qobj header.
                qobj.header = QobjHeader.from_dict(custom_qobj_header)
                # Update the Qobj.experiment header.
                qobj.experiments[0].header.some_field = 'extra info'

                result = backend.run(qobj).result()
                self.assertEqual(result.header.to_dict(), custom_qobj_header)
                self.assertEqual(result.results[0].header.some_field,
                                 'extra info')
コード例 #6
0
    try:
        # select least busy available device and execute.
        least_busy_device = least_busy(IBMQ.backends(simulator=False))
    except:
        print("All devices are currently unavailable.")

    print("Running on current least busy device: ", least_busy_device)
    print("(with configuration) ")
    pprint.pprint(least_busy_device.configuration())
    print("(with properties) ")
    pprint.pprint(least_busy_device.properties())

    # Transpile the circuits to make them compatible with the experimental backend
    [qc1_new, qc2_new
     ] = transpile(circuits=[qc1, qc2],
                   transpile_config=TranspileConfig(backend=least_busy_device))
    print("Bell circuit before transpile:")
    print(qc1)
    print("Bell circuit after transpile:")
    print(qc1_new)
    print("Superposition circuit before transpile:")
    print(qc2)
    print("Superposition circuit after transpile:")
    print(qc2_new)

    # Assemble the two circuits into a runnable qobj
    qobj = assemble_circuits([qc1_new, qc2_new],
                             run_config=RunConfig(shots=1000))

    # Running qobj on the simulator
    sim_job = qasm_simulator.run(qobj)
コード例 #7
0
ファイル: execute.py プロジェクト: jagunnels/qiskit-sdk-py
def execute(circuits,
            backend,
            qobj_header=None,
            config=None,
            basis_gates=None,
            coupling_map=None,
            initial_layout=None,
            shots=1024,
            max_credits=10,
            seed=None,
            qobj_id=None,
            seed_mapper=None,
            pass_manager=None,
            memory=False,
            **kwargs):
    """Executes a set of circuits.

    Args:
        circuits (QuantumCircuit or list[QuantumCircuit]): circuits to execute
        backend (BaseBackend): a backend to execute the circuits on
        qobj_header (QobjHeader): user input to go into the header
        config (dict): dictionary of parameters (e.g. noise) used by runner
        basis_gates (list[str]): list of basis gate names supported by the
            target. Default: ['u1','u2','u3','cx','id']
        coupling_map (list): coupling map (perhaps custom) to target in mapping
        initial_layout (list): initial layout of qubits in mapping
        shots (int): number of repetitions of each circuit, for sampling
        max_credits (int): maximum credits to use
        seed (int): random seed for simulators
        seed_mapper (int): random seed for swapper mapper
        qobj_id (int): identifier for the generated qobj
        pass_manager (PassManager): a pass manger for the transpiler pipeline
        memory (bool): if True, per-shot measurement bitstrings are returned as well.
        kwargs: extra arguments used by AER for running configurable backends.
                Refer to the backend documentation for details on these arguments

    Returns:
        BaseJob: returns job instance derived from BaseJob
    """

    transpile_config = TranspileConfig()
    run_config = RunConfig()

    if config:
        warnings.warn('config is deprecated in terra 0.8', DeprecationWarning)
    if qobj_id:
        warnings.warn('qobj_id is deprecated in terra 0.8', DeprecationWarning)
    if basis_gates:
        transpile_config.basis_gate = basis_gates
    if coupling_map:
        transpile_config.coupling_map = coupling_map
    if initial_layout:
        transpile_config.initial_layout = initial_layout
    if seed_mapper:
        transpile_config.seed_mapper = seed_mapper
    if shots:
        run_config.shots = shots
    if max_credits:
        run_config.max_credits = max_credits
    if seed:
        run_config.seed = seed
    if memory:
        run_config.memory = memory
    if pass_manager:
        warnings.warn(
            'pass_manager in the execute function is deprecated in terra 0.8.',
            DeprecationWarning)

    job = execute_circuits(circuits,
                           backend,
                           qobj_header=qobj_header,
                           run_config=run_config,
                           transpile_config=transpile_config,
                           **kwargs)

    return job