# -*- coding: utf-8 -*-

# This code is part of Qiskit.
#
# (C) Copyright IBM 2017, 2019.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

# pylint: disable=invalid-name

"""Tests for Operator matrix linear operator class."""

import unittest
import logging
import copy
import numpy as np
from numpy.testing import assert_allclose
import scipy.linalg as la

from qiskit import QiskitError
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.extensions.standard import HGate, CHGate, CXGate
from qiskit.test import QiskitTestCase
from qiskit.quantum_info.operators.operator import Operator
from qiskit.quantum_info.operators.predicates import matrix_equal

logger = logging.getLogger(__name__)


class OperatorTestCase(QiskitTestCase):
    """Test utils for Operator"""

    # Pauli-matrix unitaries
    UI = np.eye(2)
    UX = np.array([[0, 1], [1, 0]])
    UY = np.array([[0, -1j], [1j, 0]])
    UZ = np.diag([1, -1])
    UH = np.array([[1, 1], [1, -1]]) / np.sqrt(2)

    @classmethod
    def rand_rho(cls, n):
        """Return random density matrix"""
        seed = np.random.randint(0, np.iinfo(np.int32).max)
        logger.debug("rand_rho RandomState seeded with seed=%s", seed)
        rng = np.random.RandomState(seed)

        psi = rng.rand(n) + 1j * rng.rand(n)
        rho = np.outer(psi, psi.conj())
        rho /= np.trace(rho)
        return rho

    @classmethod
    def rand_matrix(cls, rows, cols=None, real=False):
        """Return a random matrix."""
        seed = np.random.randint(0, np.iinfo(np.int32).max)
        logger.debug("rand_matrix RandomState seeded with seed=%s", seed)
        rng = np.random.RandomState(seed)

        if cols is None:
            cols = rows
        if real:
            return rng.rand(rows, cols)
        return rng.rand(rows, cols) + 1j * rng.rand(rows, cols)

    def simple_circuit_no_measure(self):
        """Return a unitary circuit and the corresponding unitary array."""
        qr = QuantumRegister(3)
        circ = QuantumCircuit(qr)
        circ.h(qr[0])
        circ.x(qr[1])
        circ.ry(np.pi / 2, qr[2])
        y90 = (1 / np.sqrt(2)) * np.array([[1, -1], [1, 1]])
        target = Operator(np.kron(y90, np.kron(self.UX, self.UH)))
        return circ, target

    def simple_circuit_with_measure(self):
        """Return a unitary circuit with measurement."""
        qr = QuantumRegister(2)
        cr = ClassicalRegister(2)
        circ = QuantumCircuit(qr, cr)
        circ.h(qr[0])
        circ.x(qr[1])
        circ.measure(qr, cr)
        return circ


class TestOperator(OperatorTestCase):
    """Tests for Operator linear operator class."""

    def test_init_array_qubit(self):
        """Test subsystem initialization from N-qubit array."""
        # Test automatic inference of qubit subsystems
        mat = self.rand_matrix(8, 8)
        op = Operator(mat)
        assert_allclose(op.data, mat)
        self.assertEqual(op.dim, (8, 8))
        self.assertEqual(op.input_dims(), (2, 2, 2))
        self.assertEqual(op.output_dims(), (2, 2, 2))

        op = Operator(mat, input_dims=8, output_dims=8)
        assert_allclose(op.data, mat)
        self.assertEqual(op.dim, (8, 8))
        self.assertEqual(op.input_dims(), (2, 2, 2))
        self.assertEqual(op.output_dims(), (2, 2, 2))

    def test_init_array(self):
        """Test initialization from array."""
        mat = np.eye(3)
        op = Operator(mat)
        assert_allclose(op.data, mat)
        self.assertEqual(op.dim, (3, 3))
        self.assertEqual(op.input_dims(), (3,))
        self.assertEqual(op.output_dims(), (3,))

        mat = self.rand_matrix(2 * 3 * 4, 4 * 5)
        op = Operator(mat, input_dims=[4, 5], output_dims=[2, 3, 4])
        assert_allclose(op.data, mat)
        self.assertEqual(op.dim, (4 * 5, 2 * 3 * 4))
        self.assertEqual(op.input_dims(), (4, 5))
        self.assertEqual(op.output_dims(), (2, 3, 4))

    def test_init_array_except(self):
        """Test initialization exception from array."""
        mat = self.rand_matrix(4, 4)
        self.assertRaises(QiskitError, Operator, mat, input_dims=[4, 2])
        self.assertRaises(QiskitError, Operator, mat, input_dims=[2, 4])
        self.assertRaises(QiskitError, Operator, mat, input_dims=5)

    def test_init_operator(self):
        """Test initialization from Operator."""
        op1 = Operator(self.rand_matrix(4, 4))
        op2 = Operator(op1)
        self.assertEqual(op1, op2)

    def test_circuit_init(self):
        """Test initialization from a circuit."""
        # Test tensor product of 1-qubit gates
        circuit = QuantumCircuit(3)
        circuit.h(0)
        circuit.x(1)
        circuit.ry(np.pi / 2, 2)
        op = Operator(circuit)
        y90 = (1 / np.sqrt(2)) * np.array([[1, -1], [1, 1]])
        target = np.kron(y90, np.kron(self.UX, self.UH))
        global_phase_equivalent = matrix_equal(
            op.data, target, ignore_phase=True)
        self.assertTrue(global_phase_equivalent)

        # Test decomposition of Controlled-u1 gate
        lam = np.pi / 4
        circuit = QuantumCircuit(2)
        circuit.cu1(lam, 0, 1)
        op = Operator(circuit)
        target = np.diag([1, 1, 1, np.exp(1j * lam)])
        global_phase_equivalent = matrix_equal(
            op.data, target, ignore_phase=True)
        self.assertTrue(global_phase_equivalent)

        # Test decomposition of controlled-H gate
        circuit = QuantumCircuit(2)
        circuit.ch(0, 1)
        op = Operator(circuit)
        target = np.kron(self.UI, np.diag([1, 0])) + np.kron(
            self.UH, np.diag([0, 1]))
        global_phase_equivalent = matrix_equal(
            op.data, target, ignore_phase=True)
        self.assertTrue(global_phase_equivalent)

    def test_instruction_init(self):
        """Test initialization from a circuit."""
        gate = CXGate()
        op = Operator(gate).data
        target = gate.to_matrix()
        global_phase_equivalent = matrix_equal(op, target, ignore_phase=True)
        self.assertTrue(global_phase_equivalent)

        gate = CHGate()
        op = Operator(gate).data
        had = HGate().to_matrix()
        target = np.kron(had, np.diag([0, 1])) + np.kron(
            np.eye(2), np.diag([1, 0]))
        global_phase_equivalent = matrix_equal(op, target, ignore_phase=True)
        self.assertTrue(global_phase_equivalent)

    def test_circuit_init_except(self):
        """Test initialization from circuit with measure raises exception."""
        circuit = self.simple_circuit_with_measure()
        self.assertRaises(QiskitError, Operator, circuit)

    def test_equal(self):
        """Test __eq__ method"""
        mat = self.rand_matrix(2, 2, real=True)
        self.assertEqual(Operator(np.array(mat, dtype=complex)),
                         Operator(mat))
        mat = self.rand_matrix(4, 4)
        self.assertEqual(Operator(mat.tolist()),
                         Operator(mat))

    def test_data(self):
        """Test Operator representation string property."""
        mat = self.rand_matrix(2, 2)
        op = Operator(mat)
        assert_allclose(mat, op.data)

    def test_dim(self):
        """Test Operator dim property."""
        mat = self.rand_matrix(4, 4)
        self.assertEqual(Operator(mat).dim, (4, 4))
        self.assertEqual(Operator(mat, input_dims=[4], output_dims=[4]).dim, (4, 4))
        self.assertEqual(Operator(mat, input_dims=[2, 2], output_dims=[2, 2]).dim, (4, 4))

    def test_input_dims(self):
        """Test Operator input_dims method."""
        op = Operator(self.rand_matrix(2 * 3 * 4, 4 * 5),
                      input_dims=[4, 5], output_dims=[2, 3, 4])
        self.assertEqual(op.input_dims(), (4, 5))
        self.assertEqual(op.input_dims(qargs=[0, 1]), (4, 5))
        self.assertEqual(op.input_dims(qargs=[1, 0]), (5, 4))
        self.assertEqual(op.input_dims(qargs=[0]), (4,))
        self.assertEqual(op.input_dims(qargs=[1]), (5,))

    def test_output_dims(self):
        """Test Operator output_dims method."""
        op = Operator(self.rand_matrix(2 * 3 * 4, 4 * 5),
                      input_dims=[4, 5], output_dims=[2, 3, 4])
        self.assertEqual(op.output_dims(), (2, 3, 4))
        self.assertEqual(op.output_dims(qargs=[0, 1, 2]), (2, 3, 4))
        self.assertEqual(op.output_dims(qargs=[2, 1, 0]), (4, 3, 2))
        self.assertEqual(op.output_dims(qargs=[2, 0, 1]), (4, 2, 3))
        self.assertEqual(op.output_dims(qargs=[0]), (2,))
        self.assertEqual(op.output_dims(qargs=[1]), (3,))
        self.assertEqual(op.output_dims(qargs=[2]), (4,))
        self.assertEqual(op.output_dims(qargs=[0, 2]), (2, 4))
        self.assertEqual(op.output_dims(qargs=[2, 0]), (4, 2))

    def test_reshape(self):
        """Test Operator reshape method."""
        op = Operator(self.rand_matrix(8, 8))
        reshaped1 = op.reshape(input_dims=[8], output_dims=[8])
        reshaped2 = op.reshape(input_dims=[4, 2], output_dims=[2, 4])
        self.assertEqual(op.output_dims(), (2, 2, 2))
        self.assertEqual(op.input_dims(), (2, 2, 2))
        self.assertEqual(reshaped1.output_dims(), (8,))
        self.assertEqual(reshaped1.input_dims(), (8,))
        self.assertEqual(reshaped2.output_dims(), (2, 4))
        self.assertEqual(reshaped2.input_dims(), (4, 2))

    def test_copy(self):
        """Test Operator copy method"""
        mat = np.eye(2)
        with self.subTest("Deep copy"):
            orig = Operator(mat)
            cpy = orig.copy()
            cpy._data[0, 0] = 0.0
            self.assertFalse(cpy == orig)
        with self.subTest("Shallow copy"):
            orig = Operator(mat)
            clone = copy.copy(orig)
            clone._data[0, 0] = 0.0
            self.assertTrue(clone == orig)

    def test_is_unitary(self):
        """Test is_unitary method."""
        # X-90 rotation
        X90 = la.expm(-1j * 0.5 * np.pi * np.array([[0, 1], [1, 0]]) / 2)
        self.assertTrue(Operator(X90).is_unitary())
        # Non-unitary should return false
        self.assertFalse(Operator([[1, 0], [0, 0]]).is_unitary())

    def test_to_operator(self):
        """Test to_operator method."""
        op1 = Operator(self.rand_matrix(4, 4))
        op2 = op1.to_operator()
        self.assertEqual(op1, op2)

    def test_conjugate(self):
        """Test conjugate method."""
        matr = self.rand_matrix(2, 4, real=True)
        mati = self.rand_matrix(2, 4, real=True)
        op = Operator(matr + 1j * mati)
        uni_conj = op.conjugate()
        self.assertEqual(uni_conj, Operator(matr - 1j * mati))

    def test_transpose(self):
        """Test transpose method."""
        matr = self.rand_matrix(2, 4, real=True)
        mati = self.rand_matrix(2, 4, real=True)
        op = Operator(matr + 1j * mati)
        uni_t = op.transpose()
        self.assertEqual(uni_t, Operator(matr.T + 1j * mati.T))

    def test_adjoint(self):
        """Test adjoint method."""
        matr = self.rand_matrix(2, 4, real=True)
        mati = self.rand_matrix(2, 4, real=True)
        op = Operator(matr + 1j * mati)
        uni_adj = op.adjoint()
        self.assertEqual(uni_adj, Operator(matr.T - 1j * mati.T))

    def test_compose_except(self):
        """Test compose different dimension exception"""
        self.assertRaises(QiskitError,
                          Operator(np.eye(2)).compose,
                          Operator(np.eye(3)))
        self.assertRaises(QiskitError, Operator(np.eye(2)).compose, 2)

    def test_compose(self):
        """Test compose method."""

        op1 = Operator(self.UX)
        op2 = Operator(self.UY)

        targ = Operator(np.dot(self.UY, self.UX))
        self.assertEqual(op1.compose(op2), targ)
        self.assertEqual(op1 @ op2, targ)

        targ = Operator(np.dot(self.UX, self.UY))
        self.assertEqual(op2.compose(op1), targ)
        self.assertEqual(op2 @ op1, targ)

    def test_dot(self):
        """Test dot method."""
        op1 = Operator(self.UY)
        op2 = Operator(self.UX)

        targ = Operator(np.dot(self.UY, self.UX))
        self.assertEqual(op1.dot(op2), targ)
        self.assertEqual(op1 * op2, targ)

        targ = Operator(np.dot(self.UX, self.UY))
        self.assertEqual(op2.dot(op1), targ)
        self.assertEqual(op2 * op1, targ)

    def test_compose_front(self):
        """Test front compose method."""

        opYX = Operator(self.UY).compose(Operator(self.UX), front=True)
        matYX = np.dot(self.UY, self.UX)
        self.assertEqual(opYX, Operator(matYX))

        opXY = Operator(self.UX).compose(Operator(self.UY), front=True)
        matXY = np.dot(self.UX, self.UY)
        self.assertEqual(opXY, Operator(matXY))

    def test_compose_subsystem(self):
        """Test subsystem compose method."""
        # 3-qubit operator
        mat = self.rand_matrix(8, 8)
        mat_a = self.rand_matrix(2, 2)
        mat_b = self.rand_matrix(2, 2)
        mat_c = self.rand_matrix(2, 2)
        op = Operator(mat)
        op1 = Operator(mat_a)
        op2 = Operator(np.kron(mat_b, mat_a))
        op3 = Operator(np.kron(mat_c, np.kron(mat_b, mat_a)))

        # op3 qargs=[0, 1, 2]
        targ = np.dot(np.kron(mat_c, np.kron(mat_b, mat_a)), mat)
        self.assertEqual(op.compose(op3, qargs=[0, 1, 2]), Operator(targ))
        self.assertEqual(op.compose(op3([0, 1, 2])), Operator(targ))
        self.assertEqual(op @ op3([0, 1, 2]), Operator(targ))
        # op3 qargs=[2, 1, 0]
        targ = np.dot(np.kron(mat_a, np.kron(mat_b, mat_c)), mat)
        self.assertEqual(op.compose(op3, qargs=[2, 1, 0]), Operator(targ))
        self.assertEqual(op @ op3([2, 1, 0]), Operator(targ))

        # op2 qargs=[0, 1]
        targ = np.dot(np.kron(np.eye(2), np.kron(mat_b, mat_a)), mat)
        self.assertEqual(op.compose(op2, qargs=[0, 1]), Operator(targ))
        self.assertEqual(op @ op2([0, 1]), Operator(targ))
        # op2 qargs=[2, 0]
        targ = np.dot(np.kron(mat_a, np.kron(np.eye(2), mat_b)), mat)
        self.assertEqual(op.compose(op2, qargs=[2, 0]), Operator(targ))
        self.assertEqual(op @ op2([2, 0]), Operator(targ))

        # op1 qargs=[0]
        targ = np.dot(np.kron(np.eye(4), mat_a), mat)
        self.assertEqual(op.compose(op1, qargs=[0]), Operator(targ))
        self.assertEqual(op @ op1([0]), Operator(targ))
        # op1 qargs=[1]
        targ = np.dot(np.kron(np.eye(2), np.kron(mat_a, np.eye(2))), mat)
        self.assertEqual(op.compose(op1, qargs=[1]), Operator(targ))
        self.assertEqual(op @ op1([1]), Operator(targ))
        # op1 qargs=[2]
        targ = np.dot(np.kron(mat_a, np.eye(4)), mat)
        self.assertEqual(op.compose(op1, qargs=[2]), Operator(targ))
        self.assertEqual(op @ op1([2]), Operator(targ))

    def test_dot_subsystem(self):
        """Test subsystem dot method."""
        # 3-qubit operator
        mat = self.rand_matrix(8, 8)
        mat_a = self.rand_matrix(2, 2)
        mat_b = self.rand_matrix(2, 2)
        mat_c = self.rand_matrix(2, 2)
        op = Operator(mat)
        op1 = Operator(mat_a)
        op2 = Operator(np.kron(mat_b, mat_a))
        op3 = Operator(np.kron(mat_c, np.kron(mat_b, mat_a)))

        # op3 qargs=[0, 1, 2]
        targ = np.dot(mat, np.kron(mat_c, np.kron(mat_b, mat_a)))
        self.assertEqual(op.dot(op3, qargs=[0, 1, 2]), Operator(targ))
        self.assertEqual(op * op3([0, 1, 2]), Operator(targ))
        # op3 qargs=[2, 1, 0]
        targ = np.dot(mat, np.kron(mat_a, np.kron(mat_b, mat_c)))
        self.assertEqual(op.dot(op3, qargs=[2, 1, 0]), Operator(targ))
        self.assertEqual(op * op3([2, 1, 0]), Operator(targ))

        # op2 qargs=[0, 1]
        targ = np.dot(mat, np.kron(np.eye(2), np.kron(mat_b, mat_a)))
        self.assertEqual(op.dot(op2, qargs=[0, 1]), Operator(targ))
        self.assertEqual(op * op2([0, 1]), Operator(targ))
        # op2 qargs=[2, 0]
        targ = np.dot(mat, np.kron(mat_a, np.kron(np.eye(2), mat_b)))
        self.assertEqual(op.dot(op2, qargs=[2, 0]), Operator(targ))
        self.assertEqual(op * op2([2, 0]), Operator(targ))

        # op1 qargs=[0]
        targ = np.dot(mat, np.kron(np.eye(4), mat_a))
        self.assertEqual(op.dot(op1, qargs=[0]), Operator(targ))
        self.assertEqual(op * op1([0]), Operator(targ))
        # op1 qargs=[1]
        targ = np.dot(mat, np.kron(np.eye(2), np.kron(mat_a, np.eye(2))))
        self.assertEqual(op.dot(op1, qargs=[1]), Operator(targ))
        self.assertEqual(op * op1([1]), Operator(targ))
        # op1 qargs=[2]
        targ = np.dot(mat, np.kron(mat_a, np.eye(4)))
        self.assertEqual(op.dot(op1, qargs=[2]), Operator(targ))
        self.assertEqual(op * op1([2]), Operator(targ))

    def test_compose_front_subsystem(self):
        """Test subsystem front compose method."""
        # 3-qubit operator
        mat = self.rand_matrix(8, 8)
        mat_a = self.rand_matrix(2, 2)
        mat_b = self.rand_matrix(2, 2)
        mat_c = self.rand_matrix(2, 2)
        op = Operator(mat)
        op1 = Operator(mat_a)
        op2 = Operator(np.kron(mat_b, mat_a))
        op3 = Operator(np.kron(mat_c, np.kron(mat_b, mat_a)))

        # op3 qargs=[0, 1, 2]
        targ = np.dot(mat, np.kron(mat_c, np.kron(mat_b, mat_a)))
        self.assertEqual(op.compose(op3, qargs=[0, 1, 2], front=True), Operator(targ))
        # op3 qargs=[2, 1, 0]
        targ = np.dot(mat, np.kron(mat_a, np.kron(mat_b, mat_c)))
        self.assertEqual(op.compose(op3, qargs=[2, 1, 0], front=True), Operator(targ))

        # op2 qargs=[0, 1]
        targ = np.dot(mat, np.kron(np.eye(2), np.kron(mat_b, mat_a)))
        self.assertEqual(op.compose(op2, qargs=[0, 1], front=True), Operator(targ))
        # op2 qargs=[2, 0]
        targ = np.dot(mat, np.kron(mat_a, np.kron(np.eye(2), mat_b)))
        self.assertEqual(op.compose(op2, qargs=[2, 0], front=True), Operator(targ))

        # op1 qargs=[0]
        targ = np.dot(mat, np.kron(np.eye(4), mat_a))
        self.assertEqual(op.compose(op1, qargs=[0], front=True), Operator(targ))

        # op1 qargs=[1]
        targ = np.dot(mat, np.kron(np.eye(2), np.kron(mat_a, np.eye(2))))
        self.assertEqual(op.compose(op1, qargs=[1], front=True), Operator(targ))

        # op1 qargs=[2]
        targ = np.dot(mat, np.kron(mat_a, np.eye(4)))
        self.assertEqual(op.compose(op1, qargs=[2], front=True), Operator(targ))

    def test_power(self):
        """Test power method."""
        X90 = la.expm(-1j * 0.5 * np.pi * np.array([[0, 1], [1, 0]]) / 2)
        op = Operator(X90)
        self.assertEqual(op.power(2), Operator([[0, -1j], [-1j, 0]]))
        self.assertEqual(op.power(4), Operator(-1 * np.eye(2)))
        self.assertEqual(op.power(8), Operator(np.eye(2)))

    def test_expand(self):
        """Test expand method."""
        mat1 = self.UX
        mat2 = np.eye(3, dtype=complex)

        mat21 = np.kron(mat2, mat1)
        op21 = Operator(mat1).expand(Operator(mat2))
        self.assertEqual(op21.dim, (6, 6))
        assert_allclose(op21.data, Operator(mat21).data)

        mat12 = np.kron(mat1, mat2)
        op12 = Operator(mat2).expand(Operator(mat1))
        self.assertEqual(op12.dim, (6, 6))
        assert_allclose(op12.data, Operator(mat12).data)

    def test_tensor(self):
        """Test tensor method."""
        mat1 = self.UX
        mat2 = np.eye(3, dtype=complex)

        mat21 = np.kron(mat2, mat1)
        op21 = Operator(mat2).tensor(Operator(mat1))
        self.assertEqual(op21.dim, (6, 6))
        assert_allclose(op21.data, Operator(mat21).data)

        mat12 = np.kron(mat1, mat2)
        op12 = Operator(mat1).tensor(Operator(mat2))
        self.assertEqual(op12.dim, (6, 6))
        assert_allclose(op12.data, Operator(mat12).data)

    def test_power_except(self):
        """Test power method raises exceptions."""
        op = Operator(self.rand_matrix(3, 3))
        # Non-integer power raises error
        self.assertRaises(QiskitError, op.power, 0.5)

    def test_add(self):
        """Test add method."""
        mat1 = self.rand_matrix(4, 4)
        mat2 = self.rand_matrix(4, 4)
        op1 = Operator(mat1)
        op2 = Operator(mat2)
        self.assertEqual(op1._add(op2), Operator(mat1 + mat2))
        self.assertEqual(op1 + op2, Operator(mat1 + mat2))
        self.assertEqual(op1 - op2, Operator(mat1 - mat2))

    def test_add_except(self):
        """Test add method raises exceptions."""
        op1 = Operator(self.rand_matrix(2, 2))
        op2 = Operator(self.rand_matrix(3, 3))
        self.assertRaises(QiskitError, op1._add, op2)

    def test_multiply(self):
        """Test multiply method."""
        mat = self.rand_matrix(4, 4)
        val = np.exp(5j)
        op = Operator(mat)
        self.assertEqual(op._multiply(val), Operator(val * mat))
        self.assertEqual(val * op, Operator(val * mat))

    def test_multiply_except(self):
        """Test multiply method raises exceptions."""
        op = Operator(self.rand_matrix(2, 2))
        self.assertRaises(QiskitError, op._multiply, 's')
        self.assertRaises(QiskitError, op.__rmul__, 's')
        self.assertRaises(QiskitError, op._multiply, op)
        self.assertRaises(QiskitError, op.__rmul__, op)

    def test_negate(self):
        """Test negate method"""
        mat = self.rand_matrix(4, 4)
        op = Operator(mat)
        self.assertEqual(-op, Operator(-1 * mat))

    def test_equiv(self):
        """Test negate method"""
        mat = np.diag([1, np.exp(1j * np.pi / 2)])
        phase = np.exp(-1j * np.pi / 4)
        op = Operator(mat)
        self.assertTrue(op.equiv(phase * mat))
        self.assertTrue(op.equiv(Operator(phase * mat)))
        self.assertFalse(op.equiv(2 * mat))


if __name__ == '__main__':
    unittest.main()

[((33, 9, 33, 36), 'logging.getLogger', 'logging.getLogger', ({(33, 27, 33, 35): '__name__'}, {}), '(__name__)', False, 'import logging\n'), ((40, 9, 40, 18), 'numpy.eye', 'np.eye', ({(40, 16, 40, 17): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((41, 9, 41, 35), 'numpy.array', 'np.array', ({(41, 18, 41, 34): '[[0, 1], [1, 0]]'}, {}), '([[0, 1], [1, 0]])', True, 'import numpy as np\n'), ((42, 9, 42, 38), 'numpy.array', 'np.array', ({(42, 18, 42, 37): '[[0, -1.0j], [1.0j, 0]]'}, {}), '([[0, -1.0j], [1.0j, 0]])', True, 'import numpy as np\n'), ((43, 9, 43, 25), 'numpy.diag', 'np.diag', ({(43, 17, 43, 24): '[1, -1]'}, {}), '([1, -1])', True, 'import numpy as np\n'), ((569, 4, 569, 19), 'unittest.main', 'unittest.main', ({}, {}), '()', False, 'import unittest\n'), ((44, 9, 44, 36), 'numpy.array', 'np.array', ({(44, 18, 44, 35): '[[1, 1], [1, -1]]'}, {}), '([[1, 1], [1, -1]])', True, 'import numpy as np\n'), ((44, 39, 44, 49), 'numpy.sqrt', 'np.sqrt', ({(44, 47, 44, 48): '(2)'}, {}), '(2)', True, 'import numpy as np\n'), ((51, 14, 51, 41), 'numpy.random.RandomState', 'np.random.RandomState', ({(51, 36, 51, 40): 'seed'}, {}), '(seed)', True, 'import numpy as np\n'), ((55, 15, 55, 28), 'numpy.trace', 'np.trace', ({(55, 24, 55, 27): 'rho'}, {}), '(rho)', True, 'import numpy as np\n'), ((63, 14, 63, 41), 'numpy.random.RandomState', 'np.random.RandomState', ({(63, 36, 63, 40): 'seed'}, {}), '(seed)', True, 'import numpy as np\n'), ((73, 13, 73, 31), 'qiskit.QuantumRegister', 'QuantumRegister', ({(73, 29, 73, 30): '3'}, {}), '(3)', False, 'from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit\n'), ((74, 15, 74, 33), 'qiskit.QuantumCircuit', 'QuantumCircuit', ({(74, 30, 74, 32): 'qr'}, {}), '(qr)', False, 'from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit\n'), ((84, 13, 84, 31), 'qiskit.QuantumRegister', 'QuantumRegister', ({(84, 29, 84, 30): '2'}, {}), '(2)', False, 'from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit\n'), ((85, 13, 85, 33), 'qiskit.ClassicalRegister', 'ClassicalRegister', ({(85, 31, 85, 32): '2'}, {}), '(2)', False, 'from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit\n'), ((86, 15, 86, 37), 'qiskit.QuantumCircuit', 'QuantumCircuit', ({(86, 30, 86, 32): 'qr', (86, 34, 86, 36): 'cr'}, {}), '(qr, cr)', False, 'from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit\n'), ((100, 13, 100, 26), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(100, 22, 100, 25): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((101, 8, 101, 37), 'numpy.testing.assert_allclose', 'assert_allclose', ({(101, 24, 101, 31): 'op.data', (101, 33, 101, 36): 'mat'}, {}), '(op.data, mat)', False, 'from numpy.testing import assert_allclose\n'), ((106, 13, 106, 55), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', (), '', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((107, 8, 107, 37), 'numpy.testing.assert_allclose', 'assert_allclose', ({(107, 24, 107, 31): 'op.data', (107, 33, 107, 36): 'mat'}, {}), '(op.data, mat)', False, 'from numpy.testing import assert_allclose\n'), ((114, 14, 114, 23), 'numpy.eye', 'np.eye', ({(114, 21, 114, 22): '3'}, {}), '(3)', True, 'import numpy as np\n'), ((115, 13, 115, 26), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(115, 22, 115, 25): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((116, 8, 116, 37), 'numpy.testing.assert_allclose', 'assert_allclose', ({(116, 24, 116, 31): 'op.data', (116, 33, 116, 36): 'mat'}, {}), '(op.data, mat)', False, 'from numpy.testing import assert_allclose\n'), ((122, 13, 122, 68), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', (), '', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((123, 8, 123, 37), 'numpy.testing.assert_allclose', 'assert_allclose', ({(123, 24, 123, 31): 'op.data', (123, 33, 123, 36): 'mat'}, {}), '(op.data, mat)', False, 'from numpy.testing import assert_allclose\n'), ((138, 14, 138, 27), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(138, 23, 138, 26): 'op1'}, {}), '(op1)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((144, 18, 144, 35), 'qiskit.QuantumCircuit', 'QuantumCircuit', ({(144, 33, 144, 34): '3'}, {}), '(3)', False, 'from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit\n'), ((148, 13, 148, 30), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(148, 22, 148, 29): 'circuit'}, {}), '(circuit)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((151, 34, 152, 47), 'qiskit.quantum_info.operators.predicates.matrix_equal', 'matrix_equal', (), '', False, 'from qiskit.quantum_info.operators.predicates import matrix_equal\n'), ((157, 18, 157, 35), 'qiskit.QuantumCircuit', 'QuantumCircuit', ({(157, 33, 157, 34): '2'}, {}), '(2)', False, 'from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit\n'), ((159, 13, 159, 30), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(159, 22, 159, 29): 'circuit'}, {}), '(circuit)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((161, 34, 162, 47), 'qiskit.quantum_info.operators.predicates.matrix_equal', 'matrix_equal', (), '', False, 'from qiskit.quantum_info.operators.predicates import matrix_equal\n'), ((166, 18, 166, 35), 'qiskit.QuantumCircuit', 'QuantumCircuit', ({(166, 33, 166, 34): '2'}, {}), '(2)', False, 'from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit\n'), ((168, 13, 168, 30), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(168, 22, 168, 29): 'circuit'}, {}), '(circuit)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((171, 34, 172, 47), 'qiskit.quantum_info.operators.predicates.matrix_equal', 'matrix_equal', (), '', False, 'from qiskit.quantum_info.operators.predicates import matrix_equal\n'), ((177, 15, 177, 23), 'qiskit.extensions.standard.CXGate', 'CXGate', ({}, {}), '()', False, 'from qiskit.extensions.standard import HGate, CHGate, CXGate\n'), ((180, 34, 180, 77), 'qiskit.quantum_info.operators.predicates.matrix_equal', 'matrix_equal', (), '', False, 'from qiskit.quantum_info.operators.predicates import matrix_equal\n'), ((183, 15, 183, 23), 'qiskit.extensions.standard.CHGate', 'CHGate', ({}, {}), '()', False, 'from qiskit.extensions.standard import HGate, CHGate, CXGate\n'), ((188, 34, 188, 77), 'qiskit.quantum_info.operators.predicates.matrix_equal', 'matrix_equal', (), '', False, 'from qiskit.quantum_info.operators.predicates import matrix_equal\n'), ((208, 13, 208, 26), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(208, 22, 208, 25): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((209, 8, 209, 37), 'numpy.testing.assert_allclose', 'assert_allclose', ({(209, 24, 209, 27): 'mat', (209, 29, 209, 36): 'op.data'}, {}), '(mat, op.data)', False, 'from numpy.testing import assert_allclose\n'), ((256, 14, 256, 23), 'numpy.eye', 'np.eye', ({(256, 21, 256, 22): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((286, 13, 286, 39), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(286, 22, 286, 38): 'matr + 1.0j * mati'}, {}), '(matr + 1.0j * mati)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((294, 13, 294, 39), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(294, 22, 294, 38): 'matr + 1.0j * mati'}, {}), '(matr + 1.0j * mati)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((302, 13, 302, 39), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(302, 22, 302, 38): 'matr + 1.0j * mati'}, {}), '(matr + 1.0j * mati)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((316, 14, 316, 31), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(316, 23, 316, 30): 'self.UX'}, {}), '(self.UX)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((317, 14, 317, 31), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(317, 23, 317, 30): 'self.UY'}, {}), '(self.UY)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((329, 14, 329, 31), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(329, 23, 329, 30): 'self.UY'}, {}), '(self.UY)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((330, 14, 330, 31), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(330, 23, 330, 30): 'self.UX'}, {}), '(self.UX)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((344, 16, 344, 40), 'numpy.dot', 'np.dot', ({(344, 23, 344, 30): 'self.UY', (344, 32, 344, 39): 'self.UX'}, {}), '(self.UY, self.UX)', True, 'import numpy as np\n'), ((348, 16, 348, 40), 'numpy.dot', 'np.dot', ({(348, 23, 348, 30): 'self.UX', (348, 32, 348, 39): 'self.UY'}, {}), '(self.UX, self.UY)', True, 'import numpy as np\n'), ((358, 13, 358, 26), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(358, 22, 358, 25): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((359, 14, 359, 29), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(359, 23, 359, 28): 'mat_a'}, {}), '(mat_a)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((402, 13, 402, 26), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(402, 22, 402, 25): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((403, 14, 403, 29), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(403, 23, 403, 28): 'mat_a'}, {}), '(mat_a)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((445, 13, 445, 26), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(445, 22, 445, 25): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((446, 14, 446, 29), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(446, 23, 446, 28): 'mat_a'}, {}), '(mat_a)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((479, 13, 479, 26), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(479, 22, 479, 25): 'X90'}, {}), '(X90)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((487, 15, 487, 39), 'numpy.eye', 'np.eye', (), '', True, 'import numpy as np\n'), ((489, 16, 489, 35), 'numpy.kron', 'np.kron', ({(489, 24, 489, 28): 'mat2', (489, 30, 489, 34): 'mat1'}, {}), '(mat2, mat1)', True, 'import numpy as np\n'), ((494, 16, 494, 35), 'numpy.kron', 'np.kron', ({(494, 24, 494, 28): 'mat1', (494, 30, 494, 34): 'mat2'}, {}), '(mat1, mat2)', True, 'import numpy as np\n'), ((502, 15, 502, 39), 'numpy.eye', 'np.eye', (), '', True, 'import numpy as np\n'), ((504, 16, 504, 35), 'numpy.kron', 'np.kron', ({(504, 24, 504, 28): 'mat2', (504, 30, 504, 34): 'mat1'}, {}), '(mat2, mat1)', True, 'import numpy as np\n'), ((509, 16, 509, 35), 'numpy.kron', 'np.kron', ({(509, 24, 509, 28): 'mat1', (509, 30, 509, 34): 'mat2'}, {}), '(mat1, mat2)', True, 'import numpy as np\n'), ((524, 14, 524, 28), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(524, 23, 524, 27): 'mat1'}, {}), '(mat1)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((525, 14, 525, 28), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(525, 23, 525, 27): 'mat2'}, {}), '(mat2)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((539, 14, 539, 24), 'numpy.exp', 'np.exp', ({(539, 21, 539, 23): '5.0j'}, {}), '(5.0j)', True, 'import numpy as np\n'), ((540, 13, 540, 26), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(540, 22, 540, 25): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((555, 13, 555, 26), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(555, 22, 555, 25): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((561, 16, 561, 39), 'numpy.exp', 'np.exp', ({(561, 23, 561, 38): '-1.0j * np.pi / 4'}, {}), '(-1.0j * np.pi / 4)', True, 'import numpy as np\n'), ((562, 13, 562, 26), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(562, 22, 562, 25): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((78, 33, 78, 60), 'numpy.array', 'np.array', ({(78, 42, 78, 59): '[[1, -1], [1, 1]]'}, {}), '([[1, -1], [1, 1]])', True, 'import numpy as np\n'), ((149, 33, 149, 60), 'numpy.array', 'np.array', ({(149, 42, 149, 59): '[[1, -1], [1, 1]]'}, {}), '([[1, -1], [1, 1]])', True, 'import numpy as np\n'), ((150, 30, 150, 55), 'numpy.kron', 'np.kron', ({(150, 38, 150, 45): 'self.UX', (150, 47, 150, 54): 'self.UH'}, {}), '(self.UX, self.UH)', True, 'import numpy as np\n'), ((178, 13, 178, 27), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(178, 22, 178, 26): 'gate'}, {}), '(gate)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((184, 13, 184, 27), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(184, 22, 184, 26): 'gate'}, {}), '(gate)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((200, 25, 200, 38), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(200, 34, 200, 37): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((203, 25, 203, 38), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(203, 34, 203, 37): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((258, 19, 258, 32), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(258, 28, 258, 31): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((263, 19, 263, 32), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(263, 28, 263, 31): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((264, 20, 264, 35), 'copy.copy', 'copy.copy', ({(264, 30, 264, 34): 'orig'}, {}), '(orig)', False, 'import copy\n'), ((288, 35, 288, 61), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(288, 44, 288, 60): '(matr - 1.0j * mati)'}, {}), '(matr - 1.0j * mati)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((296, 32, 296, 62), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(296, 41, 296, 61): '(matr.T + 1.0j * mati.T)'}, {}), '(matr.T + 1.0j * mati.T)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((304, 34, 304, 64), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(304, 43, 304, 63): '(matr.T - 1.0j * mati.T)'}, {}), '(matr.T - 1.0j * mati.T)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((319, 24, 319, 48), 'numpy.dot', 'np.dot', ({(319, 31, 319, 38): 'self.UY', (319, 40, 319, 47): 'self.UX'}, {}), '(self.UY, self.UX)', True, 'import numpy as np\n'), ((323, 24, 323, 48), 'numpy.dot', 'np.dot', ({(323, 31, 323, 38): 'self.UX', (323, 40, 323, 47): 'self.UY'}, {}), '(self.UX, self.UY)', True, 'import numpy as np\n'), ((332, 24, 332, 48), 'numpy.dot', 'np.dot', ({(332, 31, 332, 38): 'self.UY', (332, 40, 332, 47): 'self.UX'}, {}), '(self.UY, self.UX)', True, 'import numpy as np\n'), ((336, 24, 336, 48), 'numpy.dot', 'np.dot', ({(336, 31, 336, 38): 'self.UX', (336, 40, 336, 47): 'self.UY'}, {}), '(self.UX, self.UY)', True, 'import numpy as np\n'), ((343, 41, 343, 58), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(343, 50, 343, 57): 'self.UX'}, {}), '(self.UX)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((345, 31, 345, 46), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(345, 40, 345, 45): 'matYX'}, {}), '(matYX)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((347, 41, 347, 58), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(347, 50, 347, 57): 'self.UY'}, {}), '(self.UY)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((349, 31, 349, 46), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(349, 40, 349, 45): 'matXY'}, {}), '(matXY)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((360, 23, 360, 44), 'numpy.kron', 'np.kron', ({(360, 31, 360, 36): 'mat_b', (360, 38, 360, 43): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((365, 59, 365, 73), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(365, 68, 365, 72): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((366, 53, 366, 67), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(366, 62, 366, 66): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((367, 46, 367, 60), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(367, 55, 367, 59): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((370, 59, 370, 73), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(370, 68, 370, 72): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((371, 46, 371, 60), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(371, 55, 371, 59): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((375, 56, 375, 70), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(375, 65, 375, 69): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((376, 43, 376, 57), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(376, 52, 376, 56): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((379, 56, 379, 70), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(379, 65, 379, 69): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((380, 43, 380, 57), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(380, 52, 380, 56): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((384, 53, 384, 67), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(384, 62, 384, 66): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((385, 40, 385, 54), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(385, 49, 385, 53): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((388, 53, 388, 67), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(388, 62, 388, 66): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((389, 40, 389, 54), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(389, 49, 389, 53): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((392, 53, 392, 67), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(392, 62, 392, 66): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((393, 40, 393, 54), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(393, 49, 393, 53): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((404, 23, 404, 44), 'numpy.kron', 'np.kron', ({(404, 31, 404, 36): 'mat_b', (404, 38, 404, 43): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((409, 55, 409, 69), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(409, 64, 409, 68): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((410, 46, 410, 60), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(410, 55, 410, 59): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((413, 55, 413, 69), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(413, 64, 413, 68): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((414, 46, 414, 60), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(414, 55, 414, 59): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((418, 52, 418, 66), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(418, 61, 418, 65): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((419, 43, 419, 57), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(419, 52, 419, 56): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((422, 52, 422, 66), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(422, 61, 422, 65): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((423, 43, 423, 57), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(423, 52, 423, 56): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((427, 49, 427, 63), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(427, 58, 427, 62): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((428, 40, 428, 54), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(428, 49, 428, 53): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((431, 49, 431, 63), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(431, 58, 431, 62): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((432, 40, 432, 54), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(432, 49, 432, 53): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((435, 49, 435, 63), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(435, 58, 435, 62): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((436, 40, 436, 54), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(436, 49, 436, 53): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((447, 23, 447, 44), 'numpy.kron', 'np.kron', ({(447, 31, 447, 36): 'mat_b', (447, 38, 447, 43): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((452, 71, 452, 85), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(452, 80, 452, 84): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((455, 71, 455, 85), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(455, 80, 455, 84): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((459, 68, 459, 82), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(459, 77, 459, 81): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((462, 68, 462, 82), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(462, 77, 462, 81): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((466, 65, 466, 79), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(466, 74, 466, 78): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((470, 65, 470, 79), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(470, 74, 470, 78): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((474, 65, 474, 79), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(474, 74, 474, 78): 'targ'}, {}), '(targ)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((480, 38, 480, 68), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(480, 47, 480, 67): '[[0, -1.0j], [-1.0j, 0]]'}, {}), '([[0, -1.0j], [-1.0j, 0]])', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((490, 37, 490, 51), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(490, 46, 490, 50): 'mat2'}, {}), '(mat2)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((495, 37, 495, 51), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(495, 46, 495, 50): 'mat1'}, {}), '(mat1)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((505, 37, 505, 51), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(505, 46, 505, 50): 'mat1'}, {}), '(mat1)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((510, 37, 510, 51), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(510, 46, 510, 50): 'mat2'}, {}), '(mat2)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((526, 40, 526, 61), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(526, 49, 526, 60): '(mat1 + mat2)'}, {}), '(mat1 + mat2)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((527, 36, 527, 57), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(527, 45, 527, 56): '(mat1 + mat2)'}, {}), '(mat1 + mat2)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((528, 36, 528, 57), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(528, 45, 528, 56): '(mat1 - mat2)'}, {}), '(mat1 - mat2)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((541, 44, 541, 63), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(541, 53, 541, 62): '(val * mat)'}, {}), '(val * mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((542, 35, 542, 54), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(542, 44, 542, 53): '(val * mat)'}, {}), '(val * mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((556, 30, 556, 48), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(556, 39, 556, 47): '(-1 * mat)'}, {}), '(-1 * mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((49, 36, 49, 54), 'numpy.iinfo', 'np.iinfo', ({(49, 45, 49, 53): 'np.int32'}, {}), '(np.int32)', True, 'import numpy as np\n'), ((61, 36, 61, 54), 'numpy.iinfo', 'np.iinfo', ({(61, 45, 61, 53): 'np.int32'}, {}), '(np.int32)', True, 'import numpy as np\n'), ((78, 19, 78, 29), 'numpy.sqrt', 'np.sqrt', ({(78, 27, 78, 28): '(2)'}, {}), '(2)', True, 'import numpy as np\n'), ((79, 39, 79, 64), 'numpy.kron', 'np.kron', ({(79, 47, 79, 54): 'self.UX', (79, 56, 79, 63): 'self.UH'}, {}), '(self.UX, self.UH)', True, 'import numpy as np\n'), ((149, 19, 149, 29), 'numpy.sqrt', 'np.sqrt', ({(149, 27, 149, 28): '(2)'}, {}), '(2)', True, 'import numpy as np\n'), ((160, 35, 160, 51), 'numpy.exp', 'np.exp', ({(160, 42, 160, 50): '1.0j * lam'}, {}), '(1.0j * lam)', True, 'import numpy as np\n'), ((169, 34, 169, 49), 'numpy.diag', 'np.diag', ({(169, 42, 169, 48): '[1, 0]'}, {}), '([1, 0])', True, 'import numpy as np\n'), ((170, 21, 170, 36), 'numpy.diag', 'np.diag', ({(170, 29, 170, 35): '[0, 1]'}, {}), '([0, 1])', True, 'import numpy as np\n'), ((185, 14, 185, 21), 'qiskit.extensions.standard.HGate', 'HGate', ({}, {}), '()', False, 'from qiskit.extensions.standard import HGate, CHGate, CXGate\n'), ((186, 30, 186, 45), 'numpy.diag', 'np.diag', ({(186, 38, 186, 44): '[0, 1]'}, {}), '([0, 1])', True, 'import numpy as np\n'), ((187, 12, 187, 21), 'numpy.eye', 'np.eye', ({(187, 19, 187, 20): '(2)'}, {}), '(2)', True, 'import numpy as np\n'), ((187, 23, 187, 38), 'numpy.diag', 'np.diag', ({(187, 31, 187, 37): '[1, 0]'}, {}), '([1, 0])', True, 'import numpy as np\n'), ((199, 34, 199, 62), 'numpy.array', 'np.array', (), '', True, 'import numpy as np\n'), ((214, 25, 214, 38), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(214, 34, 214, 37): 'mat'}, {}), '(mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((215, 25, 215, 71), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', (), '', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((216, 25, 216, 77), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', (), '', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((310, 35, 310, 44), 'numpy.eye', 'np.eye', ({(310, 42, 310, 43): '(3)'}, {}), '(3)', True, 'import numpy as np\n'), ((343, 15, 343, 32), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(343, 24, 343, 31): 'self.UY'}, {}), '(self.UY)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((347, 15, 347, 32), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(347, 24, 347, 31): 'self.UX'}, {}), '(self.UX)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((361, 38, 361, 59), 'numpy.kron', 'np.kron', ({(361, 46, 361, 51): 'mat_b', (361, 53, 361, 58): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((364, 37, 364, 58), 'numpy.kron', 'np.kron', ({(364, 45, 364, 50): 'mat_b', (364, 52, 364, 57): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((369, 37, 369, 58), 'numpy.kron', 'np.kron', ({(369, 45, 369, 50): 'mat_b', (369, 52, 369, 57): 'mat_c'}, {}), '(mat_b, mat_c)', True, 'import numpy as np\n'), ((374, 30, 374, 39), 'numpy.eye', 'np.eye', ({(374, 37, 374, 38): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((374, 41, 374, 62), 'numpy.kron', 'np.kron', ({(374, 49, 374, 54): 'mat_b', (374, 56, 374, 61): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((383, 30, 383, 39), 'numpy.eye', 'np.eye', ({(383, 37, 383, 38): '4'}, {}), '(4)', True, 'import numpy as np\n'), ((387, 30, 387, 39), 'numpy.eye', 'np.eye', ({(387, 37, 387, 38): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((391, 37, 391, 46), 'numpy.eye', 'np.eye', ({(391, 44, 391, 45): '4'}, {}), '(4)', True, 'import numpy as np\n'), ((405, 38, 405, 59), 'numpy.kron', 'np.kron', ({(405, 46, 405, 51): 'mat_b', (405, 53, 405, 58): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((408, 42, 408, 63), 'numpy.kron', 'np.kron', ({(408, 50, 408, 55): 'mat_b', (408, 57, 408, 62): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((412, 42, 412, 63), 'numpy.kron', 'np.kron', ({(412, 50, 412, 55): 'mat_b', (412, 57, 412, 62): 'mat_c'}, {}), '(mat_b, mat_c)', True, 'import numpy as np\n'), ((417, 35, 417, 44), 'numpy.eye', 'np.eye', ({(417, 42, 417, 43): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((417, 46, 417, 67), 'numpy.kron', 'np.kron', ({(417, 54, 417, 59): 'mat_b', (417, 61, 417, 66): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((426, 35, 426, 44), 'numpy.eye', 'np.eye', ({(426, 42, 426, 43): '4'}, {}), '(4)', True, 'import numpy as np\n'), ((430, 35, 430, 44), 'numpy.eye', 'np.eye', ({(430, 42, 430, 43): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((434, 42, 434, 51), 'numpy.eye', 'np.eye', ({(434, 49, 434, 50): '4'}, {}), '(4)', True, 'import numpy as np\n'), ((448, 38, 448, 59), 'numpy.kron', 'np.kron', ({(448, 46, 448, 51): 'mat_b', (448, 53, 448, 58): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((451, 42, 451, 63), 'numpy.kron', 'np.kron', ({(451, 50, 451, 55): 'mat_b', (451, 57, 451, 62): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((454, 42, 454, 63), 'numpy.kron', 'np.kron', ({(454, 50, 454, 55): 'mat_b', (454, 57, 454, 62): 'mat_c'}, {}), '(mat_b, mat_c)', True, 'import numpy as np\n'), ((458, 35, 458, 44), 'numpy.eye', 'np.eye', ({(458, 42, 458, 43): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((458, 46, 458, 67), 'numpy.kron', 'np.kron', ({(458, 54, 458, 59): 'mat_b', (458, 61, 458, 66): 'mat_a'}, {}), '(mat_b, mat_a)', True, 'import numpy as np\n'), ((465, 35, 465, 44), 'numpy.eye', 'np.eye', ({(465, 42, 465, 43): '4'}, {}), '(4)', True, 'import numpy as np\n'), ((469, 35, 469, 44), 'numpy.eye', 'np.eye', ({(469, 42, 469, 43): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((473, 42, 473, 51), 'numpy.eye', 'np.eye', ({(473, 49, 473, 50): '4'}, {}), '(4)', True, 'import numpy as np\n'), ((482, 47, 482, 56), 'numpy.eye', 'np.eye', ({(482, 54, 482, 55): '(2)'}, {}), '(2)', True, 'import numpy as np\n'), ((490, 15, 490, 29), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(490, 24, 490, 28): 'mat1'}, {}), '(mat1)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((492, 35, 492, 50), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(492, 44, 492, 49): 'mat21'}, {}), '(mat21)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((495, 15, 495, 29), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(495, 24, 495, 28): 'mat2'}, {}), '(mat2)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((497, 35, 497, 50), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(497, 44, 497, 49): 'mat12'}, {}), '(mat12)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((505, 15, 505, 29), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(505, 24, 505, 28): 'mat2'}, {}), '(mat2)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((507, 35, 507, 50), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(507, 44, 507, 49): 'mat21'}, {}), '(mat21)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((510, 15, 510, 29), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(510, 24, 510, 28): 'mat1'}, {}), '(mat1)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((512, 35, 512, 50), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(512, 44, 512, 49): 'mat12'}, {}), '(mat12)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((560, 26, 560, 48), 'numpy.exp', 'np.exp', ({(560, 33, 560, 47): '1.0j * np.pi / 2'}, {}), '(1.0j * np.pi / 2)', True, 'import numpy as np\n'), ((564, 33, 564, 54), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(564, 42, 564, 53): '(phase * mat)'}, {}), '(phase * mat)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((271, 42, 271, 68), 'numpy.array', 'np.array', ({(271, 51, 271, 67): '[[0, 1], [1, 0]]'}, {}), '([[0, 1], [1, 0]])', True, 'import numpy as np\n'), ((272, 24, 272, 37), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(272, 33, 272, 36): 'X90'}, {}), '(X90)', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((274, 25, 274, 51), 'qiskit.quantum_info.operators.operator.Operator', 'Operator', ({(274, 34, 274, 50): '[[1, 0], [0, 0]]'}, {}), '([[1, 0], [0, 0]])', False, 'from qiskit.quantum_info.operators.operator import Operator\n'), ((309, 35, 309, 44), 'numpy.eye', 'np.eye', ({(309, 42, 309, 43): '(2)'}, {}), '(2)', True, 'import numpy as np\n'), ((311, 48, 311, 57), 'numpy.eye', 'np.eye', ({(311, 55, 311, 56): '(2)'}, {}), '(2)', True, 'import numpy as np\n'), ((378, 45, 378, 54), 'numpy.eye', 'np.eye', ({(378, 52, 378, 53): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((387, 56, 387, 65), 'numpy.eye', 'np.eye', ({(387, 63, 387, 64): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((421, 50, 421, 59), 'numpy.eye', 'np.eye', ({(421, 57, 421, 58): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((430, 61, 430, 70), 'numpy.eye', 'np.eye', ({(430, 68, 430, 69): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((461, 50, 461, 59), 'numpy.eye', 'np.eye', ({(461, 57, 461, 58): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((469, 61, 469, 70), 'numpy.eye', 'np.eye', ({(469, 68, 469, 69): '2'}, {}), '(2)', True, 'import numpy as np\n'), ((478, 42, 478, 68), 'numpy.array', 'np.array', ({(478, 51, 478, 67): '[[0, 1], [1, 0]]'}, {}), '([[0, 1], [1, 0]])', True, 'import numpy as np\n'), ((481, 52, 481, 61), 'numpy.eye', 'np.eye', ({(481, 59, 481, 60): '(2)'}, {}), '(2)', True, 'import numpy as np\n')]