diff --git a/test/embedding/test_ae_feature_map.py b/test/embedding/test_ae_feature_map.py index 21010d5..b68b66e 100644 --- a/test/embedding/test_ae_feature_map.py +++ b/test/embedding/test_ae_feature_map.py @@ -41,7 +41,7 @@ def test_rnd_state(self): state = Statevector(circuit) - self.assertTrue(np.allclose(state_vector, state)) + self.assertTrue(np.allclose(state_vector, state, rtol=1e-03, atol=1e-05)) def test_non_normalized_state(self): # This test is important because during NQE training @@ -61,7 +61,7 @@ def test_non_normalized_state(self): state = Statevector(circuit) state_vector = state_vector / np.linalg.norm(state_vector) - self.assertTrue(np.allclose(state_vector, state)) + self.assertTrue(np.allclose(state_vector, state, rtol=1e-03, atol=1e-05)) def test_sparse_state(self): # Ensure that embedding is preventing division by zero. @@ -80,4 +80,36 @@ def test_sparse_state(self): state = Statevector(circuit) state_vector = state_vector / np.linalg.norm(state_vector) - self.assertTrue(np.allclose(state_vector, state)) + self.assertTrue(np.allclose(state_vector, state, rtol=1e-03, atol=1e-05)) + + def test_fixed_state(self): + n_qubits = 6 + state_vector = [-0.00750879, -0.19509541, 0.13329143, -0.05016399, + 0.15207381, 0.07559872, 0.06584141, 0.02580133, + 0.07838591, 0.1797185, -0.08671011, 0.12130839, + -0.01520751, -0.16350927, -0.14340019, 0.06187, + -0.15696974, -0.07004782, -0.10200592, -0.13275576, + 0.03975269, -0.06866376, -0.19666519, -0.19759358, + -0.06338929, 0.01957956, -0.04101603, -0.17654797, + 0.13379771, 0.13126602, -0.06316672, -0.16629322, + 0.19740418, -0.01161936, 0.00660316, 0.18850766, + 0.05001657, 0.05713368, -0.10440029, -0.19293127, + -0.21320381, -0.15065956, 0.20290586, -0.03929146, + 0.0254895, 0.03343766, -0.17821551, -0.1903655, + 0.13099242, -0.11116633, 0.15833651, -0.02708352, + -0.03610143, 0.20473973, 0.03146476, -0.03039286, + -0.14796486, 0.00971746, -0.15238775, 0.12996466, + -0.19630254, -0.08859373, -0.12830557, 0.12446281] + +# state_vector = state_vector / np.linalg.norm(state_vector) + + feature_map = AeFeatureMap(n_qubits, normalize=False, set_global_phase=True) + + circuit = QuantumCircuit(n_qubits) + circuit.compose(feature_map, list(range(n_qubits)), inplace=True) + circuit.assign_parameters(state_vector, inplace=True) + + state = Statevector(circuit) + + state_vector = state_vector / np.linalg.norm(state_vector) + self.assertTrue(np.allclose(state_vector, state, rtol=1e-03, atol=1e-05))