Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add givens2 gate #253

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion quimb/tensor/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from ..utils import progbar as _progbar
from . import array_ops as ops
from .tensor_1d import Dense1D, MatrixProductOperator
from .tensor_arbgeom import TensorNetworkGenVector, TensorNetworkGenOperator
from .tensor_arbgeom import TensorNetworkGenOperator, TensorNetworkGenVector
from .tensor_builder import (
HTN_CP_operator_from_products,
MPO_identity_like,
Expand Down Expand Up @@ -809,6 +809,36 @@
register_param_gate("GIVENS", givens_param_gen, num_qubits=2)


def givens2_param_gen(params):
theta, phi = params[0], params[1]

Check warning on line 813 in quimb/tensor/circuit.py

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/circuit.py#L813

Added line #L813 was not covered by tests

with backend_like(theta):

Check warning on line 815 in quimb/tensor/circuit.py

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/circuit.py#L815

Added line #L815 was not covered by tests
# get a real backend zero
zero = 0.0 * theta

Check warning on line 817 in quimb/tensor/circuit.py

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/circuit.py#L817

Added line #L817 was not covered by tests

a = do("complex", do("cos", theta), zero)
b = do("exp", do("complex", zero, phi)) * do(

Check warning on line 820 in quimb/tensor/circuit.py

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/circuit.py#L819-L820

Added lines #L819 - L820 were not covered by tests
"complex", do("sin", theta), zero
)
b_conj = do("exp", do("complex", zero, -phi)) * do(

Check warning on line 823 in quimb/tensor/circuit.py

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/circuit.py#L823

Added line #L823 was not covered by tests
"complex", do("sin", theta), zero
)

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

Check warning on line 829 in quimb/tensor/circuit.py

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/circuit.py#L828-L829

Added lines #L828 - L829 were not covered by tests

data = (

Check warning on line 831 in quimb/tensor/circuit.py

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/circuit.py#L831

Added line #L831 was not covered by tests
(((one, zero), (zero, zero)), ((zero, a), (-b, zero))),
(((zero, b_conj), (a, zero)), ((zero, zero), (zero, one))),
)

return recursive_stack(data)

Check warning on line 836 in quimb/tensor/circuit.py

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/circuit.py#L836

Added line #L836 was not covered by tests


register_param_gate("GIVENS2", givens2_param_gen, num_qubits=2)


def rxx_param_gen(params):
r"""Parametrized two qubit XX-rotation.

Expand Down Expand Up @@ -2167,6 +2197,20 @@
**kwargs,
)

def givens2(
self, theta, phi, i, j, gate_round=None, parametrize=False, **kwargs
):
self.apply_gate(

Check warning on line 2203 in quimb/tensor/circuit.py

View check run for this annotation

Codecov / codecov/patch

quimb/tensor/circuit.py#L2203

Added line #L2203 was not covered by tests
"GIVENS2",
theta,
phi,
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
3 changes: 2 additions & 1 deletion tests/test_tensor/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ def test_all_gate_methods(self, Circ):
("cu1", 2, 1),
("fsim", 2, 2),
("fsimg", 2, 5),
("rzz", 2, 1),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rzz is already tested above

("givens", 2, 1),
("givens2", 2, 2),
("su4", 2, 15),
]
random.shuffle(g_nq_np)
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 @@ -242,6 +242,7 @@ def test_every_parametrized_gate(backend):
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.givens2(*qu.randn(2), 0, 1, parametrize=True, tags=["OPTIMIZE"])
circ.su4(*qu.randn(15), 0, 1, parametrize=True, tags=["OPTIMIZE"])
psi = circ.psi

Expand Down
Loading