예제 #1
0
파일: x.py 프로젝트: nelix1000/qiskit-terra
 def _define(self):
     """
     gate ccx a,b,c
     {
     h c; cx b,c; tdg c; cx a,c;
     t c; cx b,c; tdg c; cx a,c;
     t b; t c; h c; cx a,b;
     t a; tdg b; cx a,b;}
     """
     from qiskit.extensions.standard.h import HGate
     from qiskit.extensions.standard.t import TGate
     from qiskit.extensions.standard.t import TdgGate
     definition = []
     q = QuantumRegister(3, "q")
     rule = [
         (HGate(), [q[2]], []),
         (CnotGate(), [q[1], q[2]], []),
         (TdgGate(), [q[2]], []),
         (CnotGate(), [q[0], q[2]], []),
         (TGate(), [q[2]], []),
         (CnotGate(), [q[1], q[2]], []),
         (TdgGate(), [q[2]], []),
         (CnotGate(), [q[0], q[2]], []),
         (TGate(), [q[1]], []),
         (TGate(), [q[2]], []),
         (HGate(), [q[2]], []),
         (CnotGate(), [q[0], q[1]], []),
         (TGate(), [q[0]], []),
         (TdgGate(), [q[1]], []),
         (CnotGate(), [q[0], q[1]], [])
     ]
     for inst in rule:
         definition.append(inst)
     self.definition = definition
예제 #2
0
파일: x.py 프로젝트: ismetshn/qiskit-terra
 def _define(self):
     """
     gate ccx a,b,c
     {
     h c; cx b,c; tdg c; cx a,c;
     t c; cx b,c; tdg c; cx a,c;
     t b; t c; h c; cx a,b;
     t a; tdg b; cx a,b;}
     """
     definition = []
     q = QuantumRegister(3, 'q')
     rule = [
         (HGate(), [q[2]], []),
         (CXGate(), [q[1], q[2]], []),
         (TdgGate(), [q[2]], []),
         (CXGate(), [q[0], q[2]], []),
         (TGate(), [q[2]], []),
         (CXGate(), [q[1], q[2]], []),
         (TdgGate(), [q[2]], []),
         (CXGate(), [q[0], q[2]], []),
         (TGate(), [q[1]], []),
         (TGate(), [q[2]], []),
         (HGate(), [q[2]], []),
         (CXGate(), [q[0], q[1]], []),
         (TGate(), [q[0]], []),
         (TdgGate(), [q[1]], []),
         (CXGate(), [q[0], q[1]], [])
     ]
     for inst in rule:
         definition.append(inst)
     self.definition = definition
예제 #3
0
 def _define_decompositions(self):
     """
     gate ccx a,b,c
     {
     h c; cx b,c; tdg c; cx a,c;
     t c; cx b,c; tdg c; cx a,c;
     t b; t c; h c; cx a,b;
     t a; tdg b; cx a,b;}
     """
     decomposition = DAGCircuit()
     q = QuantumRegister(3, "q")
     decomposition.add_qreg(q)
     rule = [
         HGate(q[2]),
         CnotGate(q[1], q[2]),
         TdgGate(q[2]),
         CnotGate(q[0], q[2]),
         TGate(q[2]),
         CnotGate(q[1], q[2]),
         TdgGate(q[2]),
         CnotGate(q[0], q[2]),
         TGate(q[1]),
         TGate(q[2]),
         HGate(q[2]),
         CnotGate(q[0], q[1]),
         TGate(q[0]),
         TdgGate(q[1]),
         CnotGate(q[0], q[1])
     ]
     for inst in rule:
         decomposition.apply_operation_back(inst)
     self._decompositions = [decomposition]
예제 #4
0
 def _define(self):
     """
     gate ch a,b {
         s b;
         h b;
         t b;
         cx a, b;
         tdg b;
         h b;
         sdg b;
     }
     """
     definition = []
     q = QuantumRegister(2, "q")
     rule = [
         (SGate(), [q[1]], []),
         (HGate(), [q[1]], []),
         (TGate(), [q[1]], []),
         (CnotGate(), [q[0], q[1]], []),
         (TdgGate(), [q[1]], []),
         (HGate(), [q[1]], []),
         (SdgGate(), [q[1]], [])
     ]
     for inst in rule:
         definition.append(inst)
     self.definition = definition
예제 #5
0
 def _define(self):
     """
     gate ch a,b {
         s b;
         h b;
         t b;
         cx a, b;
         tdg b;
         h b;
         sdg b;
     }
     """
     from qiskit.extensions.standard.s import SGate, SdgGate
     from qiskit.extensions.standard.t import TGate, TdgGate
     from qiskit.extensions.standard.x import CnotGate
     definition = []
     q = QuantumRegister(2, "q")
     rule = [
         (SGate(), [q[1]], []),
         (HGate(), [q[1]], []),
         (TGate(), [q[1]], []),
         (CnotGate(), [q[0], q[1]], []),
         (TdgGate(), [q[1]], []),
         (HGate(), [q[1]], []),
         (SdgGate(), [q[1]], [])
     ]
     for inst in rule:
         definition.append(inst)
     self.definition = definition
예제 #6
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]
예제 #7
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)