Skip to content
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

Controlled H crashes on a PyQVM #1259

Open
2 tasks done
jsvandyke86 opened this issue Oct 20, 2020 · 1 comment · May be fixed by #1338
Open
2 tasks done

Controlled H crashes on a PyQVM #1259

jsvandyke86 opened this issue Oct 20, 2020 · 1 comment · May be fixed by #1338
Labels
bug 🐛 An issue that needs fixing.

Comments

@jsvandyke86
Copy link

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
@jsvandyke86 jsvandyke86 added the bug 🐛 An issue that needs fixing. label Oct 20, 2020
@wjy99-c
Copy link

wjy99-c commented Nov 17, 2020

I have the same issue with Controlled X. But it is strange Pyqvm can work with CNOT. CNOT should be the same gate with Controlled X, right?

@dwillmer dwillmer linked a pull request May 22, 2021 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue that needs fixing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants