|
| 1 | +# dt4acc |
| 2 | + |
| 3 | +**Digital Twins for Accelerators (dt4acc)** is a Python package developed by the Helmholtz-Zentrum Berlin (HZB) to support digital twin modeling and control of particle accelerators. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Modular Architecture**: Clear separation between source code components. |
| 8 | +- **Modern Python Packaging**: Uses `pyproject.toml` for dependency management and build configuration. |
| 9 | +- **Open Source**: Licensed under the GNU General Public License v3.0 (GPL-3.0), encouraging collaboration and transparency. |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +Clone and install the package: |
| 14 | + |
| 15 | +```bash |
| 16 | +git clone https://github.com/hz-b/dt4acc.git |
| 17 | +cd dt4acc |
| 18 | +python3 -m venv venv |
| 19 | +source venv/bin/activate |
| 20 | +pip install -e . |
| 21 | +``` |
| 22 | + |
| 23 | +> **Note:** The `-e` flag installs the package in editable mode, which is useful during development. |
| 24 | +
|
| 25 | +## Usage |
| 26 | + |
| 27 | +Import the package in your scripts: |
| 28 | + |
| 29 | +```python |
| 30 | +import dt4acc |
| 31 | +``` |
| 32 | + |
| 33 | +### Running the Digital Twin with EPICS |
| 34 | + |
| 35 | +#### Required Environment Variables |
| 36 | + |
| 37 | +- `DT4ACC_PREFIX`: Prefix for all EPICS variables (e.g., `MyTwin`). |
| 38 | +- `MONGODB_URL`: MongoDB URI (e.g., `mongodb://localhost:47017/bessyii`). |
| 39 | +- `MONGODB_DB`: MongoDB database name (default: `bessyii`). |
| 40 | + |
| 41 | +### MongoDB Setup |
| 42 | + |
| 43 | +You can either install MongoDB manually or run it inside a container. |
| 44 | + |
| 45 | +#### Option A: Manual MongoDB Installation |
| 46 | + |
| 47 | +Follow the [lat2db](https://github.com/hz-b/lat2db) instructions to import your lattice into MongoDB. |
| 48 | + |
| 49 | +#### Option B: MongoDB Container |
| 50 | + |
| 51 | +Use a pre-built container from [bact-containers](https://github.com/hz-b/bact-containers/blob/main/recipes/mongo-container.sdef): |
| 52 | + |
| 53 | +```bash |
| 54 | +cd /twin_containers_data/bin |
| 55 | +apptainer run -B data/db/:/data/db ./mongo-container.sif |
| 56 | +``` |
| 57 | + |
| 58 | +This binds your host's data directory to the container's MongoDB volume. |
| 59 | + |
| 60 | +#### Importing Data into MongoDB |
| 61 | + |
| 62 | +With the container running, restore collections individually: |
| 63 | + |
| 64 | +```bash |
| 65 | +mongorestore --port 47017 --db bessyii --collection machines data/to_import/machines.bson |
| 66 | +mongorestore --port 47017 --db bessyii --collection accelerator.setup data/to_import/accelerator.bson |
| 67 | +mongorestore --port 47017 --db bessyii --collection bpm.config data/to_import/bpm_config.bson |
| 68 | +mongorestore --port 47017 --db bessyii --collection bpm.offset data/to_import/bpm_offset.bson |
| 69 | +``` |
| 70 | + |
| 71 | +Or restore the full database: |
| 72 | + |
| 73 | +```bash |
| 74 | +mongorestore --port 47017 --db bessyii data/to_import/bessyii |
| 75 | +``` |
| 76 | + |
| 77 | +### Running the Twin |
| 78 | + |
| 79 | +Set the environment variables: |
| 80 | + |
| 81 | +```bash |
| 82 | +export MONGODB_URL=mongodb://localhost:47017/bessyii |
| 83 | +export MONGODB_DB=bessyii |
| 84 | +export DT4ACC_PREFIX=MyTwin |
| 85 | +``` |
| 86 | + |
| 87 | +> Defaults: If unset, the prefix will default to `Anonym`, MongoDB URL to `localhost:27017`, and DB name to `bessyii`. |
| 88 | +
|
| 89 | +Start the twin server: |
| 90 | + |
| 91 | +```bash |
| 92 | +python src/dt4acc/custom_epics/ioc/server.py |
| 93 | +``` |
| 94 | + |
| 95 | +### Interact with the Twin |
| 96 | + |
| 97 | +Use EPICS command-line tools: |
| 98 | + |
| 99 | +```bash |
| 100 | +pvlist |
| 101 | +pvlist <hash> |
| 102 | +pvget <pv_name> |
| 103 | +pvput <pv_name> <value> |
| 104 | +``` |
| 105 | + |
| 106 | +### Containerized Twin |
| 107 | + |
| 108 | +You can also run the twin entirely in a container. See [bessyii_specifics.rst](https://github.com/hz-b/bact-containers/blob/main/doc/bessyii_specifics.rst) for more details. |
0 commit comments