Skip to content

Commit

Permalink
circuit: add givens, fix for 3qb
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed Sep 10, 2023
1 parent f95252e commit 6f24494
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
38 changes: 38 additions & 0 deletions quimb/tensor/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,31 @@ def fsimg_param_gen(params):
register_param_gate("FSIMG", fsimg_param_gen, 2)


def givens_param_gen(params):
theta = params[0]

with backend_like(theta):
# get a real backend zero
zero = 0.0 * theta

a = do("complex", do("cos", theta), zero)
b = do("complex", do("sin", theta), zero)

# get a complex backend zero and backend one
zero = do("complex", zero, zero)
one = zero + 1.0

data = (
(((one, zero), (zero, zero)), ((zero, a), (-b, zero))),
(((zero, b), (a, zero)), ((zero, zero), (zero, one))),
)

return recursive_stack(data)


register_param_gate("GIVENS", givens_param_gen, num_qubits=2)


def rxx_param_gen(params):
r"""Parametrized two qubit XX-rotation.
Expand Down Expand Up @@ -1394,6 +1419,19 @@ def fsimg(
**kwargs,
)

def givens(
self, theta, i, j, gate_round=None, parametrize=False, **kwargs
):
self.apply_gate(
"GIVENS",
theta,
i,
j,
gate_round=gate_round,
parametrize=parametrize,
**kwargs,
)

def rxx(self, theta, i, j, gate_round=None, parametrize=False, **kwargs):
self.apply_gate(
"RXX",
Expand Down
6 changes: 5 additions & 1 deletion quimb/tensor/tensor_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3493,8 +3493,12 @@ def tensor_network_gate_inds(
f"indices {inds} with dimensions {dims}.")

basic = (contract in _BASIC_GATE_CONTRACT)
if (not basic) and (ng == 1):
if (
# if single ind, gate splitting methods are same as lazy
((not basic) and (ng == 1)) or
# or for 3+ sites, treat auto as no splitting
((contract == "auto-split-gate") and (ng > 2))
):
basic = True
contract = False

Expand Down
1 change: 1 addition & 0 deletions tests/test_tensor/test_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def test_every_parametrized_gate(backend):
circ.cu3(*qu.randn(3), 1, 0, parametrize=True, tags=['OPTIMIZE'])
circ.fsim(*qu.randn(2), 0, 1, parametrize=True, tags=['OPTIMIZE'])
circ.fsimg(*qu.randn(5), 1, 0, parametrize=True, tags=['OPTIMIZE'])
circ.givens(*qu.randn(1), 0, 1, parametrize=True, tags=['OPTIMIZE'])
circ.su4(*qu.randn(15), 0, 1, parametrize=True, tags=['OPTIMIZE'])
psi = circ.psi

Expand Down

0 comments on commit 6f24494

Please sign in to comment.