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

Deutsch-Josza broken for two-qubit case #156

Open
rsln-s opened this issue May 17, 2018 · 1 comment
Open

Deutsch-Josza broken for two-qubit case #156

rsln-s opened this issue May 17, 2018 · 1 comment
Assignees

Comments

@rsln-s
Copy link

rsln-s commented May 17, 2018

The following example breaks Deutsch-Josza for two-qubit case with error:

Traceback (most recent call last):
  File "./deutsch-josza.py", line 15, in <module>
    is_constant = dj.is_constant(qvm,qubit_bitmap)
  File "/Users/ruslan/anaconda3/envs/pyquil/lib/python3.6/site-packages/grove/deutsch_jozsa/deutsch_jozsa.py", line 59, in is_constant
    constant = all([bit == 0 for bit in bitstring])
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Code producing the error:

import numpy as np
import pyquil.api as api
import pyquil.quil as pq
from pyquil.gates import X, H, CNOT

from grove.deutsch_jozsa.deutsch_jozsa import DeutschJosza, ORACLE_GATE_NAME

qvm = api.QVMConnection()
qubit_bitmap = {"00": "1", "01" : "1", "10" : "1", "11": "1"}

dj = DeutschJosza()
is_constant = dj.is_constant(qvm,qubit_bitmap)
print(is_constant)

Is fixable by changing the offending line to:

constant = all([bit == 0 for bit in bitstring][0])

but I'm not sure if that's the most elegant solution.

You might also want to consider adding it to tests (they lack working 2-qubit mapping examples, only the ones that are invalid).

See also PR #146

@amyfbrown amyfbrown self-assigned this Nov 17, 2018
@jorgeviegas
Copy link

Hey @amyfbrown

Was there a fix for this? I'm unable to make DJ algorithm run for 1+ qubit.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-459d38310220> in <module>
     19 
     20 dj = DeutschJosza()
---> 21 is_constant = dj.is_constant(qvm,qubit_bitmap)
     22 print(is_constant)

~/opt/anaconda3/envs/QUANTUM/lib/python3.9/site-packages/grove/deutsch_jozsa/deutsch_jozsa.py in is_constant(self, cxn, bitstring_map)
     57         # We are only running a single shot, so we are only interested in the first element.
     58         bitstring = np.array(returned_bitstring, dtype=int)
---> 59         constant = all([bit == 0 for bit in bitstring])
     60         return constant
     61 

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants