Skip to content

Commit 5ce7d21

Browse files
add tests for adjoint
1 parent 0dbbee8 commit 5ce7d21

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test_circuit.py

+19
Original file line numberDiff line numberDiff line change
@@ -1515,3 +1515,22 @@ def test_get_positional_logical_mapping():
15151515
c.measure_instruction(2)
15161516
c.measure_instruction(0)
15171517
assert c.get_positional_logical_mapping() == {0: 2, 1: 0}
1518+
1519+
@pytest.mark.parametrize("backend", [lf("tfb"), lf("jaxb")])
1520+
def test_inverse_jit(backend):
1521+
K = tc.backend
1522+
def simple_ansatz(param):
1523+
c = tc.Circuit(3)
1524+
for i in range(3):
1525+
c.cx(i, (i+1)%3)
1526+
c.rzz(i, (i+1)%3, theta=param[i])
1527+
c1 = c.inverse()
1528+
c2 = tc.Circuit(3)
1529+
c2.x(1)
1530+
c1.append(c2)
1531+
return tc.backend.real(c1.expectation_ps(z=[1]))
1532+
1533+
v_ansatz = K.jit(K.vvag(simple_ansatz))
1534+
vs, gs = v_ansatz(K.ones([2, 3], dtype="float32"))
1535+
assert K.shape_tuple(gs) == (2, 3)
1536+
np.testing.assert_allclose(K.numpy(vs), -1.*K.ones([2]), atol=1e-5)

0 commit comments

Comments
 (0)