Skip to content

Commit 2223012

Browse files
committed
Merge branch 'dev/main' into backup-before-filterrepo
2 parents 95afca3 + d041ab8 commit 2223012

29 files changed

+1262
-1007
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "dt4acc"
7-
version = "0.0.4"
7+
version = "0.1.0"
88
description = "digital twin for accelerators"
99
authors = [ "Waheedullah Sulaiman Khail", "Pierre Schnizer"]
1010
license = "GPL-3.0"

src/dt4acc/core/accelerators/accelerator_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,4 @@ def setup_event_subscriptions(self):
8181
self.accelerator.on_new_twiss.subscribe(self.view.push_twiss)
8282
self.accelerator.on_new_orbit.subscribe(self.view.push_orbit)
8383

84-
self.accelerator.on_new_orbit.subscribe(self.view.push_bpms)
8584
self.accelerator.on_changed_value.subscribe(self.view.push_value)

src/dt4acc/core/accelerators/element_proxies.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,48 @@ async def update(self, property_id: str, value, element_data):
165165

166166
await self.on_update_finished.trigger(None)
167167

168+
def peek(self, property_id: str) -> float:
169+
if property_id in ["K", "H", "main_strength"]:
170+
return self.peek_main_strength(property_id)
171+
elif property_id in ["x_kick", "y_kick"]:
172+
return self.peek_kick(property_id)
173+
elif property_id in ["frequency"]:
174+
return self.peek_frequency()
175+
else:
176+
raise NotImplementedError(
177+
f"handling property {property_id} not (yet) implemented"
178+
)
179+
180+
def peek_frequency(self):
181+
(element,) = self._obj
182+
return element.Frequency
183+
184+
def peek_main_strength(self, property_id: str):
185+
(element,) = self._obj
186+
element_type = element.__class__.__name__
187+
if element_type == "Quadrupole":
188+
assert property_id in ["K", "main_strength"]
189+
return element.K
190+
elif element_type == "Sextupole":
191+
if property_id not in ["H", "main_strength"]:
192+
raise AssertionError(
193+
f"Not handling {property_id} for element {element_type}"
194+
)
195+
return element.H
196+
else:
197+
raise NotImplementedError(
198+
f"main strength not implemented for element {element_type}"
199+
)
200+
201+
def peek_kick(self, property_id: str):
202+
(element,) = self._obj
203+
lut = dict(x_kick=0, y_kick=1)
204+
try:
205+
idx = lut[property_id]
206+
except KeyError as ke:
207+
raise AssertionError(f"Did not expect kick {property_id}")
208+
return element.KickAngle[idx]
209+
168210

169211

170212

src/dt4acc/core/bl/delay_execution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def request_execution(self):
3939
self.pending_task.cancel()
4040

4141
# Schedule a new execution task after the delay
42-
self.pending_task = asyncio.create_task(self._delayed_execution())
42+
self.pending_task = asyncio.create_task(self._delayed_execution(), name="delayed-execution")
4343

4444
async def _delayed_execution(self):
4545
"""
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from abc import ABCMeta, abstractmethod
2+
3+
4+
class ViewInterface(metaclass=ABCMeta):
5+
@abstractmethod
6+
async def push(self, data):
7+
"""
8+
"""
9+
raise NotImplementedError("use base class instead")

src/dt4acc/core/model/twiss.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,11 @@ def get_plane(self, plane: Planes):
4040
elif plane == Planes.y:
4141
return self.y
4242
else:
43-
raise AssertionError("How could I end up here")
43+
raise AssertionError("How could I end up here")
44+
45+
@dataclass
46+
class TuneData:
47+
"""extracted tune data for the tune device
48+
"""
49+
x: float
50+
y: float
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import asyncio
2+
import itertools
3+
4+
from .logger import get_logger
5+
from ..interfaces.view_interface import ViewInterface
6+
7+
#: use a "singleton", even if the name is not unique it should still work
8+
counter = itertools.count()
9+
logger = get_logger()
10+
11+
class PeriodicPublisher:
12+
"""
13+
14+
Todo:
15+
find a better name for it?
16+
Its rather a periodic publisher proxy
17+
18+
It is expected to be triggered from outside
19+
"""
20+
def __init__(self, view: ViewInterface, name: str):
21+
"""
22+
23+
Todo:
24+
view should cohere to a protocol or interface
25+
"""
26+
self.view = view
27+
self.data = None
28+
self.name = name
29+
30+
def set_data(self, data):
31+
self.data = data
32+
33+
async def publish(self):
34+
"""
35+
Expect that publish is called in parallel, thus just return stat object
36+
"""
37+
# name=f"publish-data-{self.name}-{next(counter)}"
38+
if self.data is None:
39+
logger.warning(f"{self.__class__.__name__}(name={self.name}), self.data is None, thus not publishing data")
40+
return
41+
return await self.view.push(self.data)

src/dt4acc/core/views/shared_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def get_view_instance():
2323
if server_type == "tango":
2424
from ...custom_tango.views.calculation_result_view import ResultView
2525
elif server_type == "epics":
26-
from ...custom_epics.views.calculation_result_view import ResultView
26+
from ...custom_epics.views.result_view import ResultView
2727
else:
2828
raise ValueError(f"Unsupported server type: {server_type}")
2929

src/dt4acc/custom_epics/ioc/handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from bact_twin_architecture.bl.command_rewriter import CommandRewriter
22
# from dt4acc.custom_epics.ioc.liasion_translation_manager import build_managers
3-
from p4p.client.asyncio import Context
43

54
from .liasion_translation_manager import build_managers
5+
from ..utils.context_proxy import ContextProxy
66
from ...core.accelerators.pyat_accelerator import setup_accelerator
77
from ...core.command import UpdateManager
88
from ...core.utils.logger import get_logger
99

1010
logger = get_logger()
1111

12-
ctx = Context("pva") # Create a context for EPICS PVA (PV Access)
12+
ctx = ContextProxy("pva") # Create a context for EPICS PVA (PV Access)
1313

1414
#: todo replace soon by database service
1515

src/dt4acc/custom_epics/ioc/pv_setup.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
LatticeElementPropertyID,
44
DevicePropertyID,
55
)
6-
from p4p.asLib.yacc import start
76

87
from .handlers import handle_device_update, update_manager
98
from ..data.constants import config, special_pvs, cavity_names
@@ -113,10 +112,10 @@ def add_pc_pvs(builder, pc_name, prefix):
113112
DevicePropertyID(device_name=pc_name, property="set_current")
114113
)
115114
start_val = np.asarray(vals).mean()
116-
rdbk = builder.aOut(f"{pc_name}:rdbk", initial_value=start_val)
115+
rdbk = builder.aOut(f"{pc_name}:rdbk", initial_value=start_val, PREC=2)
117116

118117
async def handle_pc_update(device_id: str, property_id: str, value: float):
119-
logger.debug("%s:%s updating setpoint val=%s", device_id, property_id, value)
118+
logger.warning("%s:%s updating setpoint val=%s", device_id, property_id, value)
120119
r = await handle_device_update(
121120
device_id=device_id, property_id=property_id, value=value
122121
)
@@ -128,6 +127,7 @@ async def handle_pc_update(device_id: str, property_id: str, value: float):
128127
f"{pc_name}:set",
129128
initial_value=start_val,
130129
on_update=lambda val: handle_pc_update(pc_name, "set_current", val),
130+
PREC = 2,
131131
)
132132

133133

@@ -147,6 +147,12 @@ def initialize_orbit_pvs(builder):
147147
builder.aOut(f"beam:orbit:found", initial_value=0)
148148

149149

150+
def initialize_tune_pvs(builder):
151+
for axis in ["x", "y"]:
152+
builder.aOut(f"TUNECC:{axis}", initial_value=0.0, PREC=9)
153+
builder.longOut(f"TUNECC:count", initial_value=0)
154+
155+
150156
def initialize_twiss_pvs(builder):
151157
"""
152158
Initializes PVs for Twiss parameters, which describe beam optics.

0 commit comments

Comments
 (0)