Ejemplo n.º 1
0
Archivo: c4u1.py Proyecto: MSwenne/BEP
 def _define_decompositions(self):
     decomposition = DAGCircuit()
     q = QuantumRegister(5, "q")
     decomposition.add_qreg(q)
     decomposition.add_basis_element("u1", 1, 0, 1)
     decomposition.add_basis_element("cx", 2, 0, 0)
     decomposition.add_basis_element("ccx", 3, 0, 0)
     decomposition.add_basis_element("c3x", 4, 0, 0)
     decomposition.add_basis_element("c4x", 5, 0, 0)
     rule = [
         C4NotGate(q[0], q[1], q[2], q[3], q[4]),
         C3NotGate(q[0], q[1], q[2], q[3]),
         ToffoliGate(q[0], q[1], q[2]),
         CnotGate(q[0], q[1]),
         U1Gate(-self.param[0] / 16, q[1]),
         U1Gate(-self.param[0] / 8, q[2]),
         U1Gate(-self.param[0] / 4, q[3]),
         U1Gate(-self.param[0] / 2, q[4]),
         CnotGate(q[0], q[1]),
         ToffoliGate(q[0], q[1], q[2]),
         C3NotGate(q[0], q[1], q[2], q[3]),
         C4NotGate(q[0], q[1], q[2], q[3], q[4]),
         U1Gate(self.param[0] / 16, q[0]),
         U1Gate(self.param[0] / 16, q[1]),
         U1Gate(self.param[0] / 8, q[2]),
         U1Gate(self.param[0] / 4, q[3]),
         U1Gate(self.param[0] / 2, q[4])
     ]
     for inst in rule:
         decomposition.apply_operation_back(inst)
     self._decompositions = [decomposition]
Ejemplo n.º 2
0
 def _define_decompositions(self):
     decomposition = DAGCircuit()
     q = QuantumRegister(6, "q")
     decomposition.add_qreg(q)
     decomposition.add_basis_element("u1", 1, 0, 1)
     decomposition.add_basis_element("h", 1, 0, 0)
     decomposition.add_basis_element("x", 1, 0, 0)
     decomposition.add_basis_element("cx", 2, 0, 0)
     decomposition.add_basis_element("ccx", 3, 0, 0)
     decomposition.add_basis_element("c3x", 4, 0, 0)
     decomposition.add_basis_element("c4x", 5, 0, 0)
     decomposition.add_basis_element("t", 1, 0, 0)
     decomposition.add_basis_element("tdg", 1, 0, 0)
     rule = [
         HGate(q[5]),
         C4NotGate(q[0], q[1], q[2], q[3], q[5]),
         TdgGate(q[5]),
         CnotGate(q[4], q[5]),
         TGate(q[5]),
         C4NotGate(q[0], q[1], q[2], q[3], q[5]),
         TdgGate(q[5]),
         CnotGate(q[4], q[5]),
         TGate(q[5]),
         HGate(q[5]),
         C4NotGate(q[0], q[1], q[2], q[3], q[4]),
         C3NotGate(q[0], q[1], q[2], q[3]),
         ToffoliGate(q[0], q[1], q[2]),
         CnotGate(q[0], q[1]),
         XGate(q[0]),
         U1Gate(-math.pi / 32, q[1]),
         U1Gate(-math.pi / 16, q[2]),
         U1Gate(-math.pi / 8, q[3]),
         U1Gate(-math.pi / 4, q[4]),
         XGate(q[0]),
         CnotGate(q[0], q[1]),
         ToffoliGate(q[0], q[1], q[2]),
         C3NotGate(q[0], q[1], q[2], q[3]),
         C4NotGate(q[0], q[1], q[2], q[3], q[4]),
         U1Gate(math.pi / 32, q[0]),
         U1Gate(math.pi / 32, q[1]),
         U1Gate(math.pi / 16, q[2]),
         U1Gate(math.pi / 8, q[3]),
         U1Gate(math.pi / 4, q[4])
     ]
     for inst in rule:
         decomposition.apply_operation_back(inst)
     self._decompositions = [decomposition]
Ejemplo n.º 3
0
 def _define(self):
     """
     gate cswap a,b,c
     { cx c,b;
       ccx a,b,c;
       cx c,b;
     }
     """
     definition = []
     q = QuantumRegister(3, "q")
     rule = [(CnotGate(), [q[2], q[1]], []),
             (ToffoliGate(), [q[0], q[1], q[2]], []),
             (CnotGate(), [q[2], q[1]], [])]
     for inst in rule:
         definition.append(inst)
     self.definition = definition
Ejemplo n.º 4
0
 def _define_decompositions(self):
     """
     gate cswap a,b,c
     { cx c,b;
       ccx a,b,c;
       cx c,b;
     }
     """
     decomposition = DAGCircuit()
     q = QuantumRegister(3, "q")
     decomposition.add_qreg(q)
     rule = [
         CnotGate(q[2], q[1]),
         ToffoliGate(q[0], q[1], q[2]),
         CnotGate(q[2], q[1])
     ]
     for inst in rule:
         decomposition.apply_operation_back(inst)
     self._decompositions = [decomposition]
Ejemplo n.º 5
0
    def create_dag_op(self, name, args, qubits):
        """Create a DAG op node.
        """
        if name == "u0":
            op = U0Gate(args[0], qubits[0])
        elif name == "u1":
            op = U1Gate(args[0], qubits[0])
        elif name == "u2":
            op = U2Gate(args[0], args[1], qubits[0])
        elif name == "u3":
            op = U3Gate(args[0], args[1], args[2], qubits[0])
        elif name == "x":
            op = XGate(qubits[0])
        elif name == "y":
            op = YGate(qubits[0])
        elif name == "z":
            op = ZGate(qubits[0])
        elif name == "t":
            op = TGate(qubits[0])
        elif name == "tdg":
            op = TdgGate(qubits[0])
        elif name == "s":
            op = SGate(qubits[0])
        elif name == "sdg":
            op = SdgGate(qubits[0])
        elif name == "swap":
            op = SwapGate(qubits[0], qubits[1])
        elif name == "rx":
            op = RXGate(args[0], qubits[0])
        elif name == "ry":
            op = RYGate(args[0], qubits[0])
        elif name == "rz":
            op = RZGate(args[0], qubits[0])
        elif name == "rzz":
            op = RZZGate(args[0], qubits[0], qubits[1])
        elif name == "id":
            op = IdGate(qubits[0])
        elif name == "h":
            op = HGate(qubits[0])
        elif name == "cx":
            op = CnotGate(qubits[0], qubits[1])
        elif name == "cy":
            op = CyGate(qubits[0], qubits[1])
        elif name == "cz":
            op = CzGate(qubits[0], qubits[1])
        elif name == "ch":
            op = CHGate(qubits[0], qubits[1])
        elif name == "crz":
            op = CrzGate(args[0], qubits[0], qubits[1])
        elif name == "cu1":
            op = Cu1Gate(args[0], qubits[0], qubits[1])
        elif name == "cu3":
            op = Cu3Gate(args[0], args[1], args[2], qubits[0], qubits[1])
        elif name == "ccx":
            op = ToffoliGate(qubits[0], qubits[1], qubits[2])
        elif name == "cswap":
            op = FredkinGate(qubits[0], qubits[1], qubits[2])
        else:
            raise BackendError("unknown operation for name ast node name %s" %
                               name)

        self.circuit.add_basis_element(op.name, len(op.qargs), len(op.cargs),
                                       len(op.param))
        self.start_gate(op)
        self.end_gate(op)