File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -1515,3 +1515,22 @@ def test_get_positional_logical_mapping():
1515
1515
c .measure_instruction (2 )
1516
1516
c .measure_instruction (0 )
1517
1517
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 )
You can’t perform that action at this time.
0 commit comments