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

DefGate construction fails if matrix contains Expressions but not parameters #1682

Closed
steve-jeffrey opened this issue Oct 20, 2023 · 0 comments · Fixed by #1757
Closed

DefGate construction fails if matrix contains Expressions but not parameters #1682

steve-jeffrey opened this issue Oct 20, 2023 · 0 comments · Fixed by #1757
Labels
bug 🐛 An issue that needs fixing. urgent Priority assistance requested

Comments

@steve-jeffrey
Copy link

Pre-Report Checklist

  • [ X] I am running the latest versions of pyQuil and the Forest SDK
  • [ X] I checked to make sure that this bug has not already been reported

Issue Description

When a DefGate without parameters is constructed, the user-specified matrix is numerically checked to determine if it is unitary.

If the matrix contains Expressions having only numeric arguments (i.e. no Parameters), the numeric check will be run and subsequently fail due to the presence of the non-numeric Expressions.

Code Snippet

import numpy as np
from pyquil.quilatom import quil_sin
from pyquil.quilbase import DefGate

unitary = np.array(
    [
        [quil_sin(1.23), 0],
        [0, 0],
    ]
)

gate_def = DefGate("MY_GATE", unitary)

Error Output

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    gate_def = DefGate("MY_GATE", unitary)
  File "...site-packages/pyquil/quilbase.py", line 437, in __init__
    is_unitary = np.allclose(np.eye(rows), self.matrix.dot(self.matrix.T.conj()))
TypeError: loop of ufunc does not support argument 0 of type Function which has no callable conjugate method

Environment Context

pyQuil: 4.0.3 (issue also occurs under 3.5.4)

Operating System: Fedora 38

Python Version (python -V): 3.9.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue that needs fixing. urgent Priority assistance requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants