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

    Args:
        circuit (QuantumCircuit): the input circuit.

    Return:
        DAGCircuit: the DAG representing the input circuit.
    """
    dagcircuit = DAGCircuit()
    dagcircuit.name = circuit.name
    for register in circuit.qregs:
        dagcircuit.add_qreg(register)
    for register in circuit.cregs:
        dagcircuit.add_creg(register)

    for instruction, qargs, cargs in circuit.data:
        # Get arguments for classical control (if any)
        if instruction.control is None:
            control = None
        else:
            control = (instruction.control[0], instruction.control[1])

        dagcircuit.apply_operation_back(instruction.copy(),
                                        qargs, cargs, control)

    return dagcircuit
def circuit_to_dag(circuit):
    """Build a ``DAGCircuit`` object from a ``QuantumCircuit``.

    Args:
        circuit (QuantumCircuit): the input circuit.

    Return:
        DAGCircuit: the DAG representing the input circuit.
    """
    dagcircuit = DAGCircuit()
    dagcircuit.name = circuit.name
    for register in circuit.qregs:
        dagcircuit.add_qreg(register)
    for register in circuit.cregs:
        dagcircuit.add_creg(register)

    for instruction, qargs, cargs in circuit.data:
        # Get arguments for classical control (if any)
        if instruction.control is None:
            control = None
        else:
            control = (instruction.control[0], instruction.control[1])

        dagcircuit.apply_operation_back(instruction.copy(),
                                        qargs, cargs, control)

    return dagcircuit
Build a ``DAGCircuit`` object from a ``QuantumCircuit``.

    Args:
        circuit (QuantumCircuit): the input circuit.

    Return:
        DAGCircuit: the DAG representing the input circuit.