Skip to content

Commit d8dea43

Browse files
authored
Merge pull request #99 from python-accelerator-middle-layer/load-accelerator-from-other
Accelerator load functions
2 parents 0a3d11b + 9cf74c1 commit d8dea43

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ If you want to only tests for your machine and not develop, you shouldn't instal
1111

1212
Available packages for bindings:
1313

14-
TANGO: [tango-pyaml](https://github.com/python-accelerator-middle-layer/tango-pyaml)
14+
TANGO: [tango-pyaml](https://github.com/python-accelerator-middle-layer/tango-pyaml)
1515
TANGO or EPICS: [pyaml-cs-oa](https://github.com/python-accelerator-middle-layer/pyaml-cs-oa)
1616

1717
#### Developer Installation
@@ -29,17 +29,17 @@ TANGO or EPICS: [pyaml-cs-oa](https://github.com/python-accelerator-middle-layer
2929
pip install -e .
3030
```
3131
4. Install the development dependencies and pre-commit hooks
32-
32+
3333
```
3434
pip install -e .[dev]
3535
pre-commit install
3636
```
3737

3838
5. If you want to try the examples using the control system bindings you also need to install those. See:
3939

40-
TANGO: [tango-pyaml](https://github.com/python-accelerator-middle-layer/tango-pyaml)
40+
TANGO: [tango-pyaml](https://github.com/python-accelerator-middle-layer/tango-pyaml)
4141
TANGO or EPICS: [pyaml-cs-oa](https://github.com/python-accelerator-middle-layer/pyaml-cs-oa)
42-
42+
4343
6. If you want to run tests manually using the TANGO bindings without requiring a live machine you can also install the the Dummy TANGO control system available in tests/dummy-cs/tango. It is a simple emulation that allows to check the interface to the control system. The implemented control system doesn't do anything but it is only intended for tests during the development.
4444

4545

pyaml/accelerator.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ def live(self) -> ControlSystem:
123123
def design(self) -> Simulator:
124124
return self.__design
125125

126+
@staticmethod
127+
def from_dict(config_dict: dict, ignore_external=False) -> "Accelerator":
128+
"""
129+
Construct an accelerator from a dictionary.
130+
Parameters
131+
----------
132+
config_dict : str
133+
Dictionnary conatining accelerator config
134+
ignore_external: bool
135+
Ignore external modules and return None for object that
136+
cannot be created. pydantic schema that support that an
137+
object is not created should handle None fields.
138+
139+
"""
140+
if ignore_external:
141+
# control systems are external, so remove controls field
142+
config_dict.pop("controls", None)
143+
return Factory.depth_first_build(config_dict, ignore_external)
144+
126145
@staticmethod
127146
def load(
128147
filename: str, use_fast_loader: bool = False, ignore_external=False
@@ -151,8 +170,4 @@ def load(
151170
rootfolder = os.path.abspath(os.path.dirname(filename))
152171
set_root_folder(rootfolder)
153172
config_dict = load(os.path.basename(filename), None, use_fast_loader)
154-
if ignore_external:
155-
# control systems are external, so remove controls field
156-
config_dict.pop("controls", None)
157-
aml = Factory.depth_first_build(config_dict, ignore_external)
158-
return aml
173+
return Accelerator.from_dict(config_dict)

0 commit comments

Comments
 (0)