Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
8139911
Make waveform val arrays consistent across csv files
ptsOSL Jul 8, 2025
55db415
Rename csv headings and add scan column
ptsOSL Jul 15, 2025
65539d8
Remove refresh records
ptsOSL Jul 15, 2025
48ed25e
Improve tunefb csv file headings
ptsOSL Jul 9, 2025
3d3ef67
Add PVs attached to lattice to limits csv file
ptsOSL Jul 9, 2025
b2903f0
Check that a new PV is not already in the csv files
ptsOSL Jul 15, 2025
bb13697
Add scan col to limits.csv and update heading names
ptsOSL Jul 15, 2025
edb3485
Add latest generated csv files
ptsOSL Jul 15, 2025
e95f648
Improve use of numpy printoptions
ptsOSL Jul 17, 2025
635ca33
Refactor generate_pv_limits and do cagets async
ptsOSL Jul 18, 2025
d1c779c
Improve type hinting
ptsOSL Jul 16, 2025
beace34
Specify epicscorelibs version to avoid issue in library
ptsOSL Jul 17, 2025
ad5908c
Remove python3.13 from ci and toml file
ptsOSL Jul 18, 2025
37c8169
Added PV class
ptsOSL Jul 21, 2025
ee8d10c
Remove unused python files and update __init__.py
ptsOSL Jul 21, 2025
920d1d1
Rename enable_emittance and add enable_tunefb bool
ptsOSL Jul 21, 2025
a92544a
Implement PV classes for pv configuration
ptsOSL Jul 21, 2025
816f607
Refactor method to enable/disable PV monitoring
ptsOSL Jul 21, 2025
eaf1ce9
Update some docstrings and type hinting
ptsOSL Jul 21, 2025
16449f0
Add method to print info about virtac
ptsOSL Jul 21, 2025
da08a9d
Move on_update method to PV classes
ptsOSL Jul 21, 2025
7052e09
Minor code comment and print statement changes
ptsOSL Jul 21, 2025
a7c1590
Add checks to RecordData for invalid dtypes
ptsOSL Jul 31, 2025
db407c9
Also check if the monitored PV is a CaPV
ptsOSL Jul 31, 2025
83ad9d8
Pass a valid default dtype for SCAN
ptsOSL Jul 31, 2025
3eed9f7
Make the virtac print virtac stats by default
ptsOSL Jul 31, 2025
c32ffb6
Refactor ca config into its own func
ptsOSL Aug 4, 2025
7bcae61
Bump python and atip versions
ptsOSL Aug 4, 2025
3a901ab
Remove python3.10 and add py3.13 to CI
ptsOSL Aug 4, 2025
61ae8a0
Rework how MonitorPV is configured
ptsOSL Aug 4, 2025
dbb49be
Refactored MonitorPV setup_pv_monitoring
ptsOSL Aug 4, 2025
5984e21
Switch on tunefb by default and rename args
ptsOSL Aug 5, 2025
bb88eec
Fix type checker errors
ptsOSL Aug 5, 2025
d9c44d7
No longer fail docs build on warning
ptsOSL Aug 6, 2025
8328c50
Remove deleted files from __init__.py
ptsOSL Aug 6, 2025
b565dd5
Fix some docstrings, logging and exception strings
ptsOSL Aug 6, 2025
a9c6df8
Remove redundant Interim PV
ptsOSL Aug 6, 2025
4423d2f
Split waveform records between in & out waveforms
ptsOSL Aug 6, 2025
54a7c66
Correct SCAN types
ptsOSL Aug 6, 2025
2059a9f
Update logging and docstrings
ptsOSL Aug 7, 2025
739973d
Fix bug with setup_pv_monitoring
ptsOSL Aug 7, 2025
a84295a
Remove redundant issubclass checks
ptsOSL Aug 7, 2025
a582b36
Replace toggle monitoring with enable/disable
ptsOSL Aug 7, 2025
02650dc
Improve typing and docstrings
ptsOSL Aug 7, 2025
54567bd
Remove unused CaPV
ptsOSL Aug 7, 2025
03e0f5c
Fix CollatePV and InvertPV callbacks
ptsOSL Aug 7, 2025
8bdb631
Move where the pytac lattice is set
ptsOSL Aug 8, 2025
d10fca0
Remove pypi from copier config and CI
ptsOSL Aug 8, 2025
246f9d3
Implement enums for record types and mirror PVs
ptsOSL Aug 12, 2025
911e397
Reduce code in print_virtac_stats
ptsOSL Aug 12, 2025
26786aa
Change PV baseclass and move pytac attributes to new subclass
ptsOSL Aug 12, 2025
4cdaa83
Merge Offset and Setpoint classes into ProxyPV
ptsOSL Aug 12, 2025
d3b1e99
Change MonitorPV and subclasses for clarity and improved index handling
ptsOSL Aug 12, 2025
5f7445a
Slim down core PV creation using new PV class changes
ptsOSL Aug 12, 2025
f4928d7
Remove most code from update_pvs
ptsOSL Aug 12, 2025
139499e
Misc docstring improvements and fixes from PV class changes
ptsOSL Aug 12, 2025
e7b08ca
Remove unused function: set_feedback_record
ptsOSL Aug 12, 2025
8fd76d8
Update logging
ptsOSL Aug 12, 2025
b21e0b1
Remove ProxyPV
ptsOSL Aug 12, 2025
982284c
Remove python 3.10 and fix min atip version
ptsOSL Aug 12, 2025
06f17ae
Fix CLI bugs
ptsOSL Aug 22, 2025
454b89e
Fix bug when enabling/disabling monitoring
ptsOSL Aug 22, 2025
ae87fac
Refactor code for creating element pvs
ptsOSL Aug 22, 2025
5b797a7
Renamed variables in tunefb setup for readability
ptsOSL Aug 22, 2025
351aeff
Updates to docstrings and log messages from code review
ptsOSL Aug 22, 2025
18d5a2e
Use existing pv name list for creating MonitorPVs
ptsOSL Aug 22, 2025
d9d7b0f
Removed unneeded func to get pytac data
ptsOSL Aug 22, 2025
9e83dee
Make verbosity more standard
ptsOSL Sep 5, 2025
68ac599
Merge branch 'dev' into virtac-refactor-rebased
ptsOSL Sep 5, 2025
540dcde
Merge pull request #8 from DiamondLightSource/virtac-refactor-rebased
ptsOSL Sep 5, 2025
aba87e0
Update DIAD csv files
ptsOSL Sep 5, 2025
ecd1917
Set the default data source to pytac.SIM
ptsOSL Sep 8, 2025
4b7f9f8
Change how we import our own modules
ptsOSL Sep 8, 2025
671f77a
Fix for incompatible pytac version
ptsOSL Sep 8, 2025
bcc45eb
Add create_csv as entrypoint
ptsOSL Sep 8, 2025
fc216d0
Improve docstrings and rename some variables for clarity
ptsOSL Sep 8, 2025
795f77d
Make github pages update from the docs branch
ptsOSL Sep 8, 2025
27f1a16
Rework the docs in tutorials
ptsOSL Sep 8, 2025
74df41b
Add the ability to print the output of commands to docs
ptsOSL Sep 8, 2025
e4839dc
Add a file explaining how to update the csv file
ptsOSL Sep 8, 2025
ecdd0af
Add a proper main function to create_csv.py
ptsOSL Sep 8, 2025
27ad212
Minor documentation improvements
ptsOSL Sep 17, 2025
b1ecdbd
Improve docs, adding detail and clarifications
ptsOSL Sep 19, 2025
ee1eda2
Make docs build from dev branch instead of docs
ptsOSL Sep 19, 2025
7ed883a
Update README.md
ptsOSL Sep 22, 2025
a0d6fdb
Merge pull request #10 from DiamondLightSource/docs
ptsOSL Sep 22, 2025
308d7c0
Update to latest copier template
ptsOSL Sep 22, 2025
6a19df4
Clarify use of dev branch
ptsOSL Sep 23, 2025
afb51e9
Fix function return type hinting
ptsOSL Sep 23, 2025
8363331
Add type casting in various places
ptsOSL Sep 23, 2025
c67ce62
Created CallbackType for improved type hinting
ptsOSL Sep 24, 2025
283e8c3
Improve limits_dict type hinting and convert to str
ptsOSL Sep 24, 2025
9ba39f9
Correct type hinting from str to pathlib.Path
ptsOSL Sep 24, 2025
bbadde1
Remove unnecessary type assertions
ptsOSL Sep 24, 2025
d2abbe5
Check if variable exists instead of is not none
ptsOSL Sep 24, 2025
f274825
Fix bug in InversionPVs callback
ptsOSL Sep 24, 2025
9fe30ab
Remove inaccessible check for tune_csv being None
ptsOSL Sep 24, 2025
ba36814
Pass an element list instead of a single element to ReadSimPV
ptsOSL Sep 24, 2025
9cce757
Remaining misc type hint improvements
ptsOSL Sep 24, 2025
2aa611e
Remove unneeded commas to improve readability
ptsOSL Sep 25, 2025
236b776
Merge pull request #12 from DiamondLightSource/type-hinting-fixes
ptsOSL Sep 26, 2025
c984453
Remove dupe docstring type hints
ptsOSL Sep 29, 2025
aee9ece
Add getter and setter for _record
ptsOSL Sep 29, 2025
e547546
Rename the PV class set/get funcs
ptsOSL Sep 29, 2025
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: 3 additions & 2 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 4.0.1
_commit: 4.3.0
_src_path: gh:DiamondLightSource/python-copier-template
author_email: tobyn.nicholls@diamond.ac.uk
author_name: Tobyn Nicholls
Expand All @@ -9,10 +9,11 @@ component_type: service
description: Diamond virtual accelerator
distribution_name: virtac
docker: true
docker_debug: false
docs_type: sphinx
git_platform: github.com
github_org: DiamondLightSource
package_name: virtac
pypi: true
pypi: false
repo_name: virtac
type_checker: mypy
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ It is recommended that developers use a [vscode devcontainer](https://code.visua

This project was created using the [Diamond Light Source Copier Template](https://github.com/DiamondLightSource/python-copier-template) for Python projects.

For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/4.0.1/how-to.html).
For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/4.3.0/how-to.html).
2 changes: 1 addition & 1 deletion .github/workflows/_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
run: python .github/pages/make_switcher.py --add $DOCS_VERSION ${{ github.repository }} .github/pages/switcher.json

- name: Publish Docs to gh-pages
if: github.ref_type == 'tag' || github.ref_name == 'main'
if: github.ref_type == 'tag' || github.ref_name == 'main' || github.ref_name == 'dev'
# We pin to the SHA, not the tag, for security reasons.
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
Expand Down
19 changes: 0 additions & 19 deletions .github/workflows/_pypi.yml

This file was deleted.

8 changes: 1 addition & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@ jobs:

dist:
uses: ./.github/workflows/_dist.yml

pypi:
needs: [dist, test]
if: github.ref_type == 'tag'
uses: ./.github/workflows/_pypi.yml
permissions:
id-token: write


release:
needs: [dist, test, docs]
Expand Down
17 changes: 15 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The devcontainer should use the developer target and run as root with podman
# or docker with user namespaces.
ARG PYTHON_VERSION=latest
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION} AS developer

# Add any system dependencies for the developer/build environment here
Expand All @@ -14,8 +14,21 @@ COPY . /virtac/
# Set up a virtual environment and put it in PATH
RUN python -m venv /venv
ENV PATH=/venv/bin:$PATH
RUN pip install .
ENV EPICS_CA_SERVER_PORT=8064
ENV EPICS_CA_REPEATER_PORT=8065

# The build stage installs the context into the venv
FROM developer AS build
# Requires buildkit 0.17.0
COPY --chmod=o+wrX . /workspaces/virtac
WORKDIR /workspaces/virtac
RUN touch dev-requirements.txt && pip install -c dev-requirements.txt .

# The runtime stage copies the built venv into a slim runtime container
FROM python:${PYTHON_VERSION}-slim AS runtime
# Add apt-get system dependecies for runtime here if needed
COPY --from=build /venv/ /venv/
ENV PATH=/venv/bin:$PATH
ENV EPICS_CA_SERVER_PORT=8064
ENV EPICS_CA_REPEATER_PORT=8065

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[![CI](https://github.com/DiamondLightSource/virtac/actions/workflows/ci.yml/badge.svg)](https://github.com/DiamondLightSource/virtac/actions/workflows/ci.yml)
[![Coverage](https://codecov.io/gh/DiamondLightSource/virtac/branch/main/graph/badge.svg)](https://codecov.io/gh/DiamondLightSource/virtac)
[![PyPI](https://img.shields.io/pypi/v/virtac.svg)](https://pypi.org/project/virtac)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)

# virtac
Expand All @@ -12,10 +11,11 @@ This module contains all of the diamond specific configuration to build the diam

Source | <https://github.com/DiamondLightSource/virtac>
:---: | :---:
PyPI | `pip install virtac`
Docker | `docker run ghcr.io/diamondlightsource/virtac:latest`
Docker | `docker run -it --network=host ghcr.io/diamondlightsource/virtac:latest`
Documentation | <https://diamondlightsource.github.io/virtac>
Installation | <https://diamondlightsource.github.io/virtac/tutorials/installation>
Releases | <https://github.com/DiamondLightSource/virtac/releases>

<!-- README only content. Anything below this line won't be included in index.md -->

The github pages documentation is automatically updated on pushes to the main and dev branches and also on tagged releases.
14 changes: 7 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"sphinx_design",
# So we can write markdown files
"myst_parser",
# For autodocumenting argparse based CLIs
"sphinxcontrib.programoutput",
]

# So we can use the ::: syntax
Expand All @@ -74,6 +76,8 @@
("py:class", "number"),
("py:class", "pythonSoftIoc.RecordWrapper"),
("py:class", "pytac.lattice.Lattice"),
("py:class", "pytac.element.Element"),
("py:class", "CSVData"),
("py:exc", "pytac.FieldException"),
("py:exc", "pytac.ControlSystemException"),
("py:exc", "pytac.HandleException"),
Expand Down Expand Up @@ -129,6 +133,8 @@
# docs in the python documentation.
intersphinx_mapping = {"python": ("https://docs.python.org/3/", None)}

intersphinx_disabled_reftypes = ["*"]

# A dictionary of graphviz graph attributes for inheritance diagrams.
inheritance_graph_attrs = {"rankdir": "TB"}

Expand Down Expand Up @@ -174,13 +180,7 @@
},
"use_edit_page_button": True,
"github_url": f"https://github.com/{github_user}/{github_repo}",
"icon_links": [
{
"name": "PyPI",
"url": f"https://pypi.org/project/{project}",
"icon": "fas fa-cube",
}
],
"icon_links": [{}],
"switcher": {
"json_url": switcher_json,
"version_match": version,
Expand Down
12 changes: 12 additions & 0 deletions docs/how-to/update_csv_files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Update CSV Files

Use the CLI to recreate the csv files. This runs create_csv.py and reads data from PVs on port 5064, so ensure you have configured your CA ports to 50XX.

You can run create_csv with the default arguments and the correct ringmode, eg:

:::{code-block} bash
create_csv I04
:::

```{program-output} create_csv -h
```
3 changes: 1 addition & 2 deletions docs/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ Tutorials for installation and typical usage. New users start here.
:maxdepth: 1
:glob:

tutorials/installation
tutorials/virtac_example
tutorials/*
```
76 changes: 76 additions & 0 deletions docs/tutorials/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Overview

## What is the Virtac?

The Diamond Virtual Accelerator (Virtac for short) was created to simulate the high level controls interface to the real accelerator, mostly the storage ring. There are three main parts:

1. An EPICS IOC which aims to faithfully reproduce the PVs available on the real machine and their behavior.
2. A pytac lattice which contains the same elements (dipoles, quadrupoles, etc) as the real machine and is updated via the aforementioned PV interface.
3. A pyAT simulation which is updated from the pytac lattice and indirectly from the Virtac PV interface.

### 1. PV interface

The Virtac provides over 4000 PVs which allow you to control the Virtac and to read information about it using channel access. We use [PythonSoftIOC](https://diamondlightsource.github.io/pythonSoftIOC/master/tutorials/creating-an-ioc.html) to create the EPICS IOC. We use information from pytac (which in turn derives its data from matlab middlelayer) in addition to information contained in csv files to create PVs. The data in our csv files is largely created by reading PVs from the real machine, with some manually generated configuration.

### 2. Pytac lattice

[Pytac](https://pytac.readthedocs.io/en/latest/) is used to define the lattice which describes the layout of the storage ring. The lattice tracks over 2000 elements, including different types of dipoles, quadrupoles, sextupoles, drifts and bpms.

Pytac supports many lattice modes, but the Virtac currently supports just three: 'DIAD', 'I04' and the Diamond 2 ringmode, '48'.

### 3. pyAT simulation

[pyAT](https://atcollab.github.io/at/p/index.html) is used to simulate the physics inside the particle accelerator. More specifically, we mostly use pyAT to simulate the path of a single electron around the storage ring. pyAT also contains a lattice, this is linked to and configured from the pytac lattice.

Our main use-case of pyAT is to allow modifications of the lattice (such as setting magnet currents via the PV interface) and then calculating how these modifications affect the reference orbit of an electron travelling around the storage ring. This core premise allows us to test certain feedback algorithms against the Virtac by setting magnet currents, then reading bpm positions and repeating until we find an idealized orbit.

### What can currently be tested against the Virtac?

Currently the Virtac only simulates the storage ring, but this may change in the future.

The main use-case is IOCs which write to magnet current PVs and then need to see what effect this has on the ring.

We simulate the following magnet families:
- Bends
- Quadrupoles
- Skew quadrupoles
- Horizontal and vertical steerers/correctors
- Horizontal and vertical ID trim coils
- Chicanes
- Sextupoles
- Octupoles (for Diamond 2)
- Combined dipole-quadrupoles (for Diamond 2)
- Anti-bend dipoles (for Diamond 2)

We simulate the following ring parameters and provide them as PVs:
- BPM positions
- Emittance
- Tune

Some of the things that we dont simulate:
- The linac
- The booster ring
- The transfer lines
- Particle injection
- Bunches
- Electrons outside of the reference orbit
- Beam decay
- Insertion devices (only the trim coils for ID corrections are simulated)

With the default settings, the simulation can only be recalculated at a maximum rate of:
- Approximately 2Hz for Diamond 1
- Approximately 0.7Hz for Diamond 2

### Apps currently being tested against the Virtac

- Slow orbit feedback
- Tune feedback
- Vertical emittance feedback
- Response matrix calculation

### Future plans

- Allow the Virtac to be run using the Diamond II lattice configuration
- Simulate the booster to storage ring transfer line
- Simulate electrons which do not follow the reference orbit, ie by giving them a non-zero initial position in the beam tube.
- Reduce the simulation recalculation delay
113 changes: 113 additions & 0 deletions docs/tutorials/using_virtac.md

Large diffs are not rendered by default.

Loading