def _compile_wrapper(circuits, backend, backend_config, compile_config, run_config): transpiled_circuits = compiler.transpile(circuits, backend, **backend_config, **compile_config) if not isinstance(transpiled_circuits, list): transpiled_circuits = [transpiled_circuits] qobj = assemble_circuits(transpiled_circuits, qobj_id=str(uuid.uuid4()), qobj_header=QobjHeader(), run_config=run_config) return qobj, transpiled_circuits
def assemble(experiments, backend=None, qobj_id=None, qobj_header=None, shots=1024, memory=False, max_credits=None, seed_simulator=None, qubit_lo_freq=None, meas_lo_freq=None, qubit_lo_range=None, meas_lo_range=None, schedule_los=None, meas_level=2, meas_return='avg', meas_map=None, memory_slot_size=100, rep_time=None, parameter_binds=None, **run_config): """Assemble a list of circuits or pulse schedules into a Qobj. This function serializes the payloads, which could be either circuits or schedules, to create Qobj "experiments". It further annotates the experiment payload with header and configurations. Args: experiments (QuantumCircuit or list[QuantumCircuit] or Schedule or list[Schedule]): Circuit(s) or pulse schedule(s) to execute backend (BaseBackend): If set, some runtime options are automatically grabbed from backend.configuration() and backend.defaults(). If any other option is explicitly set (e.g. rep_rate), it will override the backend's. If any other options is set in the run_config, it will also override the backend's. qobj_id (str): String identifier to annotate the Qobj qobj_header (QobjHeader or dict): User input that will be inserted in Qobj header, and will also be copied to the corresponding Result header. Headers do not affect the run. shots (int): Number of repetitions of each circuit, for sampling. Default: 1024 memory (bool): If True, per-shot measurement bitstrings are returned as well (provided the backend supports it). For OpenPulse jobs, only measurement level 2 supports this option. Default: False max_credits (int): Maximum credits to spend on job. Default: 10 seed_simulator (int): Random seed to control sampling, for when backend is a simulator qubit_lo_freq (list): List of default qubit lo frequencies. Will be overridden by `schedule_los` if set. meas_lo_freq (list): List of default meas lo frequencies. Will be overridden by `schedule_los` if set. qubit_lo_range (list): List of drive lo ranges used to validate that the supplied qubit los are valid. meas_lo_range (list): List of meas lo ranges used to validate that the supplied measurement los are valid. schedule_los (None or list[Union[Dict[PulseChannel, float], LoConfig]] or \ Union[Dict[PulseChannel, float], LoConfig]): Experiment LO configurations meas_level (int): Set the appropriate level of the measurement output for pulse experiments. meas_return (str): Level of measurement data for the backend to return For `meas_level` 0 and 1: * "single" returns information from every shot. * "avg" returns average measurement output (averaged over number of shots). meas_map (list): List of lists, containing qubits that must be measured together. memory_slot_size (int): Size of each memory slot if the output is Level 0. rep_time (int): repetition time of the experiment in μs. The delay between experiments will be rep_time. Must be from the list provided by the device. parameter_binds (list[dict{Parameter: Value}]): List of Parameter bindings over which the set of experiments will be executed. Each list element (bind) should be of the form {Parameter1: value1, Parameter2: value2, ...}. All binds will be executed across all experiments, e.g. if parameter_binds is a length-n list, and there are m experiments, a total of m x n experiments will be run (one for each experiment/bind pair). **run_config (dict): extra arguments used to configure the run (e.g. for Aer configurable backends). Refer to the backend documentation for details on these arguments. Returns: Qobj: a qobj which can be run on a backend. Depending on the type of input, this will be either a QasmQobj or a PulseQobj. Raises: QiskitError: if the input cannot be interpreted as either circuits or schedules """ experiments = experiments if isinstance(experiments, list) else [experiments] qobj_id, qobj_header, run_config_common_dict = _parse_common_args( backend, qobj_id, qobj_header, shots, memory, max_credits, seed_simulator, **run_config) # assemble either circuits or schedules if all(isinstance(exp, QuantumCircuit) for exp in experiments): run_config = _parse_circuit_args(parameter_binds, **run_config_common_dict) # If circuits are parameterized, bind parameters and remove from run_config bound_experiments, run_config = _expand_parameters( circuits=experiments, run_config=run_config) return assemble_circuits(circuits=bound_experiments, qobj_id=qobj_id, qobj_header=qobj_header, run_config=run_config) elif all(isinstance(exp, ScheduleComponent) for exp in experiments): run_config = _parse_pulse_args(backend, qubit_lo_freq, meas_lo_freq, qubit_lo_range, meas_lo_range, schedule_los, meas_level, meas_return, meas_map, memory_slot_size, rep_time, **run_config_common_dict) return assemble_schedules(schedules=experiments, qobj_id=qobj_id, qobj_header=qobj_header, run_config=run_config) else: raise QiskitError("bad input to assemble() function; " "must be either circuits or schedules")
def assemble(experiments: Union[QuantumCircuit, List[QuantumCircuit], Schedule, List[Schedule]], backend: Optional[BaseBackend] = None, qobj_id: Optional[str] = None, qobj_header: Optional[Union[QobjHeader, Dict]] = None, shots: Optional[int] = None, memory: Optional[bool] = False, max_credits: Optional[int] = None, seed_simulator: Optional[int] = None, qubit_lo_freq: Optional[List[int]] = None, meas_lo_freq: Optional[List[int]] = None, qubit_lo_range: Optional[List[int]] = None, meas_lo_range: Optional[List[int]] = None, schedule_los: Optional[Union[List[Union[Dict[PulseChannel, float], LoConfig]], Union[Dict[PulseChannel, float], LoConfig]]] = None, meas_level: Union[int, MeasLevel] = MeasLevel.CLASSIFIED, meas_return: Union[str, MeasReturnType] = MeasReturnType.AVERAGE, meas_map: Optional[List[List[Qubit]]] = None, memory_slot_size: int = 100, rep_time: Optional[int] = None, rep_delay: Optional[float] = None, parameter_binds: Optional[List[Dict[Parameter, float]]] = None, parametric_pulses: Optional[List[str]] = None, init_qubits: bool = True, **run_config: Dict) -> Qobj: """Assemble a list of circuits or pulse schedules into a ``Qobj``. This function serializes the payloads, which could be either circuits or schedules, to create ``Qobj`` "experiments". It further annotates the experiment payload with header and configurations. Args: experiments: Circuit(s) or pulse schedule(s) to execute backend: If set, some runtime options are automatically grabbed from ``backend.configuration()`` and ``backend.defaults()``. If any other option is explicitly set (e.g., ``rep_time``), it will override the backend's. If any other options is set in the run_config, it will also override the backend's. qobj_id: String identifier to annotate the ``Qobj`` qobj_header: User input that will be inserted in ``Qobj`` header, and will also be copied to the corresponding Result header. Headers do not affect the run. shots: Number of repetitions of each circuit, for sampling. Default: 1024 or ``max_shots`` from the backend configuration, whichever is smaller memory: If ``True``, per-shot measurement bitstrings are returned as well (provided the backend supports it). For OpenPulse jobs, only measurement level 2 supports this option. max_credits: Maximum credits to spend on job. Default: 10 seed_simulator: Random seed to control sampling, for when backend is a simulator qubit_lo_freq: List of default qubit LO frequencies in Hz. Will be overridden by ``schedule_los`` if set. meas_lo_freq: List of default measurement LO frequencies in Hz. Will be overridden by ``schedule_los`` if set. qubit_lo_range: List of drive LO ranges each of form ``[range_min, range_max]`` in Hz. Used to validate the supplied qubit frequencies. meas_lo_range: List of measurement LO ranges each of form ``[range_min, range_max]`` in Hz. Used to validate the supplied qubit frequencies. schedule_los: Experiment LO configurations, frequencies are given in Hz. meas_level: Set the appropriate level of the measurement output for pulse experiments. meas_return: Level of measurement data for the backend to return. For ``meas_level`` 0 and 1: * ``single`` returns information from every shot. * ``avg`` returns average measurement output (averaged over number of shots). meas_map: List of lists, containing qubits that must be measured together. memory_slot_size: Size of each memory slot if the output is Level 0. rep_time (int): Time per program execution in seconds. Must be from the list provided by the backend (``backend.configuration().rep_times``). Defaults to the first entry. rep_delay (float): Delay between programs in seconds. Only supported on certain backends (if ``backend.configuration().dynamic_reprate_enabled=True``). If supported, ``rep_delay`` will be used instead of ``rep_time`` and must be from the range supplied by the backend (``backend.configuration().rep_delay_range``). Default is given by ``backend.configuration().default_rep_delay``. parameter_binds: List of Parameter bindings over which the set of experiments will be executed. Each list element (bind) should be of the form {Parameter1: value1, Parameter2: value2, ...}. All binds will be executed across all experiments; e.g., if parameter_binds is a length-n list, and there are m experiments, a total of m x n experiments will be run (one for each experiment/bind pair). parametric_pulses: A list of pulse shapes which are supported internally on the backend. Example:: ['gaussian', 'constant'] init_qubits: Whether to reset the qubits to the ground state for each shot. Default: ``True``. **run_config: Extra arguments used to configure the run (e.g., for Aer configurable backends). Refer to the backend documentation for details on these arguments. Returns: A ``Qobj`` that can be run on a backend. Depending on the type of input, this will be either a ``QasmQobj`` or a ``PulseQobj``. Raises: QiskitError: if the input cannot be interpreted as either circuits or schedules """ start_time = time() experiments = experiments if isinstance(experiments, list) else [experiments] qobj_id, qobj_header, run_config_common_dict = _parse_common_args( backend, qobj_id, qobj_header, shots, memory, max_credits, seed_simulator, init_qubits, rep_delay, **run_config) # assemble either circuits or schedules if all(isinstance(exp, QuantumCircuit) for exp in experiments): run_config = _parse_circuit_args(parameter_binds, backend, parametric_pulses, **run_config_common_dict) # If circuits are parameterized, bind parameters and remove from run_config bound_experiments, run_config = _expand_parameters( circuits=experiments, run_config=run_config) end_time = time() _log_assembly_time(start_time, end_time) return assemble_circuits(circuits=bound_experiments, qobj_id=qobj_id, qobj_header=qobj_header, run_config=run_config) elif all(isinstance(exp, ScheduleComponent) for exp in experiments): run_config = _parse_pulse_args(backend, qubit_lo_freq, meas_lo_freq, qubit_lo_range, meas_lo_range, schedule_los, meas_level, meas_return, meas_map, memory_slot_size, rep_time, parametric_pulses, **run_config_common_dict) end_time = time() _log_assembly_time(start_time, end_time) return assemble_schedules(schedules=experiments, qobj_id=qobj_id, qobj_header=qobj_header, run_config=run_config) else: raise QiskitError("bad input to assemble() function; " "must be either circuits or schedules")