コード例 #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
ファイル: h.py プロジェクト: wguanicedew/qiskit-terra
 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
 def __init__(self,
              λ: float,
              target: Tuple[QuantumRegister, int],
              control: Tuple[QuantumRegister, int],
              circ,
              cnot_back: bool = False):
     super().__init__("cPhase", [λ], [target, control], circ)
     if math.fabs(λ - math.pi / 2) < 1e-3:
         self.t(target)
         self._cx(control, target, cnot_back)
         super()._attach(TGate(target, circ).inverse())
         self.t(control)
         self._cx(control, target, cnot_back)
     elif math.fabs(λ - math.pi) < 1e-3:
         self.s(target)
         self._cx(control, target, cnot_back)
         super()._attach(SGate(target, circ).inverse())
         self.s(control)
         self._cx(control, target, cnot_back)
     else:
         super()._attach(RZGate_ibm(λ, target))
         self._cx(control, target, cnot_back)
         super()._attach(RZGate_ibm(-λ, target))
         super()._attach(RZGate_ibm(λ, control))
         self._cx(control, target, cnot_back)
コード例 #5
0
ファイル: iswap.py プロジェクト: yehuda-naveh/qiskit-terra
 def _define(self):
     """
     gate iswap a,b {
         s q[0];
         s q[1];
         h q[0];
         cx q[0],q[1];
         cx q[1],q[0];
         h q[1];
     }
     """
     from qiskit.extensions.standard.h import HGate
     from qiskit.extensions.standard.s import SGate
     from qiskit.extensions.standard.x import CXGate
     q = QuantumRegister(2, 'q')
     self.definition = [(SGate(), [q[0]], []), (SGate(), [q[1]], []),
                        (HGate(), [q[0]], []), (CXGate(), [q[0], q[1]], []),
                        (CXGate(), [q[1], q[0]], []), (HGate(), [q[1]], [])]
コード例 #6
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]
コード例 #7
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
コード例 #8
0
 def test_inverse_and_append(self):
     """test appending inverted gates to circuits"""
     q = QuantumRegister(1)
     circ = QuantumCircuit(q, name='circ')
     circ.s(q)
     circ.append(SGate().inverse(), q[:])
     circ.append(TGate().inverse(), q[:])
     circ.t(q)
     gate = circ.to_instruction()
     circ = QuantumCircuit(q, name='circ')
     circ.inverse()
     circ.tdg(q)
     circ.t(q)
     circ.s(q)
     circ.sdg(q)
     gate_inverse = circ.to_instruction()
     self.assertEqual(gate.inverse().definition, gate_inverse.definition)
コード例 #9
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)