Skip to content

Controlled H crashes on a PyQVM #1259

@jsvandyke86

Description

@jsvandyke86

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

I might be missing something, but when I try to implement a controlled H gate on a PyQVM and execute it, the system crashes.

Code Snippet

from pyquil import Program
from pyquil.gates import H, X
from pyquil.pyqvm import PyQVM

p = Program(X(0), H(1).controlled(0))

qvm = PyQVM(n_qubits=2)
qvm.execute(p)

Error Output

Traceback (most recent call last):
  File "dotest_pyqvm.py", line 9, in <module>
    qvm.execute(p)
  File "/opt/miniconda3/envs/rigetti/lib/python3.7/site-packages/pyquil/pyqvm.py", line 502, in execute
    return self._execute_program()
  File "/opt/miniconda3/envs/rigetti/lib/python3.7/site-packages/pyquil/pyqvm.py", line 486, in _execute_program
    halted = self.transition()
  File "/opt/miniconda3/envs/rigetti/lib/python3.7/site-packages/pyquil/pyqvm.py", line 323, in transition
    self.wf_simulator.do_gate(gate=instruction)
  File "/opt/miniconda3/envs/rigetti/lib/python3.7/site-packages/pyquil/simulation/_numpy.py", line 266, in do_gate
    gate_matrix, qubit_inds = _get_gate_tensor_and_qubits(gate=gate)
  File "/opt/miniconda3/envs/rigetti/lib/python3.7/site-packages/pyquil/simulation/_numpy.py", line 160, in _get_gate_tensor_and_qubits
    tensor = np.reshape(matrix, (2,) * len(qubit_inds) * 2)
  File "<__array_function__ internals>", line 6, in reshape
  File "/opt/miniconda3/envs/rigetti/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 299, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "/opt/miniconda3/envs/rigetti/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 58, in _wrapfunc
    return bound(*args, **kwds)
ValueError: cannot reshape array of size 4 into shape (2,2,2,2)

Environment Context

Operating System: MacOS Catalina 10.15.4

Python Version (python -V): Python 3.7.8

Quilc Version (quilc --version): 1.22.0 [cb8ba42]

QVM Version (qvm --version): 1.17.1 [cf3f91f]

Python Environment Details (pip freeze or conda list):

# packages in environment at /opt/miniconda3/envs/rigetti:
#
# Name                    Version                   Build  Channel
antlr4-python3-runtime    4.7.2                    pypi_0    pypi
ca-certificates           2020.6.20            hecda079_0    conda-forge
certifi                   2020.6.20        py37h2987424_2    conda-forge
chardet                   3.0.4                    pypi_0    pypi
decorator                 4.4.2                    pypi_0    pypi
idna                      2.10                     pypi_0    pypi
immutables                0.6                      pypi_0    pypi
libcxx                    11.0.0               h439d374_0    conda-forge
libffi                    3.2.1             hb1e8313_1007    conda-forge
msgpack                   0.6.2                    pypi_0    pypi
ncurses                   6.2                  hb1e8313_2    conda-forge
networkx                  2.5                      pypi_0    pypi
numpy                     1.19.2                   pypi_0    pypi
openssl                   1.1.1h               haf1e3a3_0    conda-forge
pip                       20.2.3                     py_0    conda-forge
pyquil                    2.23.2                   pypi_0    pypi
python                    3.7.8           hc9dea61_1_cpython    conda-forge
python-rapidjson          0.9.1                    pypi_0    pypi
python_abi                3.7                     1_cp37m    conda-forge
pyzmq                     19.0.2                   pypi_0    pypi
readline                  8.0                  h0678c8f_2    conda-forge
requests                  2.24.0                   pypi_0    pypi
rpcq                      3.4.0                    pypi_0    pypi
ruamel-yaml               0.16.12                  pypi_0    pypi
ruamel-yaml-clib          0.2.2                    pypi_0    pypi
scipy                     1.5.2                    pypi_0    pypi
setuptools                49.6.0           py37h2987424_2    conda-forge
sqlite                    3.33.0               h960bd1c_1    conda-forge
tk                        8.6.10               hb0a8c7a_1    conda-forge
urllib3                   1.25.10                  pypi_0    pypi
wheel                     0.35.1             pyh9f0ad1d_0    conda-forge
xz                        5.2.5                haf1e3a3_1    conda-forge
zlib                      1.2.11            h7795811_1010    conda-forge

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛An issue that needs fixing.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions