-
Notifications
You must be signed in to change notification settings - Fork 342
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 broken in the NumpyWavefunctionSimulator #1059
Comments
Hi, thanks for reporting this. I am not super familiar with the
from pyquil import get_qc
qc = get_qc('2q-pyqvm')
ro = p.declare('ro', 'BIT', 1)
p += MEASURE(1, ro[0])
compiled_program = qc.compile(p)
results = qc.run(compiled_program)
|
Ah, that's good to know!
I should clarify, that the reason I noticed this was that non-parametrized |
For example, using theta = 0.543
U = np.array([
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, np.cos(theta / 2), -1j * np.sin(theta / 2)],
[0, 0, -1j * np.sin(theta / 2), np.cos(theta / 2)]
])
gate_definition = DefGate('U_test', U)
U_test = gate_definition.get_constructor() I get the same error as above in the latest PyQuil PyQVM, but it works fine in 2.10. |
I see. Yes, looking at the git history, the behavior of Full example calling import numpy as np
from pyquil import Program
from pyquil.quilbase import DefGate
from pyquil.numpy_simulator import NumpyWavefunctionSimulator
from pyquil.pyqvm import PyQVM
theta = 0.543
U = np.array([
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, np.cos(theta / 2), -1j * np.sin(theta / 2)],
[0, 0, -1j * np.sin(theta / 2), np.cos(theta / 2)]
])
gate_definition = DefGate('U_test', U)
U_test = gate_definition.get_constructor()
p = Program()
p += gate_definition
p += U_test(0, 1)
ro = p.declare('ro', 'BIT', 2)
p += MEASURE(0, ro[0])
p += MEASURE(1, ro[1])
qam = PyQVM(n_qubits=2, quantum_simulator_type=NumpyWavefunctionSimulator)
qam.load(p)
qam.run()
qam.read_memory(region_name="ro") Or via the from pyquil import get_qc
qc = get_qc('2q-pyqvm')
p = Program()
p += gate_definition
p += U_test(0, 1)
qc.run_and_measure(p, trials=1) |
In #874, PyQVM was changed to remove the restriction for run-and-measure style programs. In the process, PyQVM.execute lost the ability to execute programs with user defined gates, which apparently broke pennylane-forest's PyQVM support. This commit re-instates the block of code for extracting defined_gates from the Program passed to PyQVM.execute, and with it the ability to execute Programs with (non-parametric) defgates. Fixes #1059 See also: PennyLaneAI/pennylane-rigetti#22
In #874, PyQVM was changed to remove the restriction for run-and-measure style programs. In the process, PyQVM.execute lost the ability to execute programs with user defined gates, which apparently broke pennylane-forest's PyQVM support. This commit reinstates the block of code for extracting defined_gates from the Program passed to PyQVM.execute, and with it the ability to execute Programs with (non-parametric) defgates. Fixes #1059 See also: PennyLaneAI/pennylane-rigetti#22
Issue Description
DefGate
seems to be broken inNumpyWavefunctionSimulator
.How to Reproduce
Code Snippet
Use any custom gate definition. Here I just copied from http://docs.rigetti.com/en/stable/basics.html#defining-parametric-gates.
Error Output
Environment Context
Operating System: Ubuntu 18.04.1
Python Version (
python -V
): 3.6.8Quilc Version (
quilc --version
): latest rigetti/qvm docker imageQVM Version (
qvm --version
): latest rigetti/quilc docker imagePython Environment Details (
pip freeze
orconda list
):The text was updated successfully, but these errors were encountered: