Skip to content

Diamond2 conversion2 - #5

Open
ptsOSL wants to merge 22 commits into
mainfrom
diamond2-conversion2
Open

ptsOSL wants to merge 22 commits into
mainfrom
diamond2-conversion2

Conversation

@ptsOSL

@ptsOSL ptsOSL commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator
  • Backwards compatible with D1
  • Adds support for D2 ringmode 49 and 48
  • Add --d2 CLI option which switches between D1 and D2 ringmodes. When running with --d2 you get access to 49 and 48 and when running without it, you get the old ringmodes.
  • Handle both old and new tune response matrix matlab data formats
  • Refactor setting up tunefb startup_currents and make sure this setup is called both when the server is first initialised and on ringmode change.

@ptsOSL
ptsOSL force-pushed the diamond2-conversion2 branch 2 times, most recently from 401d8cf to e4a1f2a Compare September 15, 2026 14:18
Rather than constructing the RM in the order defined
in the mml tuneRM file, we do it in the order defined
in tunefb_offsets.py
We now find our config files from either diamond2opsdata
or diamondopsdata depending on the ringmode
@ptsOSL
ptsOSL force-pushed the diamond2-conversion2 branch from fa5051a to 4e03ab6 Compare September 16, 2026 10:54
This ensures the caputs complete before continuing and anecdotally
has been seen to improve results against the Virtac which responds much
slower than the real machine.
When running in D2 mode, you get different ringmodes to choose
which load different lattices and make different PVs
@ptsOSL
ptsOSL force-pushed the diamond2-conversion2 branch from 4e03ab6 to 4bdbe8a Compare September 16, 2026 11:00
@ptsOSL ptsOSL changed the title Draft: Diamond2 conversion2 Diamond2 conversion2 Sep 16, 2026
Comment thread src/dls_slow_feedbacks/tunefb_server.py Outdated
# that they are ordered in the same order as defined elsewhere.
for family in families:
for rmat in raw_rms["Rmat"][0]:
rmat_family = str(rmat["Actuator"][0][0][0][0][1][0])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list of indices seems a bit confusing, just reply to this comment explaining it so I can see whether it's worth hiding or not.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the structure we get when loading the matlab file:

[[array([[(array([[107.11158457],
[107.11158457],
[107.11158457],
[107.11158457],
[107.11158457],
[107.11158457],
[107.11158457],
[107.11158457],
[107.11158457],
[107.11158457],
[107.11158457],
[107.11158457]]), array(['Q0L'], dtype='<U3'), array(['Setpoint'], dtype='<U8'), array([[ 1, 1],
[ 4, 17],
[ 5, 1],
[ 8, 17],
[ 9, 1],
[12, 17],
[13, 1],
[16, 17],
[17, 1],
[20, 17],
[21, 1],
[24, 17]], dtype=uint8), array([[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1]], dtype=uint8), array(['Simulator'], dtype='<U9'), array(['Hardware'], dtype='<U8'), array(['a'], dtype='<U1'), array(['Get by FamilyName'], dtype='<U17'), array(['getpv'], dtype='<U5'), array([[0]], dtype=uint8), array([[0.02197698]]), array([[740219.615283],
[740219.615283],
[740219.615283],
[740219.615283],
[740219.615283],
[740219.615283],
[740219.615283],
[740219.615283],
[740219.615283],
[740219.615283],
[740219.615283],
[740219.615283]]), array([[2.02600e+03, 8.00000e+00, 2.50000e+01, 1.40000e+01, 4.60000e+01,
4.45502e-01]])) ]],
dtype=[('Data', 'O'), ('FamilyName', 'O'), ('Field', 'O'), ('DeviceList', 'O'), ('Status', 'O'), ('Mode', 'O'), ('Units', 'O'), ('UnitsString', 'O'), ('DataDescriptor', 'O'), ('CreatedBy', 'O'), ('t', 'O'), ('tout', 'O'), ('DataTime', 'O'), ('TimeStamp', 'O')]) ]]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indices are to get the quadrupole family Q0L. Im not sure why the imported dictionary is so horrible, it looks a lot better in matlab.

This code adds a way to make sure that the response matrixes are ordered how we expect. Essentially we are just checking that the data is ordered as we expect and if its not, then we reorder it. This is so we dont end up using the wrong response matrixes for a Quad family

@MJGaughran MJGaughran Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still a bit lost.

I was looking for a brief (one line?) comment explaining the whole [0][0][0][0][1][0] thing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indices are to index a nested list which is generated when the matlab file is loaded using scipy, the quadrupole family string is located at [0][0][0][0][1][0].

Comment thread src/dls_slow_feedbacks/tunefb_server.py Outdated
rmats = []

# We build the response matrix out of the tune quad families, making sure
# that they are ordered in the same order as defined elsewhere.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is elsewhere? MML config? Inside dls_slow_feedbacks? All of them?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside dls_slow_feedbacks. Previously we just assumed the data in mml was in the order we required, now we check and reorder if necessary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this explicit in the comment?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the comment

Comment thread src/dls_slow_feedbacks/vefb_server.py Outdated
Comment thread src/dls_slow_feedbacks/mode.py Outdated
Comment thread src/dls_slow_feedbacks/tunefb_server.py Outdated
def set_mode(self, mode: int) -> None:
"""Set the ring mode and reload the lattice."""
self.name = RING_MODES[mode]
if self.name in RING_MODES_D2:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does feel like there should be some separate variable to indicate whether we are in D2 or D1 mode, although I understand this should work.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see an argument for this yeh, I was trying not to treat D2 as a special case and rather focus on ringmodes which are already an established thing in slow feedbacks.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is effectively a special case already. Please just make sure you've tested it in anger.

@ptsOSL
ptsOSL force-pushed the diamond2-conversion2 branch from a7cf2b4 to e888c1f Compare September 16, 2026 13:06
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.06897% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.05%. Comparing base (bd980d6) to head (c2bb4a4).

Files with missing lines Patch % Lines
src/dls_slow_feedbacks/tunefb_server.py 62.16% 14 Missing ⚠️
src/dls_slow_feedbacks/mode.py 56.52% 10 Missing ⚠️
src/dls_slow_feedbacks/rffb_server.py 40.00% 3 Missing ⚠️
src/dls_slow_feedbacks/sofb_server.py 50.00% 2 Missing ⚠️
src/dls_slow_feedbacks/vefb_server.py 71.42% 2 Missing ⚠️
src/dls_slow_feedbacks/__main__.py 50.00% 1 Missing ⚠️
src/dls_slow_feedbacks/tunefb_offsets.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #5      +/-   ##
==========================================
+ Coverage   47.55%   48.05%   +0.49%     
==========================================
  Files          16       16              
  Lines        1659     1698      +39     
==========================================
+ Hits          789      816      +27     
- Misses        870      882      +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This was actually slowing Virtac. This is because Virtac
would see the changes to the first pv in the list and then recalculate
before the others had taken effect. As wait=True, tunefb would have
to wait for Virtac to recalculate and then read in the remainder of
the caputs at which point tunefb could then move on. In some ways this
was the correct behaviour, but it was causing issues.
@ptsOSL
ptsOSL force-pushed the diamond2-conversion2 branch from d235679 to 614cbee Compare September 21, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants