Skip to content

Commit

Permalink
test(tensorflow): Fix interferometer gradient test
Browse files Browse the repository at this point in the history
`tf.exp` was applied to a matrix, but it is an element-wise exponential
instead of a matrix exponential, hence the resulting matrix was not
unitary.
  • Loading branch information
VHenrik007 committed Mar 7, 2023
1 parent 8bd3b17 commit c23a9d6
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions tests/backends/tensorflow/test_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ def test_Interferometer_fock_probabilities():
)

j = tf.complex(0.0, 1.0)
interferometer = tf.exp(j * hamiltonian)

interferometer = tf.linalg.expm(j * hamiltonian)
with pq.Program() as program:
pq.Q(all) | pq.StateVector((1, 0)) / np.sqrt(2)
pq.Q(all) | pq.StateVector((1, 1)) / np.sqrt(2)
Expand All @@ -365,11 +364,11 @@ def test_Interferometer_fock_probabilities():
jacobian,
[
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, -0.42073548, -0.5950098, -0.90929735, -0.5950098],
[0.0, -0.42073548, 0.0, 0.0, -0.84147096, 0.0],
[0.0, -0.5950098, 0.0, 0.0, -1.1900196, 0.0],
[0.0, -0.90929735, -0.84147096, -1.1900196, -1.8185948, -1.1900196],
[0.0, -0.5950098, 0.0, 0.0, -1.1900196, 0.0],
[0.0, -0.4546487, 0.0, 0.0, -0.3162077, 0.0],
[0.0, 0.0, 0.4546488, -0.07391234, 0.0, -0.07391226],
[0.0, 0.0, -0.07391234, -0.3784013, 0.0, -0.3784013],
[0.0, -0.3162077, 0.0, 0.0, 0.75680256, 0.0],
[0.0, 0.0, -0.07391226, -0.3784013, 0.0, -0.37840137],
],
)

Expand Down

0 comments on commit c23a9d6

Please sign in to comment.