pyquil
pyquil copied to clipboard
Typing on exponential_map return value is incorrect
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
The signature of exponential_map
is:
def exponential_map(term: PauliTerm) -> Callable[[float], Program]:
But at least MemoryReference
can also be provided on the second chained invocation.
This requires "noqa" to silence type checks on circuit-parameterized invocations of this method.
Suggest the signature be changed to at least:
def exponential_map(term: PauliTerm) -> Callable[[Union[float, MemoryReference]], Program]:
How to Reproduce
This is not a run-time bug. I'm observing type check warning highlighting in PyCharm. I'm assuming running eg. mypy
would output the following error:
Expected type 'float', got 'MemoryReference' instead
Environment Context
IDE: Jetbrains PyCharm 2020.2
Hey, Mark. Would you provide a MWE that triggers the mypy warning?
Hi @notmgsk - so I just checked and my assumption about mypy was wrong. It seems PyCharm has its own native implementation of the relevant PEPs pertaining to type checking and does this inside the IDE. You will have to install PyCharm community edition and have it point at an environment with pyquil installed to see the issue.
The MWE is then:
from pyquil import Program
from pyquil.paulis import PauliSum, sZ, exponential_map
cost_hamiltonian = PauliSum([sZ(0) * sZ(1)])
program = Program()
gammas = program.declare("gammas", "REAL", 1)
program.inst(exponential_map(term)(gammas[0]) for term in cost_hamiltonian)
Here, gammas[0]
will be highlighted as an error, as per the above.