ProjectQ-Framework / ProjectQ

ProjectQ: An open source software framework for quantum computing
https://projectq.ch
Apache License 2.0
874 stars 271 forks source link

How to check if projectq is running on C++ Simulator #415

Closed keithyau closed 2 years ago

keithyau commented 2 years ago

Hi there,

I'm trying to run ProjectQ on ARM devices and since the LLVM / GCC is well supported. How do i check if the jobs are not running on Python Simulator?

Thank you very mcuh !!!

Takishima commented 2 years ago

The Python simulator always print a message upon construction (Note: This is the (slow) Python simulator.).

If that message does not appear when creating a new Simulator object, you're using the C++ simulator.

keithyau commented 2 years ago

hi, i found that pybind11 is not really working and pip install not compiling .so

But python3 setup.py build install works.

Takishima commented 2 years ago

Could you provide here the full installation log with the error when running the installation command using Pip?

Something like python3 -m pip install -v projectq.

Also, what OS, OS version, Python and Pip versions are you using?

Further output that could be helpful:

keithyau commented 2 years ago

MacOS Big sur git clone python3 -m pip install --user . #No error messages but .so not generated

python3 setup.py install #.so generated with ERROR image

AWS gravtion ARM machine git clone python3 -m pip install --user . #No error messages but .so not generated python3 setup.py install #.so generated without ERROR image

But run sample code below cannot mutli-thread

import os
os.environ["OMP_NUM_THREADS"] = '4'
os.environ["OMP_PROC_BIND"] = "spread"

from projectq import MainEngine
from projectq.backends import ResourceCounter
from projectq.ops import All, CNOT, H, Measure, Rz, X, Z, Swap
from projectq.ops import QFT
from projectq.setups import linear
from projectq.setups.default import get_engine_list

import time
start_time = time.time()
compiler_engines = linear.get_engine_list(num_qubits=100,
                                          one_qubit_gates='any',
                                          two_qubit_gates=(CNOT, Swap))
resource_counter = ResourceCounter()
#eng = MainEngine(engine_list=get_engine_list() + [resource_counter])
eng = MainEngine(backend=resource_counter, engine_list=compiler_engines)
#eng = MainEngine(backend=resource_counter)
qureg = eng.allocate_qureg(100)
QFT | qureg
eng.flush()

print(resource_counter)
print("--- %s seconds ---" % (time.time() - start_time))

image

thank you so much

Takishima commented 2 years ago

Thanks for the information.

One potential issue regarding the multi-threading is that the Apple Clang compiler does not actually support OpenMP (the last time I looked, haven't checked lately), so you might want to install the llvm package using HomeBrew (for e.g.) and then install ProjectQ like so:

CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++ python3 -m pip install -v projectq

EDIT:

Also, the installer will never actually fail, if for some reason the compilation fails, an error message is printed to the console (but hidden from you if you do not add the -v verbose flag to pip install)

Takishima commented 2 years ago

Also, regarding your second point about multi-threading, only the C++ simulator is actually capable of using OpenMP enabled code. So all of these:

eng = MainEngine(backend=resource_counter, engine_list=compiler_engines)
eng = MainEngine(backend=resource_counter)

Will not run in parallel, since no C++ simulator is instantiated.

keithyau commented 2 years ago

Also, regarding your second point about multi-threading, only the C++ simulator is actually capable of using OpenMP enabled code. So all of these:

eng = MainEngine(backend=resource_counter, engine_list=compiler_engines)
eng = MainEngine(backend=resource_counter)

Will not run in parallel, since no C++ simulator is instantiated.

So how can I run the C++ Simulator ?

keithyau commented 2 years ago

Also, regarding your second point about multi-threading, only the C++ simulator is actually capable of using OpenMP enabled code. So all of these:

eng = MainEngine(backend=resource_counter, engine_list=compiler_engines)
eng = MainEngine(backend=resource_counter)

Will not run in parallel, since no C++ simulator is instantiated.

So how can I run the C++ Simulator ?

Worked with demo Shor algo, Thank you so much !