ngnrsaa / qflex

Flexible Quantum Circuit Simulator (qFlex) implements an efficient tensor network, CPU-based simulator of large quantum circuits.
Apache License 2.0
97 stars 24 forks source link

Can't get python interface to work #219

Closed kevinsung closed 4 years ago

kevinsung commented 4 years ago

After following the instructions for setting up Python, I try to run the example script by executing python qflex_cirq_example.py. I get

Traceback (most recent call last):
  File "qflex_cirq_example.py", line 2, in <module>
    import python.cirq_interface.qflex_simulator as qsim
  File "/usr/local/google/home/sungkevin/Projects/qflex/python/cirq_interface/qflex_simulator.py", line 5, in <module>
    from python import qflex
ImportError: cannot import name 'qflex' from 'python' (unknown location)
s-mandra commented 4 years ago

Thanks for catching this. I've created a patch to solve the problem in #221. The problem is related to the fact that it's missing the relative path to where to find the qflex python modules. Try now with:

python3 python/qflex_cirq_example.py

from the root folder of qflex (it works for me).

alexandrupaler commented 4 years ago

Thank you for pointing this out. It is indeed an issue with the paths. However, we have also a relative paths related issue #167 . I guess the solution should consider module __init__.py.

kevinsung commented 4 years ago

It still doesn't work for me (same error).

alexandrupaler commented 4 years ago

Have you compiled QFlex with make pybind? In the pythonfolder there should be a file with a name like qflex.[long_name].so

95-martin-orion commented 4 years ago

Have you compiled QFlex with make pybind?

Note that this normally runs during the default make invocation; if it didn't, the logs should indicate what prevented it from doing so (usually missing dependencies, IIRC).

kevinsung commented 4 years ago

I didn't have pybind. Installing it fixed the issue. Thanks!

alexandrupaler commented 4 years ago

@s-mandra Should we suggest the user to run pip install -r requirements.txt if one if the python dependencies fail on configure?

s-mandra commented 4 years ago

Sure, I can add that to README.md and docs/install.md.