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

feature: xfel sase launch environments #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions environments/xfel_sase1_launch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# XFEL_SASE1 Environment for Badger

## Prerequisites

## Usage
80 changes: 80 additions & 0 deletions environments/xfel_sase1_launch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import time
import numpy as np
from badger import environment
from badger.interface import Interface
from badger.factory import get_intf


class Environment(environment.Environment):

name = 'XFEL Sase1 Launch'

def __init__(self, interface: Interface, params):
super().__init__(interface, params)

# set interface according to params
try:
new_interface, _ = get_intf(params['interface'])
self.interface = new_interface()
except KeyError:
print(f'Cannot load interface defined in params')

self.limits_undulators = {}
aircoil_list = ["XFEL.MAGNETS/MAGNET.ML/QF.2162.T2/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2177.T2/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2192.T2/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2207.T2/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2218.T2/CURRENT.SP"
]
for addr in aircoil_list:
self.limits_undulators[addr] = [20, 60]


def _get_vrange(self, var):
return self.limits_undulators[var]

@staticmethod
def list_vars():
return ["XFEL.MAGNETS/MAGNET.ML/QF.2162.T2/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2177.T2/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2192.T2/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2207.T2/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2218.T2/CURRENT.SP"
]


# TODO: add losses
@staticmethod
def list_obses():
return ['sases_average']

@staticmethod
def get_default_params():
return {
'waiting_time': 15,
'interface': 'doocs'
}

def _get_var(self, var):
return self.interface.get_value(var)

def _set_var(self, var, x):
self.interface.set_value(var, x)

def _get_obs(self, obs):
try:
dt = self.params['waiting_time']
except KeyError:
dt = 0
time.sleep(dt)



if obs == 'sases_average':
values = []
for i in range(30):
sa1 = self.interface.get_value(
"XFEL.FEL/XGM/XGM.2643.T9/INTENSITY.SA1.RAW.TRAIN")
values.append(sa1)
time.sleep(0.1)
return np.mean(values)
8 changes: 8 additions & 0 deletions environments/xfel_sase1_launch/configs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: xfel_sase1
version: "0.1"
dependencies:
- numpy
- badger-opt
interface:
- doocs
5 changes: 5 additions & 0 deletions environments/xfel_sase2_launch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# XFEL_SASE1 Environment for Badger

## Prerequisites

## Usage
88 changes: 88 additions & 0 deletions environments/xfel_sase2_launch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import time
import numpy as np
from badger import environment
from badger.interface import Interface
from badger.factory import get_intf


class Environment(environment.Environment):

name = 'XFEL Sase2 Launch'

def __init__(self, interface: Interface, params):
super().__init__(interface, params)

# set interface according to params
try:
new_interface, _ = get_intf(params['interface'])
self.interface = new_interface()
except KeyError:
print(f'Cannot load interface defined in params')

self.limits_undulators = {}
aircoil_list = [
"XFEL.MAGNETS/MAGNET.ML/QF.2083.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2098.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2110.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2124.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2139.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2153.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2168.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2180.T1/CURRENT.SP"
]
for addr in aircoil_list:
self.limits_undulators[addr] = [20, 60]


def _get_vrange(self, var):
return self.limits_undulators[var]

@staticmethod
def list_vars():
return [
"XFEL.MAGNETS/MAGNET.ML/QF.2083.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2098.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2110.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2124.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2139.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2153.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2168.T1/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2180.T1/CURRENT.SP"
]


# TODO: add losses
@staticmethod
def list_obses():
return ['sases_average']

@staticmethod
def get_default_params():
return {
'waiting_time': 15,
'interface': 'doocs'
}

def _get_var(self, var):
return self.interface.get_value(var)

def _set_var(self, var, x):
self.interface.set_value(var, x)

def _get_obs(self, obs):
try:
dt = self.params['waiting_time']
except KeyError:
dt = 0
time.sleep(dt)



if obs == 'sases_average':
values = []
for i in range(30):
sa = self.interface.get_value(
"XFEL.FEL/XGM/XGM.2595.T6/INTENSITY.RAW.TRAIN")
values.append(sa)
time.sleep(0.1)
return np.mean(values)
14 changes: 14 additions & 0 deletions environments/xfel_sase2_launch/configs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
---
name: xfel_sase2_launch
version: "0.1"
dependencies:
- numpy
- badger-opt
interface:
- doocs
- doocs_mock
- doocs_real2sim
params:
- waiting_time: 1
- interface: doocs
5 changes: 5 additions & 0 deletions environments/xfel_sase3_launch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# XFEL_SASE1 Environment for Badger

## Prerequisites

## Usage
81 changes: 81 additions & 0 deletions environments/xfel_sase3_launch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import time
import numpy as np
from badger import environment
from badger.interface import Interface
from badger.factory import get_intf


class Environment(environment.Environment):

name = 'XFEL Sase2 Launch'

def __init__(self, interface: Interface, params):
super().__init__(interface, params)

# set interface according to params
try:
new_interface, _ = get_intf(params['interface'])
self.interface = new_interface()
except KeyError:
print(f'Cannot load interface defined in params')

self.limits_undulators = {}
aircoil_list = [
"XFEL.MAGNETS/MAGNET.ML/QF.2749.T4/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2761.T4/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2773.T4/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2785.T4/CURRENT.SP"
]

for addr in aircoil_list:
self.limits_undulators[addr] = [20, 60]


def _get_vrange(self, var):
return self.limits_undulators[var]

@staticmethod
def list_vars():
return [
"XFEL.MAGNETS/MAGNET.ML/QF.2749.T4/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2761.T4/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2773.T4/CURRENT.SP",
"XFEL.MAGNETS/MAGNET.ML/QF.2785.T4/CURRENT.SP"
]


# TODO: add losses
@staticmethod
def list_obses():
return ['sases_average']

@staticmethod
def get_default_params():
return {
'waiting_time': 15,
'interface': 'doocs'
}

def _get_var(self, var):
return self.interface.get_value(var)

def _set_var(self, var, x):
self.interface.set_value(var, x)

def _get_obs(self, obs):
try:
dt = self.params['waiting_time']
except KeyError:
dt = 0
time.sleep(dt)



if obs == 'sases_average':
values = []
for i in range(30):
sa = self.interface.get_value(
"XFEL.FEL/XGM/XGM.3130.T10/INTENSITY.SA3.RAW.TRAIN")
values.append(sa)
time.sleep(0.1)
return np.mean(values)
14 changes: 14 additions & 0 deletions environments/xfel_sase3_launch/configs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
---
name: xfel_sase3_launch
version: "0.1"
dependencies:
- numpy
- badger-opt
interface:
- doocs
- doocs_mock
- doocs_real2sim
params:
- waiting_time: 1
- interface: doocs