Lightning.qubit CPU utilisation

Hi again,

Does lightning.qubit utilise all cores of a CPU or just one?

Thanks :slight_smile:

Hi @James_Ellis,

It utilises a single core at the moment, but exploring multi-threading is on our radar. :slightly_smiling_face:

1 Like

Thanks for the answer.

Does this mean it is possible to run multiple ‘lightning.qubit’ experiments at once?

Hi @James_Ellis,

Yes, that would be feasible!

So if I have a quad core i7… could I run 4 experiments or 8 (because of hyper-threading) ?

Hi @James_Ellis,

Creating a simulation with lightning.qubit device and executing quantum circuits would be contained within a single Python process that places calls to bound C++ functions.

Since we are not handling multi-threading or parallelism explicitly within PennyLane when using lightning.qubit with default options, creating multiple Python processes that contain experiments as described will behave similarly for multi-core machines as creating other Python processes. Most probably the ability to utilize multiple cores will help, though the incurred overhead of scheduling and using shared resources will also affect the performance.

Having said that we haven’t explored multi-core running scenarios too extensively, so would be interesting to see any findings on it! :slightly_smiling_face:

Thanks for the detailed reply!

So to summarise, does this mean I can’t run multiple qubit experiments in parallel in one python script? It would have to be over multiple python scripts?

Hi @James_Ellis. You should be able to run multiple simulations in parallel using a single Python script, although you would have to parallelize it yourself using e.g. Dask, which would help you set up up to one Python process per thread (i.e. 8 in your case, I believe).

There’s a quirk with Python called the Global Interpreter Lock (GIL) that prevents multiple threads from executing Python code at the same time. Thus, you’d need to create separate Python processes that, as @antalszava mentioned above, need to share some resources and will incur some extra overhead. Dask, and other parallelisation packages, would be able to help you with that, without the need to understand or implement the nitty-gritty details yourself.

Let us know how it goes, or if you have any other issues or questions!