def test_big_gates(self): """Test large gates with params""" qr = QuantumRegister(6, "q") circuit = QuantumCircuit(qr) circuit.append(IQP([[6, 5, 3], [5, 4, 5], [3, 5, 1]]), [0, 1, 2]) desired_vector = [ 1 / math.sqrt(16) * complex(0, 1), 1 / math.sqrt(8) * complex(1, 0), 1 / math.sqrt(16) * complex(1, 1), 0, 0, 1 / math.sqrt(8) * complex(1, 2), 1 / math.sqrt(16) * complex(1, 0), 0, ] circuit.initialize(desired_vector, [qr[3], qr[4], qr[5]]) circuit.unitary([[1, 0], [0, 1]], [qr[0]]) matrix = np.zeros((4, 4)) theta = Parameter("theta") circuit.append(HamiltonianGate(matrix, theta), [qr[1], qr[2]]) circuit = circuit.bind_parameters({theta: 1}) circuit.isometry(np.eye(4, 4), list(range(3, 5)), []) self.circuit_drawer(circuit, filename="big_gates.png")
def test_big_gates(self): """Test large gates with params""" filename = self._get_resource_path('test_latex_big_gates.tex') qr = QuantumRegister(6, 'q') circuit = QuantumCircuit(qr) circuit.append(IQP([[6, 5, 3], [5, 4, 5], [3, 5, 1]]), [0, 1, 2]) desired_vector = [ 1 / math.sqrt(16) * complex(0, 1), 1 / math.sqrt(8) * complex(1, 0), 1 / math.sqrt(16) * complex(1, 1), 0, 0, 1 / math.sqrt(8) * complex(1, 2), 1 / math.sqrt(16) * complex(1, 0), 0] circuit.initialize(desired_vector, [qr[3], qr[4], qr[5]]) circuit.unitary([[1, 0], [0, 1]], [qr[0]]) matrix = np.zeros((4, 4)) theta = Parameter('theta') circuit.append(HamiltonianGate(matrix, theta), [qr[1], qr[2]]) circuit = circuit.bind_parameters({theta: 1}) circuit.isometry(np.eye(4, 4), list(range(3, 5)), []) circuit_drawer(circuit, filename=filename, output='latex_source') self.assertEqualToReference(filename)
def test_iqp(self): """Test iqp circuit.""" circuit = IQP(interactions=np.array([[6, 5, 1], [5, 4, 3], [1, 3, 2]])) expected = QuantumCircuit(3) expected.h([0, 1, 2]) expected.cp(5 * np.pi / 2, 0, 1) expected.cp(3 * np.pi / 2, 1, 2) expected.cp(1 * np.pi / 2, 0, 2) expected.p(6 * np.pi / 8, 0) expected.p(4 * np.pi / 8, 1) expected.p(2 * np.pi / 8, 2) expected.h([0, 1, 2]) expected = Operator(expected) simulated = Operator(circuit) self.assertTrue(expected.equiv(simulated))
def test_iqp(self): """Test iqp circuit.""" circuit = IQP(interactions=np.array([[6, 5, 1], [5, 4, 3], [1, 3, 2]])) # ┌───┐ ┌─────────┐┌───┐ # q_0: ┤ H ├─■───────────────────■───────┤ P(3π/4) ├┤ H ├ # ├───┤ │P(5π/2) │ └┬────────┤├───┤ # q_1: ┤ H ├─■─────────■─────────┼────────┤ P(π/2) ├┤ H ├ # ├───┤ │P(3π/2) │P(π/2) ├────────┤├───┤ # q_2: ┤ H ├───────────■─────────■────────┤ P(π/4) ├┤ H ├ # └───┘ └────────┘└───┘ expected = QuantumCircuit(3) expected.h([0, 1, 2]) expected.cp(5 * np.pi / 2, 0, 1) expected.cp(3 * np.pi / 2, 1, 2) expected.cp(1 * np.pi / 2, 0, 2) expected.p(6 * np.pi / 8, 0) expected.p(4 * np.pi / 8, 1) expected.p(2 * np.pi / 8, 2) expected.h([0, 1, 2]) expected = Operator(expected) simulated = Operator(circuit) self.assertTrue(expected.equiv(simulated))