def test_no_run_config(self):
     """Test circuits_to_qobj_without_run_config_set."""
     qr = QuantumRegister(2, 'q')
     cr = ClassicalRegister(2, 'c')
     qc = QuantumCircuit(qr, cr)
     qc.h(qr[0])
     qc.cx(qr[0], qr[1])
     qc.measure(qr[0], cr[0])
     qc.measure(qr[1], cr[1])
     qobj = circuits_to_qobj(qc)
     expected = [{
         'name': 'h',
         'qubits': [0]
     }, {
         'name': 'cx',
         'qubits': [0, 1]
     }, {
         'name': 'measure',
         'memory': [0],
         'qubits': [0]
     }, {
         'name': 'measure',
         'memory': [1],
         'qubits': [1]
     }]
     self.assertEqual(qobj.to_dict()['experiments'][0]['instructions'],
                      expected)
Esempio n. 2
0
def _compile_wrapper(circuits, backend, backend_config, compile_config,
                     run_config):
    transpiled_circuits = transpiler.transpile(circuits, backend,
                                               **backend_config,
                                               **compile_config)
    qobj = circuits_to_qobj(transpiled_circuits,
                            user_qobj_header=QobjHeader(),
                            run_config=run_config,
                            qobj_id=None)
    return qobj, transpiled_circuits
Esempio n. 3
0
def compile(circuits, backend,
            config=None, basis_gates=None, coupling_map=None, initial_layout=None,
            shots=1024, max_credits=10, seed=None, qobj_id=None,
            skip_transpiler=False, seed_mapper=None, pass_manager=None, memory=False):
    """Compile a list of circuits into a qobj.

    Args:
        circuits (QuantumCircuit or list[QuantumCircuit]): circuits to compile
        backend (BaseBackend): a backend to compile for
        config (dict): dictionary of parameters (e.g. noise) used by runner
        basis_gates (str): comma-separated basis gate set to compile to
        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
        skip_transpiler (bool): DEPRECATED skip transpiler and create qobj directly

    Returns:
        Qobj: the qobj to be run on the backends

    Raises:
        QiskitError: if the desired options are not supported by backend
    """
    if skip_transpiler:  # empty pass manager which does nothing
        pass_manager = PassManager()
        warnings.warn('The skip_transpiler option has been deprecated. '
                      'Please pass an empty PassManager() instance instead',
                      DeprecationWarning)

    backend_memory = getattr(backend.configuration(), 'memory', False)
    if memory and not backend_memory:
        raise QiskitError("Backend %s only returns total counts, not single-shot memory." %
                          backend.name())

    circuits = transpiler.transpile(circuits, backend, basis_gates, coupling_map, initial_layout,
                                    seed_mapper, pass_manager)

    # step 4: Making a qobj
    qobj = circuits_to_qobj(circuits, backend_name=backend.name(),
                            config=config, shots=shots, max_credits=max_credits,
                            qobj_id=qobj_id, basis_gates=basis_gates,
                            coupling_map=coupling_map, seed=seed, memory=memory)

    return qobj
 def test_qobj_with_unitary_matrix(self):
     """test qobj output with unitary matrix"""
     qr = QuantumRegister(4)
     qc = QuantumCircuit(qr)
     sigmax = numpy.array([[0, 1], [1, 0]])
     sigmay = numpy.array([[0, -1j], [1j, 0]])
     matrix = numpy.kron(sigmay, numpy.kron(sigmax, sigmay))
     qc.x(qr[0])
     qc.unitary(matrix, qr[0], qr[1], qr[3])
     qc.cx(qr[3], qr[2])
     qobj = circuits_to_qobj(qc)
     instr = qobj.experiments[0].instructions[1]
     self.assertEqual(instr.name, 'unitary')
     self.assertTrue(
         numpy.allclose(
             numpy.array(instr.params).astype(numpy.complex64), matrix))
Esempio n. 5
0
def compile(circuits,
            backend,
            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):
    """Compile a list of circuits into a qobj.

    Args:
        circuits (QuantumCircuit or list[QuantumCircuit]): circuits to compile
        backend (BaseBackend): a backend to compile for
        config (dict): dictionary of parameters (e.g. noise) used by runner
        basis_gates (str): comma-separated basis gate set to compile to
        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

    Returns:
        Qobj: the qobj to be run on the backends

    Raises:
        QiskitError: if the desired options are not supported by backend
    """
    if config:
        warnings.warn(
            'The `config` argument is deprecated and '
            'does not do anything', DeprecationWarning)

    circuits = transpiler.transpile(circuits, backend, basis_gates,
                                    coupling_map, initial_layout, seed_mapper,
                                    pass_manager)

    # step 4: Making a qobj
    run_config = RunConfig()

    if seed:
        run_config.seed = seed
    if shots:
        run_config.shots = shots
    if max_credits:
        run_config.max_credits = max_credits
    if memory:
        run_config.memory = memory
    qobj = circuits_to_qobj(circuits,
                            user_qobj_header=QobjHeader(),
                            run_config=run_config,
                            qobj_id=qobj_id)

    return qobj