示例#1
0
 def _define(self):
     """
     gate ch a,b {
     h b;
     sdg b;
     cx a,b;
     h b;
     t b;
     cx a,b;
     t b;
     h b;
     s b;
     x b;
     s a;}
     """
     definition = []
     q = QuantumRegister(2, "q")
     rule = [(HGate(), [q[1]], []), (SdgGate(), [q[1]], []),
             (CnotGate(), [q[0], q[1]], []), (HGate(), [q[1]], []),
             (TGate(), [q[1]], []), (CnotGate(), [q[0], q[1]], []),
             (TGate(), [q[1]], []), (HGate(), [q[1]], []),
             (SGate(), [q[1]], []), (XGate(), [q[1]], []),
             (SGate(), [q[0]], [])]
     for inst in rule:
         definition.append(inst)
     self.definition = definition
示例#2
0
 def _define_decompositions(self):
     """
     gate ch a,b {
     h b;
     sdg b;
     cx a,b;
     h b;
     t b;
     cx a,b;
     t b;
     h b;
     s b;
     x b;
     s a;}
     """
     decomposition = DAGCircuit()
     q = QuantumRegister(2, "q")
     decomposition.add_qreg(q)
     rule = [
         HGate(q[1]),
         SdgGate(q[1]),
         CnotGate(q[0], q[1]),
         HGate(q[1]),
         TGate(q[1]),
         CnotGate(q[0], q[1]),
         TGate(q[1]),
         HGate(q[1]),
         SGate(q[1]),
         XGate(q[1]),
         SGate(q[0])
     ]
     for inst in rule:
         decomposition.apply_operation_back(inst)
     self._decompositions = [decomposition]
示例#3
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
示例#4
0
文件: cy.py 项目: CQCL/qiskit-terra
 def _define_decompositions(self):
     """
     gate cy a,b { sdg b; cx a,b; s b; }
     """
     decomposition = DAGCircuit()
     q = QuantumRegister(2, "q")
     decomposition.add_qreg(q)
     decomposition.add_basis_element("s", 1, 0, 0)
     decomposition.add_basis_element("sdg", 1, 0, 0)
     decomposition.add_basis_element("cx", 2, 0, 0)
     rule = [SdgGate(q[1]), CnotGate(q[0], q[1]), SGate(q[1])]
     for inst in rule:
         decomposition.apply_operation_back(inst)
     self._decompositions = [decomposition]
示例#5
0
 def _define(self):
     """
     gate cy a,b { sdg b; cx a,b; s b; }
     """
     from qiskit.extensions.standard.s import SGate
     from qiskit.extensions.standard.s import SdgGate
     from qiskit.extensions.standard.x import CXGate
     definition = []
     q = QuantumRegister(2, 'q')
     rule = [(SdgGate(), [q[1]], []), (CXGate(), [q[0], q[1]], []),
             (SGate(), [q[1]], [])]
     for inst in rule:
         definition.append(inst)
     self.definition = definition
示例#6
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)