Skip to content

Commit

Permalink
test call graph
Browse files Browse the repository at this point in the history
  • Loading branch information
anurudhp committed Mar 28, 2024
1 parent 95436a9 commit edd3f14
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion qualtran/bloqs/basic_gates/su2_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ def _unitary_(self):

def build_composite_bloq(self, bb: 'BloqBuilder', q: 'SoquetT') -> Dict[str, 'SoquetT']:
pi = sympy.pi if self._is_parameterized_() else np.pi
exp = sympy.exp if self._is_parameterized_() else np.exp

bb.add(GlobalPhase(coefficient=-np.exp(1j * self.global_shift), eps=self.eps / 4))
bb.add(GlobalPhase(coefficient=-exp(1j * self.global_shift), eps=self.eps / 4))
q = bb.add(ZPowGate(exponent=1 - self.lambd / pi, global_shift=-1, eps=self.eps / 4), q=q)
q = bb.add(Ry(angle=2 * self.theta, eps=self.eps / 4), q=q)
q = bb.add(ZPowGate(exponent=-self.phi / pi, global_shift=-1, eps=self.eps / 4), q=q)
Expand Down
26 changes: 25 additions & 1 deletion qualtran/bloqs/basic_gates/su2_rotation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@
# limitations under the License.
import cirq
import numpy as np
import sympy

from qualtran import Bloq
from qualtran.bloqs.basic_gates import Hadamard, TGate, XGate, YGate, ZGate
from qualtran.bloqs.basic_gates import (
GlobalPhase,
Hadamard,
Ry,
TGate,
XGate,
YGate,
ZGate,
ZPowGate,
)
from qualtran.cirq_interop import BloqAsCirqGate
from qualtran.cirq_interop.testing import assert_decompose_is_consistent_with_t_complexity

Expand Down Expand Up @@ -80,3 +90,17 @@ def test_from_matrix_on_standard_gates():
np.testing.assert_allclose(
SU2RotationGate.from_matrix(mat).rotation_matrix, mat, atol=1e-15
)


def test_call_graph():
theta, phi, lambd, alpha, eps = sympy.symbols("theta, phi, lambd, alpha, eps")
pi = sympy.pi

gate = SU2RotationGate(theta, phi, lambd, alpha, eps)
_, sigma = gate.call_graph()
assert sigma == {
GlobalPhase(-sympy.exp(1j * alpha), eps / 4): 1,
ZPowGate(-phi / pi, -1, eps / 4): 1,
ZPowGate(-lambd / pi + 1, -1, eps / 4): 1,
Ry(2 * theta, eps / 4): 1,
}

0 comments on commit edd3f14

Please sign in to comment.