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

Global Rydberg pulse is only single threaded #177

Open
paoloviviani opened this issue May 25, 2021 · 4 comments
Open

Global Rydberg pulse is only single threaded #177

paoloviviani opened this issue May 25, 2021 · 4 comments
Labels
archive Smthg to keep in mind, but not worth implementing now

Comments

@paoloviviani
Copy link

paoloviviani commented May 25, 2021

I tried to run execute the UD-MIS tutorial either on the proposed register and on a larger one (10 quits) with longer sequences/more layers.
With typical pulser/qutip installation from pip the single quantum loop runs always on a single core only.

I tried to:

but none of the solutions above improved the cpu usage beyond a single core.

In general it would be possible to parallelise the code at a different level (e.g. at the level of the optimization loop, like with population-based optimizers), however, I was wondering if this is the expected behaviour or if there is a chance of parallelising the simulation itself.

@sebgrijalva
Copy link
Contributor

Hi Paolo,

Thanks for raising this issue, indeed, It's interesting to try to run a multi-thread job for Pulser leveraging QuTiP. I will try to reproduce a basic approach and get back to you. We might have to ask the devs at QuTiP too if necessary.

@sebgrijalva
Copy link
Contributor

sebgrijalva commented May 27, 2021

Here's a simple implementation of using multiple cores with Pulser and leveraging QuTiP's parallel_map() function:

import numpy as np
import qutip

from pulser import Register, Pulse, Sequence
from pulser.devices import Chadoq2
from pulser.simulation import Simulation

# Create a parametrized sequence
reg = Register.from_coordinates([[0,0]] )  # Just one atom.
seq = Sequence(reg, Chadoq2)
seq.declare_channel('ch0', 'rydberg_global')

rabi = seq.declare_variable('rabi')

seq.add(Pulse.ConstantPulse(200, rabi ,0, 0), 'ch0')

Notice that instead of assigning values one by one in a for loop (and thus having to redefine several times the Sequenceinstance), I am using a parametrized sequence with variable rabi. Then, I will build each sequence according to a given param:

# Define simulation experiment function:
def experiment(param):
    obs = qutip.basis(2,0).proj()  # Calculate occupation in the rydberg state
    seq_instance = seq.build(rabi=param)
    seq_instance.measure('ground-rydberg')
    
    sim = Simulation(seq_instance, sampling_rate=0.01)
    res = sim.run()

    return res.expect([obs])[0]

With this setup you can use QuTiP's parallel_map() function which automatically uses all the cores available in your computer :

qutip.parallel_map(experiment, np.linspace(1, 1.5, 100)) # Get expectation values for the entire dynamics and 100 parameter values

Notice this will be twice as fast as simply using

for val in np.linspace(1,1.5,1000):
    experiment(val)

Depending on the parameters of your sequence, this might be what you're looking for. Let me know if it helps.

@HGSilveri
Copy link
Collaborator

@sebgrijalva This issue has been open for a while now, what's the status on this? Should we close it / archive it?

@sebgrijalva
Copy link
Contributor

I'd say we archive it, yes.

@HGSilveri HGSilveri added the archive Smthg to keep in mind, but not worth implementing now label May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archive Smthg to keep in mind, but not worth implementing now
Projects
None yet
Development

No branches or pull requests

3 participants