qiskit/converters/dag_to_circuit.py
def dag_to_circuit(dag):
    """Build a ``QuantumCircuit`` object from a ``DAGCircuit``.

    Args:
        dag (DAGCircuit): the input dag.

    Return:
        QuantumCircuit: the circuit representing the input dag.
    """
    qregs = collections.OrderedDict()
    for qreg in dag.qregs.values():
        qreg_tmp = QuantumRegister(qreg.size, name=qreg.name)
        qregs[qreg.name] = qreg_tmp
    cregs = collections.OrderedDict()
    for creg in dag.cregs.values():
        creg_tmp = ClassicalRegister(creg.size, name=creg.name)
        cregs[creg.name] = creg_tmp

    name = dag.name or None
    circuit = QuantumCircuit(*qregs.values(), *cregs.values(), name=name)

    for node in dag.topological_op_nodes():
        qubits = []
        for qubit in node.qargs:
            qubits.append(qregs[qubit[0].name][qubit[1]])

        clbits = []
        for clbit in node.cargs:
            clbits.append(cregs[clbit[0].name][clbit[1]])

        # Get arguments for classical control (if any)
        if node.condition is None:
            control = None
        else:
            control = (node.condition[0], node.condition[1])

        inst = node.op.copy()
        inst.control = control
        circuit.append(inst, qubits, clbits)
    return circuit
def dag_to_circuit(dag):
    qregs = collections.OrderedDict()
    for qreg in dag.qregs.values():
        qreg_tmp = QuantumRegister(qreg.size, name=qreg.name)
        qregs[qreg.name] = qreg_tmp
    cregs = collections.OrderedDict()
    for creg in dag.cregs.values():
        creg_tmp = ClassicalRegister(creg.size, name=creg.name)
        cregs[creg.name] = creg_tmp

    name = dag.name or None
    circuit = QuantumCircuit(*qregs.values(), *cregs.values(), name=name)

    for node in dag.topological_op_nodes():
        qubits = []
        for qubit in node.qargs:
            qubits.append(qregs[qubit[0].name][qubit[1]])

        clbits = []
        for clbit in node.cargs:
            clbits.append(cregs[clbit[0].name][clbit[1]])

        # Get arguments for classical control (if any)
        if node.condition is None:
            control = None
        else:
            control = (node.condition[0], node.condition[1])

        inst = node.op.copy()
        inst.control = control
        circuit.append(inst, qubits, clbits)
    return circuit
def dag_to_circuit ( dag ) : qregs = collections . OrderedDict ( ) for qreg in dag . qregs . values ( ) : qreg_tmp = QuantumRegister ( qreg . size , name = qreg . name ) qregs [ qreg . name ] = qreg_tmp cregs = collections . OrderedDict ( ) for creg in dag . cregs . values ( ) : creg_tmp = ClassicalRegister ( creg . size , name = creg . name ) cregs [ creg . name ] = creg_tmp name = dag . name or None circuit = QuantumCircuit ( * qregs . values ( ) , * cregs . values ( ) , name = name ) for node in dag . topological_op_nodes ( ) : qubits = [ ] for qubit in node . qargs : qubits . append ( qregs [ qubit [ 0 ] . name ] [ qubit [ 1 ] ] ) clbits = [ ] for clbit in node . cargs : clbits . append ( cregs [ clbit [ 0 ] . name ] [ clbit [ 1 ] ] ) # Get arguments for classical control (if any) if node . condition is None : control = None else : control = ( node . condition [ 0 ] , node . condition [ 1 ] ) inst = node . op . copy ( ) inst . control = control circuit . append ( inst , qubits , clbits ) return circuit
Build a ``QuantumCircuit`` object from a ``DAGCircuit``.

    Args:
        dag (DAGCircuit): the input dag.

    Return:
        QuantumCircuit: the circuit representing the input dag.
Build a QuantumCircuit object from a DAGCircuit .