def assemble_circuits(circuits, qobj_id=None, qobj_header=None, run_config=None):
qobj_config = QasmQobjConfig()<EOL>if run_config:<EOL><INDENT>qobj_config = QasmQobjConfig(**run_config.to_dict())<EOL><DEDENT>experiments = []<EOL>max_n_qubits = <NUM_LIT:0><EOL>max_memory_slots = <NUM_LIT:0><EOL>for circuit in circuits:<EOL><INDENT>n_qubits = <NUM_LIT:0><EOL>memory_slots = <NUM_LIT:0><EOL>qubit_labels = []<EOL>clbit_labels = []<EOL>qreg_sizes = []<EOL>creg_sizes = []<EOL>for qreg in circuit.qregs:<EOL><INDENT>qreg_sizes.append([qreg.name, qreg.size])<EOL>for j in range(qreg.size):<EOL><INDENT>qubit_labels.append([qreg.name, j])<EOL><DEDENT>n_qubits += qreg.size<EOL><DEDENT>for creg in circuit.cregs:<EOL><INDENT>creg_sizes.append([creg.name, creg.size])<EOL>for j in range(creg.size):<EOL><INDENT>clbit_labels.append([creg.name, j])<EOL><DEDENT>memory_slots += creg.size<EOL><DEDENT>experimentheader = QobjExperimentHeader(qubit_labels=qubit_labels,<EOL>n_qubits=n_qubits,<EOL>qreg_sizes=qreg_sizes,<EOL>clbit_labels=clbit_labels,<EOL>memory_slots=memory_slots,<EOL>creg_sizes=creg_sizes,<EOL>name=circuit.name)<EOL>experimentconfig = QasmQobjExperimentConfig(n_qubits=n_qubits, memory_slots=memory_slots)<EOL>is_conditional_experiment = any(op.control for (op, qargs, cargs) in circuit.data)<EOL>max_conditional_idx = <NUM_LIT:0><EOL>instructions = []<EOL>for op_context in circuit.data:<EOL><INDENT>instruction = op_context[<NUM_LIT:0>].assemble()<EOL>qargs = op_context[<NUM_LIT:1>]<EOL>cargs = op_context[<NUM_LIT:2>]<EOL>if qargs:<EOL><INDENT>qubit_indices = [qubit_labels.index([qubit[<NUM_LIT:0>].name, qubit[<NUM_LIT:1>]])<EOL>for qubit in qargs]<EOL>instruction.qubits = qubit_indices<EOL><DEDENT>if cargs:<EOL><INDENT>clbit_indices = [clbit_labels.index([clbit[<NUM_LIT:0>].name, clbit[<NUM_LIT:1>]])<EOL>for clbit in cargs]<EOL>instruction.memory = clbit_indices<EOL>if instruction.name == "<STR_LIT>" and is_conditional_experiment:<EOL><INDENT>instruction.register = clbit_indices<EOL><DEDENT><DEDENT>if hasattr(instruction, '<STR_LIT>'):<EOL><INDENT>ctrl_reg, ctrl_val = instruction._control<EOL>mask = <NUM_LIT:0><EOL>val = <NUM_LIT:0><EOL>for clbit in clbit_labels:<EOL><INDENT>if clbit[<NUM_LIT:0>] == ctrl_reg.name:<EOL><INDENT>mask |= (<NUM_LIT:1> << clbit_labels.index(clbit))<EOL>val |= (((ctrl_val >> clbit[<NUM_LIT:1>]) & <NUM_LIT:1>) << clbit_labels.index(clbit))<EOL><DEDENT><DEDENT>conditional_reg_idx = memory_slots + max_conditional_idx<EOL>conversion_bfunc = QasmQobjInstruction(name='<STR_LIT>',<EOL>mask="<STR_LIT>" % mask,<EOL>relation='<STR_LIT>',<EOL>val="<STR_LIT>" % val,<EOL>register=conditional_reg_idx)<EOL>instructions.append(conversion_bfunc)<EOL>instruction.conditional = conditional_reg_idx<EOL>max_conditional_idx += <NUM_LIT:1><EOL>del instruction._control<EOL><DEDENT>instructions.append(instruction)<EOL><DEDENT>experiments.append(QasmQobjExperiment(instructions=instructions, header=experimentheader,<EOL>config=experimentconfig))<EOL>if n_qubits > max_n_qubits:<EOL><INDENT>max_n_qubits = n_qubits<EOL><DEDENT>if memory_slots > max_memory_slots:<EOL><INDENT>max_memory_slots = memory_slots<EOL><DEDENT><DEDENT>qobj_config.memory_slots = max_memory_slots<EOL>qobj_config.n_qubits = max_n_qubits<EOL>return QasmQobj(qobj_id=qobj_id,<EOL>config=qobj_config,<EOL>experiments=experiments,<EOL>header=qobj_header)<EOL>
Assembles a list of circuits into a qobj which can be run on the backend.

    Args:
        circuits (list[QuantumCircuits]): circuit(s) to assemble
        qobj_id (int): identifier for the generated qobj
        qobj_header (QobjHeader): header to pass to the results
        run_config (RunConfig): configuration of the runtime environment

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