Skip to content

Commit

Permalink
moved XFELInterface to xfel folder. Minor update of readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-tomin committed Mar 20, 2019
1 parent cd2160e commit 8c4c241
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 14 deletions.
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,33 @@ Ocelot Optimizer was designed to cover as many as possible
## How to get started

* Download @GitHub: https://github.com/ocelot-collab/optimizer

* Try “simulation” interface and test different optimization methods:
>> python generic_optim.py MultinormalInterface
* to ask help:
>> python generic_optim.py --help
* Edit template machine interface to map in your control system:
- DemoInterface (path optimizer/mint/demo/demo_interface.py)
** Guys can we extend a bit DemoInterface and add more details. I actually would be also interested to see what options LCLSMachineInterface has**
* Edit template machine interface to map in your control system:
- [DemoInterface](mint/demo/demo_interface.py)
>> python generic_optim.py MultinormalInterface
```python
class DemoInterface(MachineInterface):
name = 'DemoInterface'

def __init__(self, args=None):
super(DemoInterface, self).__init__(args=args)
self.config_dir = os.path.join(self.config_dir, "demo") # <ocelot>/parameters/demo

# self.config_dir is path to a directory where a default config will be saved (the tool state)
# self.config_dir = "<optimizer>/parameters/" is default path in the parent class MachineInterface
self.config_dir = os.path.join(self.config_dir, "demo") # <optimizer>/parameters/demo

# self.path2jsondir is a path to a folder where optimization histories will be saved in json format
# by default self.path2jsondir = <data> on the same level that <optimizer>
# the folder will be created automatically

# flag from LCLSInterface which not allow Optimizer to write to control system
self.read_only = False

def get_value(self, channel):
Expand All @@ -89,4 +100,13 @@ class DemoInterface(MachineInterface):
def set_value(self, channel, val):
print("Called set_value for channel: {}, with value: {}".format(channel, val))

```
```

As a second step we recommend to have a look to XFELMachineInterface (<optimizer>/min/xfel/xfel_interface.py)
and also [TestMachineInterface](min/xfel/xfel_interface.py)
which you can run using:

>> python generic_optim.py --devmode

See the parent class [MachineInterface](mint/opt_objects.py) to have more configurable options.
12 changes: 10 additions & 2 deletions mint/demo/demo_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ class DemoInterface(MachineInterface):

def __init__(self, args=None):
super(DemoInterface, self).__init__(args=args)
self.config_dir = os.path.join(self.config_dir,
"demo") # <ocelot>/parameters/demo

# self.config_dir is path to a directory where a default config will be saved (the tool state)
# self.config_dir = "<optimizer>/parameters/" is default path in the parent class MachineInterface
self.config_dir = os.path.join(self.config_dir, "demo") # <optimizer>/parameters/demo

# self.path2jsondir is a path to a folder where optimization histories will be saved in json format
# by default self.path2jsondir = <data> on the same level that <optimizer>
# the folder will be created automatically

# flag from LCLSInterface which not allow Optimizer to write to control system
self.read_only = False

def get_value(self, channel):
Expand Down
Empty file added mint/xfel/__init__.py
Empty file.
9 changes: 4 additions & 5 deletions mint/xfel_interface.py → mint/xfel/xfel_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import numpy as np
import subprocess
import base64
from threading import Lock
from mint.opt_objects import MachineInterface, Device
from collections import OrderedDict

Expand All @@ -40,9 +39,8 @@ def __init__(self, args=None):
print('error importing doocs library')
self.logbook_name = "xfellog"

path2root = os.path.abspath(os.path.join(__file__ , "../../.."))
path2root = os.path.abspath(os.path.join(__file__ , "../../../.."))
self.config_dir = os.path.join(path2root, "config_optim_new")

def get_value(self, channel):
"""
Getter function for XFEL.
Expand Down Expand Up @@ -133,7 +131,7 @@ def send_to_logbook(self, *args, **kwargs):
return succeded

def get_obj_function_module(self):
from mint import xfel_obj_function
from mint.xfel import xfel_obj_function
return xfel_obj_function

def get_preset_settings(self):
Expand Down Expand Up @@ -207,6 +205,7 @@ def __init__(self, args):
super(TestMachineInterface, self).__init__(args)
self.data = 1.
pass

def get_alarms(self):
return np.random.rand(4)#0.0, 0.0, 0.0, 0.0]

Expand Down Expand Up @@ -272,7 +271,7 @@ def send_to_logbook(*args, **kwargs):
return True

def get_obj_function_module(self):
from mint import xfel_obj_function
from mint.xfel import xfel_obj_function
return xfel_obj_function


File renamed without changes.
8 changes: 6 additions & 2 deletions sint/multinormal/multinormal_obj_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, mi=None, eid='sim_objective'):
self.points = None
self.initialize = True


def get_penalty(self):
sase, std, charge, current, losses = self.get_value()
alarm = self.get_alarm()
Expand Down Expand Up @@ -67,10 +68,10 @@ def get_value(self):
if self.points is None:
self.points = 120
self.mi.points = self.points
print("Get Value of : ", self.points, " points.")
# print("Get Value of : ", self.points, " points.")

data = self.mi.f(self.mi.x)
print("Data (", data.shape, ") : ", data)
# print("Data (", data.shape, ") : ", data)

if self.stats is None:
self.stats = stats.StatNone
Expand All @@ -97,3 +98,6 @@ def clean(self):
self.charge = []
self.current = []
self.losses = []

def get_energy(self):
return 7 # GeV

0 comments on commit 8c4c241

Please sign in to comment.