Skip to main content

Sirepo-Bluesky interface

Project description

Sirepo-Bluesky interface


An attempt to integrate Sirepo/SRW simulations with Bluesky/Ophyd.

Based on this Sirepo simulation that can be downloaded in the next section:

Prepare a local Sirepo server

  • Install Sirepo using Vagrant/VirtualBox following the instructions (you will need to install VirtualBox and Vagrant)

  • After the successful installation start the VM with vagrant up and ssh to it with vagrant ssh

  • Run the following command to start Sirepo with the Bluesky interface (bluesky is a “secret” key used on both server and client sides, and the SIREPO_FEATURE_CONFIG_SIM_TYPES=srw part is optional if you run Sirepo directly on a Linux/Mac machine and only have SRW installed):

  • In your browser, go to, click the “Import” button in the right-upper corner and upload the archive with the simulation stored in this repo

  • You should be redirected to the address like

  • Grab the last 8 alphanumeric symbols (IKROlKfR), which represent a UID for the simulation we will be working with in the next section.

You can also consider running a Docker container:

mkdir -p $HOME/tmp/sirepo-docker-run
docker run -it --rm -e SIREPO_AUTH_METHODS=bluesky:guest -e SIREPO_AUTH_BLUESKY_SECRET=bluesky -e SIREPO_SRDB_ROOT=/sirepo -e SIREPO_COOKIE_IS_SECURE=false -p 8000:8000 -v $HOME/tmp/sirepo-docker-run:/sirepo radiasoft/sirepo:beta /home/vagrant/.pyenv/shims/sirepo service http

Prepare Bluesky and trigger a simulated Sirepo detector

  • (OPTIONAL) Make sure you have mongodb installed and the service is running (see local.yml for details)

  • Create a conda environment:

git clone
cd sirepo-bluesky/
conda create -n sirepo_bluesky python=3.7 -y
conda activate sirepo_bluesky
pip install -e .
  • Start ipython and run the following where sim_id is the UID for the simulation we are working with:

%run -i examples/
import sirepo_bluesky.sirepo_detector as sd
import bluesky.plans as bp
sirepo_det = sd.SirepoDetector(sim_id='<sim_id>', reg=db.reg)
param1 = sirepo_det.create_parameter('horizontalSize')
param2 = sirepo_det.create_parameter('verticalSize')
sirepo_det.read_attrs = ['image', 'mean', 'photon_energy']
sirepo_det.configuration_attrs = ['horizontal_extent',
                param1, 0, 1, 10,
                param2, 0, 1, 10,

You should get something like:
  • Get the data:

hdr = db[-1]
imgs = list('sirepo_det_image'))
cfg = hdr.config_data('sirepo_det')['primary'][0]
hor_ext = cfg['{}_horizontal_extent'.format(]
vert_ext = cfg['{}_vertical_extent'.format(]
plt.imshow(imgs[21], aspect='equal', extent=(*hor_ext, *vert_ext))

You should get something like:

To view single-electron spectrum report (Hint: use a different sim_id, e.g. for the NSLS-II CHX beamline example):

%run -i examples/
import sirepo_bluesky.sirepo_detector as sd
import bluesky.plans as bp
sirepo_det = sd.SirepoDetector(sim_id='<sim_id>', reg=db.reg, source_simulation=True)
sirepo_det.read_attrs = ['image', 'mean', 'photon_energy']
sirepo_det.configuration_attrs = ['horizontal_extent',
hdr = db[-1]
imgs = list('sirepo_det_image'))

You should get something like:

Use a simulated Sirepo Flyer to run multiple simulations

  • This section is based on the Young’s Double Slit Experiment Sirepo example that can be found in the wavefront propagation folder on the SRW simulations section

  • Open the simulation and grab the new UID (the last 8 alphanumeric symbols)

  • Start ipython and run the following:

%run -i examples/
import bluesky.plans as bp
import sirepo_bluesky.sirepo_flyer as sf
  • To create 5 different simulations that change 4 parameters at a time:

params_to_change = []
for i in range(1, 6):
    key1 = 'Aperture'
    parameters_update1 = {'horizontalSize': i * .1, 'verticalSize': (16 - i) * .1}
    key2 = 'Lens'
    parameters_update2 = {'horizontalFocalLength': i + 7}
    key3 = 'Obstacle'
    parameters_update3 = {'horizontalSize': 6 - i}
    params_to_change.append({key1: parameters_update1,
                             key2: parameters_update2,
                             key3: parameters_update3})
  • Create the flyer and run a fly scan where sim_id is the UID of this simulation:

sirepo_flyer = sf.SirepoFlyer(sim_id='<sim_id>', server_name='',
                              root_dir=root_dir, params_to_change=params_to_change,

  • Access the data:

hdr = db[-1]

Databroker will return the following information:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sirepo-bluesky-0.0.2.tar.gz (37.9 kB view hashes)

Uploaded source

Built Distribution

sirepo_bluesky-0.0.2-py3-none-any.whl (18.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page