rigetti / reference-qvm

A reference implementation for a quantum virtual machine in Python
Apache License 2.0
46 stars 20 forks source link

unitary_generator.py : tensor_gates() tries to call numpy array #18

Closed astrophys closed 5 years ago

astrophys commented 6 years ago

I have a minimal working example:

from pyquil.quil import Program
from pyquil.gates import *
from pyquil.parameters import Parameter, quil_sin, quil_cos
from pyquil.quilbase import DefGate
from pyquil.api import QVMConnection
#from referenceqvm.api import QVMConnection
import numpy as np
theta = Parameter('theta')
cry = np.array([[1.0,0.0,0.0,0.0],[0.0,1.0,0.0,0.0],[0.0,0.0,quil_cos(theta / 2), -1 * quil_sin(theta / 2)],[0.0,0.0,quil_sin(theta / 2), quil_cos(theta / 2)]]) 
dg = DefGate('CRY', cry, [theta])
CRY = dg.get_constructor()
p = Program()
p.inst(dg)
p.inst (X(0))
p.inst (X(1))
p.inst (CRY(4.304)(0,2))
qvm = QVMConnection()
wf = qvm.wavefunction(p)
print(wf)

When I run this I get the output :

(-0.5490303672+0j)|011> + (0.8358024024+0j)|111>

If I switch from the Rigetti server to a local installation of reference-qvm (i.e. comment from pyquil.api import QVMConnection and uncomment #from referenceqvm.api import QVMConnection) and try to run it I get the error :

Traceback (most recent call last):
  File "minimal_broken_example.py", line 22, in <module>
    wf = qvm.wavefunction(p)
  File "/gpfs0/export/opt/python/3.6.5/additional_packages/src/reference-qvm/referenceqvm/qvm_wavefunction.py", line 378, in wavefunction
    self.kernel()
  File "/gpfs0/export/opt/python/3.6.5/additional_packages/src/reference-qvm/referenceqvm/qam.py", line 167, in kernel
    halted = self.transition(self.current_instruction())
  File "/gpfs0/export/opt/python/3.6.5/additional_packages/src/reference-qvm/referenceqvm/qvm_wavefunction.py", line 268, in transition
    self._transition(instruction)
  File "/gpfs0/export/opt/python/3.6.5/additional_packages/src/reference-qvm/referenceqvm/qvm_wavefunction.py", line 180, in _transition
    unitary = tensor_gates(self.gate_set, self.defgate_set, instruction, self.num_qubits)
  File "/gpfs0/export/opt/python/3.6.5/additional_packages/src/reference-qvm/referenceqvm/unitary_generator.py", line 352, in tensor_gates
    (*[value_get(p) for p in pyquil_gate.params]),
TypeError: 'numpy.ndarray' object is not callable

It seems to me that the in the function tensor_gates() that it is expecting something other than a numpy array to be returned by dict_check[pyquil_gate.name].

QUESTIONS:

  1. How do I fix this?
  2. Also, is the expected behavior of the local installation of reference-qvm supposed to exactly replicate the behavior of the Rigetti server version?

Thanks

vtomole commented 6 years ago

Could be a bug in the reference QVM. What do you think? @ncrubin

ncrubin commented 6 years ago

Checking in detail this week

euler16 commented 6 years ago

is this issue still open?

vtomole commented 6 years ago

@euler16 Yes.

euler16 commented 6 years ago

@vtomole I want to start contributing to Open Source and specially PyQuil. Could you give me some pointers to solve the issue?

vtomole commented 6 years ago

@euler16 This is not a good isue for first timers. I sugget you work on any of https://github.com/rigetticomputing/pyquil/issues?q=label%3A"good+first+issue"+is%3Aissue+is%3Aopen instead.

mpharrigan commented 6 years ago

you can also try using / contributing to https://github.com/rigetticomputing/pyquil/pull/552

euler16 commented 6 years ago

Thank you @vtomole and @mpharrigan :)

mpharrigan commented 5 years ago

reference_qvm is now cleaned up and in pyquil