def test_angle_encoding1(self): """ n_qubits """ ae = encode.AngleEncoding() x = np.arange(10) n_qubits = ae.n_qubits(x) self.assertEqual(10, n_qubits, 'Error in n_qubits')
def test_combine2(self): x = np.array([0.75, 0, 0.25, 0]) encoder = encode.AngleEncoding() model = EntangledQubit() full_circuit = combine(x, encoder, model) print(full_circuit) self.assertTrue(isinstance(full_circuit, qiskit.QuantumCircuit))
def test_angle_encoding2(self): """ Default arguments """ ae = encode.AngleEncoding() x = np.random.random(4) psi = ae.state_vector(x) circuit = ae.circuit(x) circuit_psi = get_state_vector(circuit) is_equal = np.allclose(psi, circuit_psi) self.assertTrue(is_equal)
def test_angle_encoding3(self): """ Testing scaling factor""" random_scaling = np.random.uniform(0, np.pi) ae = encode.AngleEncoding(scaling=random_scaling) x = np.random.random(4) psi = ae.state_vector(x) circuit = ae.circuit(x) circuit_psi = get_state_vector(circuit) is_equal = np.allclose(psi, circuit_psi) self.assertTrue(is_equal)
def test_angle_encoding4(self): """ Testing different gates """ #gate_set = [Gate.RX, Gate.RZ, Gate.U1] # RZ has no .to_matrix() ??? gate_set = [Gate.RX, Gate.U1] ae = encode.AngleEncoding() x = np.random.random(4) is_equal_list = [] for gate in gate_set: ae.gate = gate psi = ae.state_vector(x) circuit = ae.circuit(x) circuit_psi = get_state_vector(circuit) is_equal_list.append(np.allclose(psi, circuit_psi)) self.assertTrue(is_equal_list)