Skip to main content

sirepo-bluesky

https://img.shields.io/travis/NSLS-II/sirepo-bluesky.svg https://img.shields.io/pypi/v/sirepo-bluesky.svg

Sirepo-Bluesky interface

Purpose

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

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

https://github.com/NSLS-II/sirepo-bluesky/raw/master/images/basic_beamline.png

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):

SIREPO_FEATURE_CONFIG_SIM_TYPES=srw SIREPO_AUTH_METHODS=bluesky:guest SIREPO_AUTH_BLUESKY_SECRET=bluesky sirepo service http
  • In your browser, go to http://10.10.10.10:8000/srw, 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 http://10.10.10.10:8000/srw#/source/IKROlKfR

  • 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 https://github.com/NSLS-II/sirepo-bluesky/
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/prepare_det_env.py
import sirepo_bluesky.sirepo_detector as sd
import bluesky.plans as bp
sirepo_det = sd.SirepoDetector(sim_id='<sim_id>', reg=db.reg)
sirepo_det.select_optic('Aperture')
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',
                                  'vertical_extent',
                                  'shape']
RE(bp.grid_scan([sirepo_det],
                param1, 0, 1, 10,
                param2, 0, 1, 10,
                True))

You should get something like:

https://github.com/NSLS-II/sirepo-bluesky/raw/master/images/sirepo_bluesky_grid.png
  • Get the data:

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

You should get something like:

https://github.com/NSLS-II/sirepo-bluesky/raw/master/images/sirepo_bluesky.png

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

%run -i examples/prepare_det_env.py
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',
                                  'vertical_extent',
                                  'shape']
RE(bp.count([sirepo_det]))
hdr = db[-1]
imgs = list(hdr.data('sirepo_det_image'))
plt.plot(imgs[-1])

You should get something like:

https://github.com/NSLS-II/sirepo-bluesky/raw/master/images/spectrum.png

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/prepare_flyer_env.py
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='http://10.10.10.10:8000',
                              root_dir=root_dir, params_to_change=params_to_change,
                              watch_name='W60')

RE(bp.fly([sirepo_flyer]))
  • Access the data:

hdr = db[-1]
hdr.table(stream_name="sirepo_flyer")

Databroker will return the following information:

https://github.com/NSLS-II/sirepo-bluesky/raw/master/images/flyer_output.png

Release files for sirepo-bluesky 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sirepo-bluesky 0.0.2
File Size Uploaded
sirepo-bluesky-0.0.2.tar.gz 37.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sirepo-bluesky 0.0.2
File Interpreter ABI Platform
sirepo_bluesky-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 56.1 kB

Release files / sirepo-bluesky-0.0.2.tar.gz

Download URL sirepo-bluesky-0.0.2.tar.gz
Size 37.9 kB
Tags Source
SHA-256 checksum
How to use checksums
05e520d72cc100dd9bc28c6742c45fec4856763595acdd91c738ad71580abd21
BLAKE2b-256 checksum
How to use checksums
8e0c19de62f9a7122f87254410abd8f40b582d900399c885f38ca84abb0440a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Release files / sirepo_bluesky-0.0.2-py3-none-any.whl

Download URL sirepo_bluesky-0.0.2-py3-none-any.whl
Size 18.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5a96767e567506c41d84bceff80612a5e57e663481fe2ca9f8c703fb940bb78
BLAKE2b-256 checksum
How to use checksums
dad1ffb91d951341ff6703841b756db1662da01c6cc764523ec6878e9987467f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Release history Release notifications | RSS feed

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page