Skip to content

Commit f3fd72f

Browse files
authored
Merge pull request #279 from kevinsung/xxyy
Add XXPLUSYY and XXMINUSYY gates
2 parents 37fa2cb + f575918 commit f3fd72f

File tree

4 files changed

+67196
-281
lines changed

4 files changed

+67196
-281
lines changed

docs/tensor-circuit.ipynb

+67,102-281
Large diffs are not rendered by default.

quimb/tensor/circuit.py

+90
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,68 @@ def givens2_param_gen(params):
845845
register_param_gate("GIVENS2", givens2_param_gen, num_qubits=2)
846846

847847

848+
def xx_plus_yy_param_gen(params):
849+
theta, beta = params[0], params[1]
850+
851+
with backend_like(theta):
852+
# get a real backend zero
853+
zero = 0.0 * theta
854+
half_theta = 0.5 * theta
855+
856+
a = do("complex", do("cos", half_theta), zero)
857+
b = do("exp", do("complex", zero, beta)) * do(
858+
"complex", do("sin", half_theta), zero
859+
)
860+
b_conj = do("exp", do("complex", zero, -beta)) * do(
861+
"complex", do("sin", half_theta), zero
862+
)
863+
864+
# get a complex backend zero and backend one
865+
zero = do("complex", zero, zero)
866+
one = zero + 1.0
867+
868+
data = (
869+
(((one, zero), (zero, zero)), ((zero, a), (-1j * b, zero))),
870+
(((zero, -1j * b_conj), (a, zero)), ((zero, zero), (zero, one))),
871+
)
872+
873+
return recursive_stack(data)
874+
875+
876+
register_param_gate("XXPLUSYY", xx_plus_yy_param_gen, num_qubits=2)
877+
878+
879+
def xx_minus_yy_param_gen(params):
880+
theta, beta = params[0], params[1]
881+
882+
with backend_like(theta):
883+
# get a real backend zero
884+
zero = 0.0 * theta
885+
half_theta = 0.5 * theta
886+
887+
a = do("complex", do("cos", half_theta), zero)
888+
b = do("exp", do("complex", zero, beta)) * do(
889+
"complex", do("sin", half_theta), zero
890+
)
891+
b_conj = do("exp", do("complex", zero, -beta)) * do(
892+
"complex", do("sin", half_theta), zero
893+
)
894+
895+
# get a complex backend zero and backend one
896+
zero = do("complex", zero, zero)
897+
one = zero + 1.0
898+
899+
data = (
900+
(((a, zero), (zero, -1j * b_conj)), ((zero, one), (zero, zero))),
901+
(((zero, zero), (one, zero)), ((-1j * b, zero), (zero, a))),
902+
)
903+
904+
return recursive_stack(data)
905+
906+
907+
register_param_gate("XXMINUSYY", xx_minus_yy_param_gen, num_qubits=2)
908+
909+
848910
def rxx_param_gen(params):
849911
r"""Parametrized two qubit XX-rotation.
850912
@@ -2300,6 +2362,34 @@ def givens2(
23002362
**kwargs,
23012363
)
23022364

2365+
def xx_plus_yy(
2366+
self, theta, beta, i, j, gate_round=None, parametrize=False, **kwargs
2367+
):
2368+
self.apply_gate(
2369+
"XXPLUSYY",
2370+
theta,
2371+
beta,
2372+
i,
2373+
j,
2374+
gate_round=gate_round,
2375+
parametrize=parametrize,
2376+
**kwargs,
2377+
)
2378+
2379+
def xx_minus_yy(
2380+
self, theta, beta, i, j, gate_round=None, parametrize=False, **kwargs
2381+
):
2382+
self.apply_gate(
2383+
"XXMINUSYY",
2384+
theta,
2385+
beta,
2386+
i,
2387+
j,
2388+
gate_round=gate_round,
2389+
parametrize=parametrize,
2390+
**kwargs,
2391+
)
2392+
23032393
def rxx(self, theta, i, j, gate_round=None, parametrize=False, **kwargs):
23042394
self.apply_gate(
23052395
"RXX",

tests/test_tensor/test_circuit.py

+2
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ def test_all_gate_methods(self, Circ):
277277
("fsimg", 2, 5),
278278
("givens", 2, 1),
279279
("givens2", 2, 2),
280+
("xx_plus_yy", 2, 2),
281+
("xx_minus_yy", 2, 2),
280282
("su4", 2, 15),
281283
]
282284
random.shuffle(g_nq_np)

tests/test_tensor/test_optimizers.py

+2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ def test_every_parametrized_gate(backend):
249249
circ.fsimg(*qu.randn(5), 1, 0, parametrize=True, tags=["OPTIMIZE"])
250250
circ.givens(*qu.randn(1), 0, 1, parametrize=True, tags=["OPTIMIZE"])
251251
circ.givens2(*qu.randn(2), 0, 1, parametrize=True, tags=["OPTIMIZE"])
252+
circ.xx_plus_yy(*qu.randn(2), 0, 1, parametrize=True, tags=["OPTIMIZE"])
253+
circ.xx_minus_yy(*qu.randn(2), 0, 1, parametrize=True, tags=["OPTIMIZE"])
252254
circ.su4(*qu.randn(15), 0, 1, parametrize=True, tags=["OPTIMIZE"])
253255
psi = circ.psi
254256

0 commit comments

Comments
 (0)