Description, motivation and use case
The current configuration for many facilities is defined in MATLAB Middle Layer (MML) files (e.g., soleilinit.m). To integrate this configuration into our Python-based middle layer, we need to convert the MML configuration format into our pyAML YAML-based format. While the data itself (e.g., device names, sectors, ranges) is identical, the syntax and structure differ significantly between the two formats. This conversion is necessary to ensure an easy transition for MML users and to simplify the configuration process by giving an initial converted-from-MML config.
For example, the MML file contains blocks like:
% ElemList devlist tangoname status common
varlist = {
1 [1 1] 'DEV_BPM_001' 1 'BPM001'
2 [1 2] 'DEV_BPM_002' 1 'BPM002'
...
}
This should be converted to a pyAML YAML format like:
- type: pyaml.bpm.bpm
name: BPM_001
model:
type: pyaml.bpm.bpm_simple_model
x_pos: DEV_BPM_001/XPosSA
y_pos: DEV_BPM_001/ZPosSA
Proposed solution
Develop a robust Python script to:
- Parse the MML configuration file (
soleilinit.m) and extract device lists (BPMs, correctors, quadrupoles, sextupoles, etc.).
- Map the extracted data to the corresponding
pyAML YAML structure.
- Generate YAML files for devices, catalogs, arrays, and tuning tools.
- Ensure the script is maintainable and can handle future updates to the MML format.
It should be refined to:
- Handle edge cases (e.g., missing markers, malformed entries).
- Validate the parsed data against expected schemas.
- Support modular extensions for new device types.
Describe alternatives you've considered
Manual Conversion: Manually rewriting the MML configuration into YAML. This is error-prone, time-consuming, and difficult to maintain.
The proposed Python-based solution is preferred because it is self-contained, easier to debug, and aligns with our existing toolchain.
Example
For instance, it can look like:
def parse_bpm_varlist(block: str) -> list[dict]:
"""Parse BPM varlist rows from MATLAB code."""
pattern = re.compile(
r"""^\s*(\d+)\s+\[\s*(\d+)\s+(\d+)\s*\]\s*'([^']+)'\s+(\d+)\s+'(\w+)'""",
re.MULTILINE,
)
entries = []
for m in pattern.finditer(block):
entries.append({
"elem": int(m.group(1)),
"sector": int(m.group(2)),
"bpm_num": int(m.group(3)),
"device": m.group(4).strip(),
"status": int(m.group(5)),
"name": m.group(6).strip(),
})
return entries
This function parses BPM entries from the MML file and returns a list of dictionaries, which can then be converted to YAML.
Additional context
- The MML file (
soleilinit.m) contains configuration for all devices in the SOLEIL Storage Ring.
- The
pyAML format is used for our Python middle layer and requires specific YAML structures for devices, catalogs, arrays, and tuning tools.
- The script should be run from the
SOLEIL_SR_examples/ directory and output YAML files to the same directory.
- The current script lacks error handling, validation, and support for all device types.
Checklist
- I've assigned this issue to a project
- I've @-mentioned relevant people
Description, motivation and use case
The current configuration for many facilities is defined in MATLAB Middle Layer (MML) files (e.g.,
soleilinit.m). To integrate this configuration into our Python-based middle layer, we need to convert the MML configuration format into ourpyAMLYAML-based format. While the data itself (e.g., device names, sectors, ranges) is identical, the syntax and structure differ significantly between the two formats. This conversion is necessary to ensure an easy transition for MML users and to simplify the configuration process by giving an initial converted-from-MML config.For example, the MML file contains blocks like:
This should be converted to a
pyAMLYAML format like:Proposed solution
Develop a robust Python script to:
soleilinit.m) and extract device lists (BPMs, correctors, quadrupoles, sextupoles, etc.).pyAMLYAML structure.It should be refined to:
Describe alternatives you've considered
Manual Conversion: Manually rewriting the MML configuration into YAML. This is error-prone, time-consuming, and difficult to maintain.
The proposed Python-based solution is preferred because it is self-contained, easier to debug, and aligns with our existing toolchain.
Example
For instance, it can look like:
This function parses BPM entries from the MML file and returns a list of dictionaries, which can then be converted to YAML.
Additional context
soleilinit.m) contains configuration for all devices in the SOLEIL Storage Ring.pyAMLformat is used for our Python middle layer and requires specific YAML structures for devices, catalogs, arrays, and tuning tools.SOLEIL_SR_examples/directory and output YAML files to the same directory.Checklist