Skip to content

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

@steve-jeffrey

Description

@steve-jeffrey

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛An issue that needs fixing.urgentPriority assistance requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions