コード例 #1
0
class TestParameterCtrlState(QiskitTestCase):
    """Test gate equality with ctrl_state parameter."""
    @data((RXGate(0.5), CRXGate(0.5)), (RYGate(0.5), CRYGate(0.5)),
          (RZGate(0.5), CRZGate(0.5)), (XGate(), CXGate()),
          (YGate(), CYGate()), (ZGate(), CZGate()),
          (U1Gate(0.5), CU1Gate(0.5)), (SwapGate(), CSwapGate()),
          (HGate(), CHGate()), (U3Gate(0.1, 0.2, 0.3), CU3Gate(0.1, 0.2, 0.3)))
    @unpack
    def test_ctrl_state_one(self, gate, controlled_gate):
        """Test controlled gates with ctrl_state
        See https://github.com/Qiskit/qiskit-terra/pull/4025
        """
        self.assertEqual(gate.control(1, ctrl_state='1'), controlled_gate)
コード例 #2
0
    def test_is_identity(self):
        """ The is_identity function determines whether a pair of gates
            forms the identity, when ignoring control qubits.
        """
        seq = [DAGNode({'type': 'op', 'op': XGate().control()}),
               DAGNode({'type': 'op', 'op': XGate().control(2)})]
        self.assertTrue(HoareOptimizer()._is_identity(seq))

        seq = [DAGNode({'type': 'op', 'op': RZGate(-pi/2).control()}),
               DAGNode({'type': 'op', 'op': RZGate(pi/2).control(2)})]
        self.assertTrue(HoareOptimizer()._is_identity(seq))

        seq = [DAGNode({'type': 'op', 'op': CSwapGate()}),
               DAGNode({'type': 'op', 'op': SwapGate()})]
        self.assertTrue(HoareOptimizer()._is_identity(seq))
コード例 #3
0
    def test_is_identity(self):
        """The is_identity function determines whether a pair of gates
        forms the identity, when ignoring control qubits.
        """
        seq = [DAGOpNode(op=XGate().control()), DAGOpNode(op=XGate().control(2))]
        self.assertTrue(HoareOptimizer()._is_identity(seq))

        seq = [
            DAGOpNode(op=RZGate(-pi / 2).control()),
            DAGOpNode(op=RZGate(pi / 2).control(2)),
        ]
        self.assertTrue(HoareOptimizer()._is_identity(seq))

        seq = [DAGOpNode(op=CSwapGate()), DAGOpNode(op=SwapGate())]
        self.assertTrue(HoareOptimizer()._is_identity(seq))
コード例 #4
0
 def test_controlled_swap(self):
     """Test creation of controlled swap gate"""
     self.assertEqual(SwapGate().control(), CSwapGate())