rigetti / rigetti/pyquil

PyQVM does not support parametric DEFGATEs

Open
#1,069 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :bug:
Dominant language
Python
Stars
1.5k
Forks
358
Avg merge
1d 58m
Merged PRs (30d)
4

Description

Pre-Report Checklist

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

Issue Description

PyQVM doesn't support parametric DEFGATEs.

See also:

https://github.com/rigetti/pyquil/issues/803
https://github.com/rigetti/pyquil/issues/906
https://github.com/rigetti/pyquil/issues/1059
https://github.com/rigetti/pyquil/issues/1068

How to Reproduce

The following parametric defgate example of comes from the docs (but swapping a PyQVM for a WavefunctionSimulator):

http://docs.rigetti.com/en/stable/basics.html#defining-parametric-gates

Code Snippet
import numpy as np

from pyquil import Program
from pyquil.quilatom import Parameter, quil_sin, quil_cos
from pyquil.quilbase import DefGate
from pyquil.gates import H
from pyquil.numpy_simulator import NumpyWavefunctionSimulator
from pyquil.pyqvm import PyQVM

# Define the new gate from a matrix
theta = Parameter('theta')
crx = np.array([
    [1, 0, 0, 0],
    [0, 1, 0, 0],
    [0, 0, quil_cos(theta / 2), -1j * quil_sin(theta / 2)],
    [0, 0, -1j * quil_sin(theta / 2), quil_cos(theta / 2)]
])

gate_definition = DefGate('CRX', crx, [theta])
CRX = gate_definition.get_constructor()

# Create our program and use the new parametric gate
p = Program()
p += [gate_definition, CRX(np.pi/2)(0, 1)]
p += H(0)
p += CRX(np.pi/2)(0, 1)

qam = PyQVM(n_qubits=2, quantum_simulator_type=NumpyWavefunctionSimulator)
qam.load(p)
Error Output
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-140-0fcc2eedc00a> in <module>
----> 1 qam.load(p)

~/src/repos/rigetti/pyquil/pyquil/pyqvm.py in load(self, executable)
    210
    211         # grab the gate definitions for future use
--> 212         self._extract_defined_gates()
    213
    214         self.status = 'loaded'

~/src/repos/rigetti/pyquil/pyquil/pyqvm.py in _extract_defined_gates(self)
    219         for dg in self.program.defined_gates:
    220             if dg.parameters is not None and len(dg.parameters) > 0:
--> 221                 raise NotImplementedError("PyQVM does not support parameterized DEFGATEs")
    222             self.defined_gates[dg.name] = dg.matrix
    223

NotImplementedError: PyQVM does not support parameterized DEFGATEs

Environment Context

Operating System: macOS Mojave 10.14.6 (18G103)

Python Version (python -V): Python 3.6.8

Quilc Version (quilc --version): 1.12.1 [2953a23]

QVM Version (qvm --version): 1.12.0 [9b26c1b]

Python Environment Details (pip freeze or conda list):

# packages in environment at /anaconda3/envs/forest:
#
# Name                    Version                   Build  Channel
alabaster                 0.7.12                   py36_0  
antlr4-python3-runtime    4.7.2                    pypi_0    pypi
apipkg                    1.5                      py36_0  
appnope                   0.1.0            py36hf537a9a_0  
asn1crypto                0.24.0                   py36_0  
atomicwrites              1.3.0                    py36_1  
attrs                     19.1.0                   py36_1  
babel                     2.7.0                      py_0  
backcall                  0.1.0                    py36_0  
blas                      1.0                         mkl  
bleach                    3.1.0                    py36_0  
ca-certificates           2019.5.15                     1  
certifi                   2019.6.16                py36_1  
cffi                      1.12.3           py36hb5b8e2f_0  
chardet                   3.0.4                 py36_1003  
coverage                  4.5.3            py36h1de35cc_0  
cryptography              2.7              py36ha12b0ac_0  
cycler                    0.10.0           py36hfc81398_0  
dbus                      1.13.6               h90a0687_0  
decorator                 4.4.0                    py36_1  
defusedxml                0.6.0                      py_0  
docutils                  0.15.2                   py36_0  
entrypoints               0.3                      py36_0  
execnet                   1.6.1                      py_0  
expat                     2.2.6                h0a44026_0  
filelock                  3.0.12                     py_0  
flake8                    3.7.7                    py36_0    conda-forge
freetype                  2.9.1                hb4e5f40_0  
future                    0.17.1                py36_1000    conda-forge
gettext                   0.19.8.1             h15daf44_3  
glib                      2.56.2               hd9629dc_0  
icu                       58.2                 h4b95b61_1  
idna                      2.8                      py36_0  
imagesize                 1.1.0                    py36_0  
immutables                0.6             py36h1de35cc_1000    conda-forge
importlib_metadata        0.19                     py36_0  
intel-openmp              2019.4                      233  
ipykernel                 5.1.1            py36h5ca1d4c_0    conda-forge
ipython                   7.8.0            py36h39e3cac_0  
ipython_genutils          0.2.0            py36h241746c_0  
ipywidgets                7.5.1                      py_0  
jedi                      0.15.1                   py36_0  
jinja2                    2.10.1                   py36_0  
jpeg                      9b                   he5867d9_2  
jsonschema                3.0.2                    py36_0  
jupyter                   1.0.0                    py36_7  
jupyter_client            5.3.1                      py_0  
jupyter_console           6.0.0                    py36_0  
jupyter_core              4.5.0                      py_0  
kiwisolver                1.1.0            py36h0a44026_0  
libcxx                    4.0.1                hcfea43d_1  
libcxxabi                 4.0.1                hcfea43d_1  
libedit                   3.1.20181209         hb402a30_0  
libffi                    3.2.1                h475c297_4  
libgfortran               3.0.1                h93005f0_2  
libiconv                  1.15                 hdd342a3_7  
libpng                    1.6.37               ha441bb4_0  
libsodium                 1.0.17               h01d97ff_0    conda-forge
markupsafe                1.1.1            py36h1de35cc_0  
matplotlib                3.1.1            py36h54f8f79_0  
mccabe                    0.6.1                    py36_1  
mistune                   0.8.4            py36h1de35cc_0  
mkl                       2019.4                      233  
mkl-service               2.3.0            py36hfbe908c_0  
mkl_fft                   1.0.14           py36h5e564d8_0  
mkl_random                1.0.2            py36h27c97d8_0  
more-itertools            7.2.0                    py36_0  
msgpack                   0.6.0                    pypi_0    pypi
nbconvert                 5.5.0                      py_0  
nbformat                  4.4.0            py36h827af21_0  
nbsphinx                  0.4.2                      py_0    conda-forge
ncurses                   6.1                  h0a44026_1  
networkx                  2.3                        py_0  
notebook                  6.0.1                    py36_0  
numpy                     1.16.5           py36hacdab7b_0  
numpy-base                1.16.5           py36h6575580_0  
openssl                   1.1.1d               h1de35cc_1  
packaging                 19.1                     py36_0  
pandas                    0.25.1           py36h0a44026_0  
pandoc                    2.2.3.2                       0  
pandocfilters             1.4.2                    py36_1  
parso                     0.5.1                      py_0  
patsy                     0.5.1                    py36_0  
pcre                      8.43                 h0a44026_0  
pexpect                   4.7.0                    py36_0  
pickleshare               0.7.5                    py36_0  
pip                       19.2.2                   py36_0  
pluggy                    0.12.0                     py_0  
prometheus_client         0.7.1                      py_0  
prompt_toolkit            2.0.9                    py36_0  
ptyprocess                0.6.0                    py36_0  
py                        1.8.0                    py36_0  
pycodestyle               2.5.0                    py36_0  
pycparser                 2.19                     py36_0  
pyflakes                  2.1.1                    py36_0  
pygments                  2.4.2                      py_0  
pyopenssl                 19.0.0                   py36_0  
pyparsing                 2.4.2                      py_0  
pyqt                      5.9.2            py36h655552a_2  
pyquil                    2.12.0                    dev_0    <develop>
pyrsistent                0.14.11          py36h1de35cc_0  
pysocks                   1.7.0                    py36_0  
pytest                    5.0.1                    py36_0    conda-forge
pytest-asyncio            0.10.0                py36_1000    conda-forge
pytest-cov                2.7.1                      py_0    conda-forge
pytest-forked             1.0.2                    py36_0  
pytest-rerunfailures      7.0                      pypi_0    pypi
pytest-timeout            1.3.3                      py_0    conda-forge
pytest-xdist              1.29.0                     py_0    conda-forge
python                    3.6.8                haf84260_0  
python-dateutil           2.8.0                    py36_0  
python-rapidjson          0.7.2            py36h6de7cb9_0    conda-forge
pytz                      2019.2                     py_0  
pyzmq                     18.0.2           py36hee98d25_2    conda-forge
qt                        5.9.7                h468cd18_1  
qtconsole                 4.5.5                      py_0  
readline                  7.0                  h1de35cc_5  
requests                  2.22.0                   py36_1    conda-forge
requests-mock             1.6.0                      py_0    conda-forge
rpcq                      2.7.3                     dev_0    <develop>
ruamel                    1.0                      py36_0    conda-forge
ruamel.yaml               0.15.100         py36h01d97ff_0    conda-forge
scipy                     1.3.1            py36h1410ff5_0  
seaborn                   0.9.0                    py36_0  
send2trash                1.5.0                    py36_0  
setuptools                41.0.1                   py36_0  
sip                       4.19.8           py36h0a44026_0  
six                       1.12.0                py36_1000    conda-forge
snowballstemmer           1.9.0                      py_0  
sphinx                    2.1.2                      py_0    conda-forge
sphinx-autodoc-typehints  1.8.0                    pypi_0    pypi
sphinx_rtd_theme          0.4.3                      py_0    conda-forge
sphinxcontrib-applehelp   1.0.1                      py_0  
sphinxcontrib-devhelp     1.0.1                      py_0  
sphinxcontrib-htmlhelp    1.0.2                      py_0  
sphinxcontrib-jsmath      1.0.1                      py_0  
sphinxcontrib-qthelp      1.0.2                      py_0  
sphinxcontrib-serializinghtml 1.1.3                      py_0  
sqlite                    3.29.0               ha441bb4_0  
statsmodels               0.10.1           py36h1d22016_0  
terminado                 0.8.2                    py36_0  
testpath                  0.4.2                    py36_0  
tk                        8.6.8                ha441bb4_0  
toml                      0.10.0           py36h28b3542_0  
tornado                   6.0.3            py36h1de35cc_0  
tox                       3.12.1                     py_0    conda-forge
traitlets                 4.3.2            py36h65bd3ce_0  
typing                    3.6.4                    py36_0    conda-forge
urllib3                   1.25.3                   py36_0  
virtualenv                16.0.0                   py36_0  
wcwidth                   0.1.7            py36h8c6ec74_0  
webencodings              0.5.1                    py36_1  
wheel                     0.33.4                   py36_0  
widgetsnbextension        3.5.1                    py36_0  
xz                        5.2.4                h1de35cc_4  
zeromq                    4.3.2                h6de7cb9_2    conda-forge
zipp                      0.5.2                      py_0  
zlib                      1.2.11               h1de35cc_3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pyquil/pyqvm.py at _extract_defined_gates(), where the reproduced example raises NotImplementedError for parameterized DEFGATEs. Run the parametric CRX example from the issue and trace how PyQVM loads defined gates. Done means PyQVM accepts and executes that example without the unsupported-operation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
backend, quantum-computing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.