Ejemplo n.º 1
0
 def add_creg(self, creg):
     """Add all wires in a classical register."""
     if not isinstance(creg, ClassicalRegister):
         raise DAGDependencyError("not a ClassicalRegister instance.")
     if creg.name in self.cregs:
         raise DAGDependencyError("duplicate register %s" % creg.name)
     self.cregs[creg.name] = creg
Ejemplo n.º 2
0
 def add_qreg(self, qreg):
     """Add qubits in a quantum register."""
     if not isinstance(qreg, QuantumRegister):
         raise DAGDependencyError("not a QuantumRegister instance.")
     if qreg.name in self.qregs:
         raise DAGDependencyError("duplicate register %s" % qreg.name)
     self.qregs[qreg.name] = qreg
Ejemplo n.º 3
0
 def add_creg(self, creg):
     """Add clbits in a classical register."""
     if not isinstance(creg, ClassicalRegister):
         raise DAGDependencyError("not a ClassicalRegister instance.")
     if creg.name in self.cregs:
         raise DAGDependencyError("duplicate register %s" % creg.name)
     self.cregs[creg.name] = creg
     for j in range(creg.size):
         self.clbits.append(creg[j])
Ejemplo n.º 4
0
    def add_clbits(self, clbits):
        """Add individual clbit wires."""
        if any(not isinstance(clbit, Clbit) for clbit in clbits):
            raise DAGDependencyError("not a Clbit instance.")

        duplicate_clbits = set(self.clbits).intersection(clbits)
        if duplicate_clbits:
            raise DAGDependencyError("duplicate clbits %s" % duplicate_clbits)

        self.clbits.extend(clbits)
Ejemplo n.º 5
0
    def add_qubits(self, qubits):
        """Add individual qubit wires."""
        if any(not isinstance(qubit, Qubit) for qubit in qubits):
            raise DAGDependencyError("not a Qubit instance.")

        duplicate_qubits = set(self.qubits).intersection(qubits)
        if duplicate_qubits:
            raise DAGDependencyError("duplicate qubits %s" % duplicate_qubits)

        self.qubits.extend(qubits)
Ejemplo n.º 6
0
 def add_qreg(self, qreg):
     """Add qubits in a quantum register."""
     if not isinstance(qreg, QuantumRegister):
         raise DAGDependencyError("not a QuantumRegister instance.")
     if qreg.name in self.qregs:
         raise DAGDependencyError("duplicate register %s" % qreg.name)
     self.qregs[qreg.name] = qreg
     existing_qubits = set(self.qubits)
     for j in range(qreg.size):
         if qreg[j] not in existing_qubits:
             self.qubits.append(qreg[j])
Ejemplo n.º 7
0
def raise_if_dagdependency_invalid(dag):
    """Validates the internal consistency of a DAGDependency._multi_graph.
    Intended for use in testing.

    Raises:
       DAGDependencyError: if DAGDependency._multi_graph is inconsistent.
    """

    multi_graph = dag._multi_graph

    if not rx.is_directed_acyclic_graph(multi_graph):
        raise DAGDependencyError("multi_graph is not a DAG.")

    # Every node should be of type op.
    for node in dag.get_nodes():
        if node.type != "op":
            raise DAGDependencyError("Found node of unexpected type: {}".format(node.type))