PaNOSC-ViNYL / ViNYL-project

This repository keeps track of tasks, milestones, deliverables of workpackage 5 in panosc.
Apache License 2.0
5 stars 5 forks source link

Instrument database #65

Closed CFGrote closed 2 years ago

CFGrote commented 3 years ago

hi @aljosahafner , if you find the time, please provide a rough sketch of your ideas and plans here.

mads-bertelsen commented 3 years ago

Reading the description for internal milestone 5.4 I get the impression we will store serialized version of the simulations in some database instead of simple python scripts. Can see the advantage in this for simple use cases, but it will be difficult to use this as examples for how to use the simulation codes. Perhaps a database with both options could be envisioned?

aljosahafner commented 3 years ago

Good point! For Oasys there is more or less no other way than making the whole Oasys workspaces (binary files) available. Otherwise it is impossible to have a certain beamline in the GUI.

aljosahafner commented 3 years ago

After discussion with @srio , we think that a documented repository of (documented) Oasys workspaces should suffice for this. There is already built-in capability in Oasys to open remote workspaces.

https://github.com/PaNOSC-ViNYL/Oasys-PaNOSC-Workspaces

CFGrote commented 3 years ago

After discussion with @srio , we think that a documented repository of (documented) Oasys workspaces should suffice for this. There is already built-in capability in Oasys to open remote workspaces.

https://github.com/PaNOSC-ViNYL/Oasys-PaNOSC-Workspaces

That's great news. Such a repo would be more than sufficient, also for other RIs and simulation frameworks.

shervin86 commented 3 years ago

Summary of the outcome of the first meeting:

JunCEEE commented 3 years ago

I feel the definitions in NeXus could be a good reference: https://manual.nexusformat.org/classes/base_classes/NXentry.html#nxentry

INSTRUMENT:
    name: simulation calculator (e.g. pysingfel) or the name of the instrument simulated by SIMEX (e.g. virtual SPB/SFX)
        @short_name: simulation calculator acronym
    DETECTOR: 
        sensor_material: Ideal
        sensor_thickness: 0
    DETECTOR_MODULE: Convert from crystfel .geom?
BEAM: 
    incident_wavelength: simulation wavelength
    total_flux: 
SOURCE:
        name: SIMEX
shervin86 commented 3 years ago

In order to clone without having an account on github, this should work:

git clone git://github.com/PaNOSC-ViNYL/instrument_database.git
shervin86 commented 3 years ago

Here's the repository that have been created and I started to populate it on a branch "shervin"

shervin86 commented 3 years ago

@mads-bertelsen @JunCEEE can you please draft a possible todo list here from your perspective?

Here's the notes I showed during our last meeting. The conversion to Markdown is not perfect, I will fix it.

Repository structure

<simulation code >/<institute>/<instrument|source|beamline>

versioning is done as follows:

Example

pseudo code

.init(url=the default repository, local_repo=some default local directory)

git clone $url $local_path if it does not exist git pull to update the local repo

.load_instrument (instrument_sample, version=HEAD)

.load_sample()

.set_sample(instrument_obj, sample_obj)

.ls_instrument()

prints the names of the available instruments

.ls_samples()

prints the names of the available samples

.ls_versions(instrument)

prints the available versions for the required instrument

.dump_instrument(outputfile)

saves in .py format the instrument description

.print_parameters(outfile)

prints in json format the list of parameters for the instrument

class pyVinylSample

Is there a general way to deal with the sample+sample environment that can be used by both McStasScripts and SimEx? Having a common base class as for the parameters would make it simpler to define an API for a sample database/repository.

class pyVinylParameters

A stupid basic example:

{
   "counts": [value, min, max, step], 
  "wavelength": , 
 "collimation":,
 "detector position" , 
}

The question is how to track changes in the non-parameter variables in the component definitions?

myparams = pyVinylParameters()

myparams = pyVinylParameters(instrument_file) # here instrument_file is in the original mcstas format

myinstrument, myparams = load_instrument()

#mysource = myinstrument.add_component("source", "Source_simple") mysource.xwidth = 0.12 mysource.yheight = 0.12 mysource.lambda0 = myparams.wavelength.value # copy by reference, not value mysource.dlambda = 2.2 mysource.focus_xw = 0.05 mysource.focus_yh = 0.05

myparams.dump("running_values.json")

myOpenPMDoutput <-> myinstrument #myOpenPMDoutput.set_parameters(myparams)

other option: my_source.xwidth = param(isParam=false, value=0.12) mysource.lambda0 = param(isParam=true, value=myparams.wavelength)

myinstrument.dump_nonparameters(): this loops over the components and prints in json format the values of the variables that are 'isParam=false'

if the instrument is not in the repository or modified w.r.t. to that, just dump the pickle in the openPMD?

it is not safe to include a pickle... json is more appropriate

Simulation request.json

{ "--ncount": "5000000000", "instrument": { "name": "D22" }, "mcpl": {}, "return": "COUNTS", "sDETECTOR": {}, "sFULL": { "lambda": 4.51 }, "sSAMPLE": { "D22~collimation~": 2.0, "material": "H2O", "sample~sizer~": 0.0051, "sample~sizey~": 0.0052 }, "sSOURCE": {}, "type": 2 }

simulation stages:

Information saved in openPMD

JunCEEE commented 3 years ago

Todo:

shervin86 commented 3 years ago
mads-bertelsen commented 2 years ago

I was tasked with creating a prototype system for parameters that would go well with the instrument database. It consists of the following:

The code includes a few example files that show how the code is supposed to be used.

ParameterPrototype_package.zip

shervin86 commented 2 years ago

This can be pushed in a new branch in the PyVynil repository and @JunCEEE and me can see how to merge it into it next week. After that, I can modify the prototype of the D22 instrument description providing the parameters

JunCEEE commented 2 years ago

I have checked @mads-bertelsen 's parameters class. I see its potential to be the baseParamters class in libpyvinyl. My question is:

If there can be answered, we are in good shape.

JunCEEE commented 2 years ago

A way to implement Mads' design in this example: https://github.com/PaNOSC-ViNYL/libpyvinyl/blob/master/doc/source/include/notebooks/example-01.ipynb

def setCalculatorParameters(photon_energy=6e3, pulse_energy=1.0e-6, grid_size_x=128, grid_size_y=128):
    param1 = Parameter("photon_energy", unit="eV", comment="Photon energy")
    param2 = Parameter("photon_energy", unit="joule", comment="Energy per pulse")
    param3 = Parameter("grid_size_x", unit="", comment="Grid size in x direction")
    param4 = Parameter("grid_size_y", unit="", comment="Grid size in y direction")
    parameters = Parameters([param1, param2, param3, param4])

    return parameters

CalculatorParameters = setCalculatorParameters(photon_energy=6e3, pulse_energy=1.0e-6, grid_size_x=128, grid_size_y=128)
calculator  = RandomImageCalculator(CalculatorParameters, output_path="out.h5")
shervin86 commented 2 years ago

I think we can start defining its json format and then we can write a toJson fromJson methods. I will try to draft their forms later

JunCEEE commented 2 years ago

We agree that we should have the parameters class in libpyvinyl.

JunCEEE commented 2 years ago

Hi @shervin86 and @mads-bertelsen, the instrument.json file generated by the parameters class which is going to be implemented in libpyvinyl here looks like this: https://gist.github.com/JunCEEE/94189879c3593d6511c30c5f57cd151e The parameters class is based on Mads's development. How do you like it?

mads-bertelsen commented 2 years ago

I am now back from vacation, happy to see the parameter system has proven useful and is being implemented into pyvinyl. I wrote it with the restriction that it should be easy to dump/read from json, but didn't actually write these methods. Didn't know about the dict method, seems like a really neat way to accomplish it!

shervin86 commented 2 years ago

Instrument database prototype available here: https://github.com/PaNOSC-ViNYL/instrument_database