Skip to content

Commit

Permalink
New test test_fixed_state
Browse files Browse the repository at this point in the history
  • Loading branch information
israelferrazaraujo committed Dec 6, 2023
1 parent efde78f commit 40d8fe9
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions test/embedding/test_ae_feature_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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))

0 comments on commit 40d8fe9

Please sign in to comment.