def test_to_matrix(self):
        """to matrix text """
        np.testing.assert_array_equal(X.to_matrix(),
                                      Operator.from_label('X').data)
        np.testing.assert_array_equal(Y.to_matrix(),
                                      Operator.from_label('Y').data)
        np.testing.assert_array_equal(Z.to_matrix(),
                                      Operator.from_label('Z').data)

        op1 = Y + H
        np.testing.assert_array_almost_equal(op1.to_matrix(),
                                             Y.to_matrix() + H.to_matrix())

        op2 = op1 * .5
        np.testing.assert_array_almost_equal(op2.to_matrix(),
                                             op1.to_matrix() * .5)

        op3 = (4 - .6j) * op2
        np.testing.assert_array_almost_equal(op3.to_matrix(),
                                             op2.to_matrix() * (4 - .6j))

        op4 = op3.tensor(X)
        np.testing.assert_array_almost_equal(
            op4.to_matrix(), np.kron(op3.to_matrix(), X.to_matrix()))

        op5 = op4.compose(H ^ I)
        np.testing.assert_array_almost_equal(
            op5.to_matrix(), np.dot(op4.to_matrix(), (H ^ I).to_matrix()))

        op6 = op5 + PrimitiveOp(Operator.from_label('+r').data)
        np.testing.assert_array_almost_equal(
            op6.to_matrix(),
            op5.to_matrix() + Operator.from_label('+r').data)
    def setUp(self):
        """Set up a basic parameterized simulation."""

        self.w = 5.0
        self.r = 0.1

        operators = [
            2 * np.pi * self.w * Array(Operator.from_label("Z").data) / 2,
            2 * np.pi * self.r * Array(Operator.from_label("X").data) / 2,
        ]

        ham = HamiltonianModel(operators=operators)

        self.ham = ham

        def param_sim(amp, drive_freq):
            signals = [
                Constant(1.0),
                Signal(lambda t: amp, carrier_freq=drive_freq)
            ]

            ham_copy = ham.copy()
            ham_copy.signals = signals

            results = solve_lmde(
                ham_copy,
                t_span=[0.0, 1 / self.r],
                y0=Array([0.0, 1.0], dtype=complex),
                method="jax_odeint",
                atol=1e-10,
                rtol=1e-10,
            )
            return results.y[-1]

        self.param_sim = param_sim
    def test_io_consistency(self):
        """ consistency test """
        new_op = X ^ Y ^ I
        label = 'XYI'
        # label = new_op.primitive.to_label()
        self.assertEqual(str(new_op.primitive), label)
        np.testing.assert_array_almost_equal(new_op.primitive.to_matrix(),
                                             Operator.from_label(label).data)
        self.assertEqual(new_op.primitive, Pauli(label=label))

        x_mat = X.primitive.to_matrix()
        y_mat = Y.primitive.to_matrix()
        i_mat = np.eye(2, 2)
        np.testing.assert_array_almost_equal(new_op.primitive.to_matrix(),
                                             np.kron(np.kron(x_mat, y_mat), i_mat))

        hi = np.kron(H.to_matrix(), I.to_matrix())
        hi2 = Operator.from_label('HI').data
        hi3 = (H ^ I).to_matrix()
        np.testing.assert_array_almost_equal(hi, hi2)
        np.testing.assert_array_almost_equal(hi2, hi3)

        xy = np.kron(X.to_matrix(), Y.to_matrix())
        xy2 = Operator.from_label('XY').data
        xy3 = (X ^ Y).to_matrix()
        np.testing.assert_array_almost_equal(xy, xy2)
        np.testing.assert_array_almost_equal(xy2, xy3)

        # Check if numpy array instantiation is the same as from Operator
        matrix_op = Operator.from_label('+r')
        np.testing.assert_array_almost_equal(PrimitiveOp(matrix_op).to_matrix(),
                                             PrimitiveOp(matrix_op.data).to_matrix())
        # Ditto list of lists
        np.testing.assert_array_almost_equal(PrimitiveOp(matrix_op.data.tolist()).to_matrix(),
                                             PrimitiveOp(matrix_op.data).to_matrix())
Пример #4
0
    def test_composite_sqrt(self):
        """Test composite Gate.power(1/2) method.
        """
        circ = QuantumCircuit(1, name='my_gate')
        import numpy as np
        thetaz = 0.1
        thetax = 0.2
        circ.rz(thetaz, 0)
        circ.rx(thetax, 0)
        gate = circ.to_gate()

        result = gate.power(1 / 2)

        iden = Operator.from_label('I')
        xgen = Operator.from_label('X')
        zgen = Operator.from_label('Z')

        def rzgate(theta):
            return np.cos(0.5 * theta) * iden - 1j * np.sin(0.5 * theta) * zgen

        def rxgate(theta):
            return np.cos(0.5 * theta) * iden - 1j * np.sin(0.5 * theta) * xgen

        rxrz = rxgate(thetax) * rzgate(thetaz)

        self.assertEqual(result.label, 'my_gate^0.5')
        self.assertEqual(len(result.definition), 1)
        self.assertIsInstance(result, Gate)
        self.assertEqual(Operator(result) @ Operator(result), rxrz)
Пример #5
0
 def test_subtract_operator_qargs(self, coeff, qargs):
     """Test qargs subtract operation with Operator (coeff={coeff}, qargs={qargs})"""
     # Get labels for qarg addition
     part_array = np.array(['X', 'Y', 'Z'])[range(len(qargs))]
     label = ''.join(part_array)
     full_array = np.array(3 * ['I'])
     inds = [2 - i for i in reversed(qargs)]
     full_array[inds] = part_array
     full_label = ''.join(full_array)
     dims = 3 * (2, )
     val = ScalarOp(dims, coeff=coeff) - Operator.from_label(label)(qargs)
     target = (coeff * Operator.from_label(3 * 'I')) - Operator.from_label(full_label)
     self.assertOperator(val, dims, target)
Пример #6
0
    def setUp(self):
        self.X = Array(Operator.from_label("X").data)
        self.Y = Array(Operator.from_label("Y").data)
        self.Z = Array(Operator.from_label("Z").data)

        # define a basic hamiltonian
        w = 2.0
        r = 0.5
        operators = [2 * np.pi * self.Z / 2, 2 * np.pi * r * self.X / 2]
        signals = [Constant(w), Signal(1.0, w)]

        self.w = w
        self.r = r
        self.basic_hamiltonian = HamiltonianModel(operators=operators, signals=signals)
Пример #7
0
    def test_subtract_operator(self, coeff, label):
        """Test subtract operation with Operator (coeff={coeff}, label={label})"""
        dims = (2, 2)
        iden = ScalarOp(4, coeff=coeff)
        op = Operator.from_label(label)
        with self.subTest(msg="{} - Operator({})".format(iden, label)):
            val = iden - op
            target = coeff * Operator.from_label("II") - op
            self.assertOperator(val, dims, target)

        with self.subTest(msg="Operator({}) - {}".format(label, iden)):
            val = op - iden
            target = op - coeff * Operator.from_label("II")
            self.assertOperator(val, dims, target)
Пример #8
0
    def test_add_operator(self, coeff, label):
        """Test add operation with Operator (coeff={coeff}, label={label})"""
        dims = (2, 2)
        iden = ScalarOp(4, coeff=coeff)
        op = Operator.from_label(label)
        with self.subTest(msg="{} + Operator({})".format(iden, label)):
            val = iden + op
            target = coeff * Operator.from_label("II") + op
            self.assertOperator(val, dims, target)

        with self.subTest(msg="Operator({}) + {}".format(label, iden)):
            val = op + iden
            target = coeff * Operator.from_label("II") + op
            self.assertOperator(val, dims, target)
Пример #9
0
 def test_add_operator_qargs(self, coeff, qargs):
     """Test qargs add operation with Operator (coeff={coeff}, qargs={qargs})"""
     # Get labels for qarg addition
     part_array = np.array(["X", "Y", "Z"])[range(len(qargs))]
     label = "".join(part_array)
     full_array = np.array(3 * ["I"])
     inds = [2 - i for i in reversed(qargs)]
     full_array[inds] = part_array
     full_label = "".join(full_array)
     dims = 3 * (2, )
     val = ScalarOp(dims, coeff=coeff) + Operator.from_label(label)(qargs)
     target = (coeff * Operator.from_label(
         3 * "I")) + Operator.from_label(full_label)
     self.assertOperator(val, dims, target)
 def test_adjoint(self):
     """ adjoint test """
     gnarly_op = 3 * (H ^ I ^ Y).compose(X ^ X ^ Z).tensor(T ^ Z) + \
         PrimitiveOp(Operator.from_label('+r0IX').data)
     np.testing.assert_array_almost_equal(
         np.conj(np.transpose(gnarly_op.to_matrix())),
         gnarly_op.adjoint().to_matrix())
Пример #11
0
    def test_primitive_strings(self):
        """ get primitives test """
        self.assertEqual(X.primitive_strings(), {'Pauli'})

        gnarly_op = 3 * (H ^ I ^ Y).compose(X ^ X ^ Z).tensor(T ^ Z) + \
            PrimitiveOp(Operator.from_label('+r0IX').data)
        self.assertEqual(gnarly_op.primitive_strings(), {'QuantumCircuit', 'Matrix'})
Пример #12
0
    def test_tensor_operator(self, coeff, label):
        """Test tensor and expand methods with ScalarOp and Operator. ({coeff}, {label})"""
        dim = 3
        iden = ScalarOp(dim, coeff=coeff)
        op = Operator.from_label(label)

        with self.subTest(msg="{}.expand(Operator({}))".format(iden, label)):
            val = iden.expand(op)
            target = iden.to_operator().expand(op)
            self.assertOperator(val, (3, 2), target)

        with self.subTest(msg="Operator({}).expand({})".format(label, iden)):
            val = op.expand(iden)
            target = op.expand(iden.to_operator())
            self.assertOperator(val, (2, 3), target)

        with self.subTest(msg="{}.tensor(Operator({}))".format(iden, label)):
            val = iden.tensor(op)
            target = iden.to_operator().tensor(op)
            self.assertOperator(val, (2, 3), target)

        with self.subTest(msg="Operator({}).tensor({})".format(label, iden)):
            val = op.tensor(iden)
            target = op.tensor(iden.to_operator())
            self.assertOperator(val, (3, 2), target)
Пример #13
0
    def setUp(self):
        self.X = Array(Operator.from_label("X").data)
        self.Y = Array(Operator.from_label("Y").data)
        self.Z = Array(Operator.from_label("Z").data)

        # define a basic model
        w = 2.0
        r = 0.5
        operators = [
            -1j * 2 * np.pi * self.Z / 2, -1j * 2 * np.pi * r * self.X / 2
        ]
        signals = [Constant(w), Signal(1.0, w)]

        self.w = 2
        self.r = r
        self.basic_model = GeneratorModel(operators=operators, signals=signals)
Пример #14
0
    def setUp(self):
        self.X = Array(Operator.from_label("X").data)
        self.Y = Array(Operator.from_label("Y").data)
        self.Z = Array(Operator.from_label("Z").data)

        # define a basic model
        w = Array(2.0)
        r = Array(0.5)
        operators = [
            -1j * 2 * np.pi * self.Z / 2, -1j * 2 * np.pi * r * self.X / 2
        ]

        def generator(t):
            return w * operators[0] + np.cos(2 * np.pi * w * t) * operators[1]

        self.w = 2
        self.r = r
        self.basic_model = CallableGenerator(generator)
Пример #15
0
 def test_to_pauli_op(self):
     """ Test to_pauli_op method """
     gnarly_op = 3 * (H ^ I ^ Y).compose(X ^ X ^ Z).tensor(T ^ Z) + \
         PrimitiveOp(Operator.from_label('+r0IX').data)
     mat_op = gnarly_op.to_matrix_op()
     pauli_op = gnarly_op.to_pauli_op()
     self.assertIsInstance(pauli_op, SummedOp)
     for p in pauli_op:
         self.assertIsInstance(p, PauliOp)
     np.testing.assert_array_almost_equal(mat_op.to_matrix(), pauli_op.to_matrix())
Пример #16
0
    def test_compose_operator(self, coeff, label):
        """Test compose and dot methods with ScalarOp and Operator."""
        dim = 4
        iden = ScalarOp(dim, coeff=coeff)
        op = Operator.from_label(label)

        with self.subTest(msg=f"{iden}.compose(Operator({label}))"):
            val = iden.compose(op)
            target = iden.to_operator().compose(op)
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg=f"Operator({label}).compose({iden})"):
            val = op.compose(iden)
            target = op.compose(iden.to_operator())
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg=f"{iden}.dot(Operator({label}))"):
            val = iden.dot(op)
            target = iden.to_operator().dot(op)
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg=f"Operator({label}).dot({iden})"):
            val = op.dot(iden)
            target = op.dot(iden.to_operator())
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg=f"{iden} & Operator({label})"):
            val = iden & op
            target = iden.to_operator().compose(op)
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg=f"Operator({label}) & {iden}"):
            val = op & iden
            target = op.compose(iden.to_operator())
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)
    def test_evals(self):
        """ evals test """
        # pylint: disable=no-member
        # TODO: Think about eval names
        self.assertEqual(Z.eval('0').eval('0'), 1)
        self.assertEqual(Z.eval('1').eval('0'), 0)
        self.assertEqual(Z.eval('0').eval('1'), 0)
        self.assertEqual(Z.eval('1').eval('1'), -1)
        self.assertEqual(X.eval('0').eval('0'), 0)
        self.assertEqual(X.eval('1').eval('0'), 1)
        self.assertEqual(X.eval('0').eval('1'), 1)
        self.assertEqual(X.eval('1').eval('1'), 0)
        self.assertEqual(Y.eval('0').eval('0'), 0)
        self.assertEqual(Y.eval('1').eval('0'), -1j)
        self.assertEqual(Y.eval('0').eval('1'), 1j)
        self.assertEqual(Y.eval('1').eval('1'), 0)

        # Check that Pauli logic eval returns same as matrix logic
        self.assertEqual(PrimitiveOp(Z.to_matrix()).eval('0').eval('0'), 1)
        self.assertEqual(PrimitiveOp(Z.to_matrix()).eval('1').eval('0'), 0)
        self.assertEqual(PrimitiveOp(Z.to_matrix()).eval('0').eval('1'), 0)
        self.assertEqual(PrimitiveOp(Z.to_matrix()).eval('1').eval('1'), -1)
        self.assertEqual(PrimitiveOp(X.to_matrix()).eval('0').eval('0'), 0)
        self.assertEqual(PrimitiveOp(X.to_matrix()).eval('1').eval('0'), 1)
        self.assertEqual(PrimitiveOp(X.to_matrix()).eval('0').eval('1'), 1)
        self.assertEqual(PrimitiveOp(X.to_matrix()).eval('1').eval('1'), 0)
        self.assertEqual(PrimitiveOp(Y.to_matrix()).eval('0').eval('0'), 0)
        self.assertEqual(PrimitiveOp(Y.to_matrix()).eval('1').eval('0'), -1j)
        self.assertEqual(PrimitiveOp(Y.to_matrix()).eval('0').eval('1'), 1j)
        self.assertEqual(PrimitiveOp(Y.to_matrix()).eval('1').eval('1'), 0)

        pauli_op = Z ^ I ^ X ^ Y
        mat_op = PrimitiveOp(pauli_op.to_matrix())
        full_basis = list(
            map(''.join, itertools.product('01', repeat=pauli_op.num_qubits)))
        for bstr1, bstr2 in itertools.product(full_basis, full_basis):
            # print('{} {} {} {}'.format(bstr1, bstr2, pauli_op.eval(bstr1, bstr2),
            # mat_op.eval(bstr1, bstr2)))
            np.testing.assert_array_almost_equal(
                pauli_op.eval(bstr1).eval(bstr2),
                mat_op.eval(bstr1).eval(bstr2))

        gnarly_op = SummedOp([(H ^ I ^ Y).compose(X ^ X ^ Z).tensor(Z),
                              PrimitiveOp(Operator.from_label('+r0I')), 3 *
                              (X ^ CX ^ T)],
                             coeff=3 + .2j)
        gnarly_mat_op = PrimitiveOp(gnarly_op.to_matrix())
        full_basis = list(
            map(''.join, itertools.product('01', repeat=gnarly_op.num_qubits)))
        for bstr1, bstr2 in itertools.product(full_basis, full_basis):
            np.testing.assert_array_almost_equal(
                gnarly_op.eval(bstr1).eval(bstr2),
                gnarly_mat_op.eval(bstr1).eval(bstr2))
Пример #18
0
    def setUp(self):
        self.X = Array(Operator.from_label("X").data)
        self.Y = Array(Operator.from_label("Y").data)
        self.Z = Array(Operator.from_label("Z").data)

        # define a basic hamiltonian
        w = 2.0
        r = 0.5
        ham_operators = [2 * np.pi * self.Z / 2, 2 * np.pi * r * self.X / 2]
        ham_signals = [Constant(w), Signal(1.0, w)]

        self.w = w
        self.r = r

        noise_operators = Array([[[0.0, 0.0], [1.0, 0.0]]])

        self.basic_lindblad = LindbladModel(
            hamiltonian_operators=ham_operators,
            hamiltonian_signals=ham_signals,
            noise_operators=noise_operators,
        )
Пример #19
0
    def test_compose_qargs_operator(self, coeff, label):
        """Test qargs compose and dot methods with ScalarOp and Operator."""
        iden = ScalarOp((2, 2), coeff=coeff)
        op = Operator.from_label(label)

        with self.subTest(msg=f"{iden}.compose(Operator({label}), qargs=[0])"):
            val = iden.compose(op, qargs=[0])
            target = iden.to_operator().compose(op, qargs=[0])
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg=f"{iden}.compose(Operator({label}), qargs=[1])"):
            val = iden.compose(op, qargs=[1])
            target = iden.to_operator().compose(op, qargs=[1])
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg=f"{iden}.dot(Operator({label}), qargs=[0])"):
            val = iden.dot(op, qargs=[0])
            target = iden.to_operator().dot(op, qargs=[0])
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg=f"{iden}.dot(Operator({label}), qargs=[1])"):
            val = iden.dot(op, qargs=[1])
            target = iden.to_operator().dot(op, qargs=[1])
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg=f"{iden} & Operator({label})([0])"):
            val = iden & op([0])
            target = iden.to_operator().compose(op, qargs=[0])
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg=f"{iden} & Operator({label})([1])"):
            val = iden & op([1])
            target = iden.to_operator().compose(op, qargs=[1])
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)
Пример #20
0
    def test_add_operator(self, coeff, label):
        """Test add and subtract operations with Operator (coeff={coeff}, label={label})"""
        dims = (2, 2)
        iden = ScalarOp(4, coeff=coeff)
        op = Operator.from_label(label)
        with self.subTest(msg='{} + Operator({})'.format(iden, label)):
            val = iden + op
            target = coeff * Operator.from_label('II') + op
            self.assertOperator(val, dims, target)

        with self.subTest(msg='Operator({}) + {}'.format(label, iden)):
            val = op + iden
            target = coeff * Operator.from_label('II') + op
            self.assertOperator(val, dims, target)

        with self.subTest(msg='{} - Operator({})'.format(iden, label)):
            val = iden - op
            target = coeff * Operator.from_label('II') - op
            self.assertOperator(val, dims, target)

        with self.subTest(msg='Operator({}) - {}'.format(label, iden)):
            val = op - iden
            target = op - coeff * Operator.from_label('II')
            self.assertOperator(val, dims, target)
Пример #21
0
    def test_compose_operator(self, coeff, label):
        """Test compose and dot methods with ScalarOp and Operator."""
        dim = 4
        iden = ScalarOp(dim, coeff=coeff)
        op = Operator.from_label(label)

        with self.subTest(msg='{}.compose(Operator({}))'.format(iden, label)):
            val = iden.compose(op)
            target = iden.to_operator().compose(op)
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg='Operator({}).compose({})'.format(label, iden)):
            val = op.compose(iden)
            target = op.compose(iden.to_operator())
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg='{}.dot(Operator({}))'.format(iden, label)):
            val = iden.dot(op)
            target = iden.to_operator().dot(op)
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg='Operator({}).dot({})'.format(label, iden)):
            val = op.dot(iden)
            target = op.dot(iden.to_operator())
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg='{} @ Operator({})'.format(iden, label)):
            val = iden @ op
            target = iden.to_operator().compose(op)
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg='Operator({}) @ {}'.format(label, iden)):
            val = op @ iden
            target = op.compose(iden.to_operator())
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg='{} * Operator({})'.format(iden, label)):
            val = iden * op
            target = iden.to_operator().dot(op)
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)

        with self.subTest(msg='Operator({}) * {}'.format(label, iden)):
            val = op * iden
            target = op.dot(iden.to_operator())
            self.assertTrue(isinstance(val, Operator))
            self.assertEqual(val.input_dims(), (2, 2))
            self.assertEqual(val.output_dims(), (2, 2))
            self.assertEqual(val, target)
Пример #22
0
 def test_exact_two_qubit_cnot_decompose_paulis(self):
     """Verify exact CNOT decomposition for Paulis
     """
     unitary = Operator.from_label('XZ')
     self.check_exact_decomposition(unitary.data, two_qubit_cnot_decompose)
def operator_from_label(label):
    """Construct operator from full Pauli group label"""
    pauli, coeff = _split_pauli_label(label)
    coeff = (-1j)**_phase_from_label(coeff)
    return coeff * Operator.from_label(pauli)
Пример #24
0
 def setUp(self):
     self.X = Array(Operator.from_label("X").data)
     self.Y = Array(Operator.from_label("Y").data)
     self.Z = Array(Operator.from_label("Z").data)