Skip to content

Removes/reduces referenece use on i10 IDs #1032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

Relm-Arrowny
Copy link
Contributor

@Relm-Arrowny Relm-Arrowny commented Jan 29, 2025

Fixes #1029 and #1046.

Instructions to reviewer on how to test:

  1. Run test.
  2. Confirm connection.
  3. Check uml.

Checks for reviewer

  • Would the PR title make sense to a scientist on a set of release notes
  • If a new device has been added does it follow the standards
  • If changing the API for a pre-existing device, ensure that any beamlines using this device have updated their Bluesky plans accordingly
  • Have the connection tests for the relevant beamline(s) been run via dodal connect ${BEAMLINE}

@Relm-Arrowny Relm-Arrowny linked an issue Jan 29, 2025 that may be closed by this pull request
9 tasks
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.88%. Comparing base (756775e) to head (0ce9976).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1032      +/-   ##
==========================================
- Coverage   97.89%   97.88%   -0.02%     
==========================================
  Files         182      182              
  Lines        7187     7182       -5     
==========================================
- Hits         7036     7030       -6     
- Misses        151      152       +1     

☔ View full report in Codecov by Sentry.
📢 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.

@Relm-Arrowny Relm-Arrowny linked an issue Feb 7, 2025 that may be closed by this pull request
1 task
@Relm-Arrowny Relm-Arrowny mentioned this pull request Feb 10, 2025
4 tasks
@Relm-Arrowny Relm-Arrowny marked this pull request as ready for review February 11, 2025 09:35
@Relm-Arrowny Relm-Arrowny requested a review from a team as a code owner February 11, 2025 09:35
@DominicOram DominicOram changed the title Removes/reduces refenece use on i10 IDs Removes/reduces referenece use on i10 IDs Feb 12, 2025
Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

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

Thanks, I think it's cleaner but have some more comments to make it even more so.

Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

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

Thanks, couple of comments in code. Additionally, I think polarisation is basically a derived signal. I will do #1077 so that we can use it here as I think it will clean things up a lot.

@DominicOram
Copy link
Contributor

I think you should be able to use #1078 for the polarisation signal now. Happy to help if it's not obvious how.

@Relm-Arrowny Relm-Arrowny requested a review from DominicOram March 4, 2025 14:58
Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

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

Thanks! I think there are still quite a few places where you could be making use of the enum but this is a start. I think using the setter from the other PR will tidy things up a bit though

@Relm-Arrowny Relm-Arrowny self-assigned this Apr 25, 2025
@olliesilvester olliesilvester self-requested a review May 27, 2025 09:57
Copy link
Collaborator

@olliesilvester olliesilvester left a comment

Choose a reason for hiding this comment

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

I haven't reviewed the entire thing yet, but a few comments for now.

"""
note:
I10 has two insertion devices one up(idu) and one down stream(idd).
It is worth noting that the down stream device is slightly longer,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
It is worth noting that the down stream device is slightly longer,
It is worth noting that the downstream device is slightly longer,

self.jaw_phase.user_setpoint_readback,
self.jaw_phase.user_readback,
self.jaw_phase.velocity,
)


class Apple2(StandardReadable, Movable):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of scope for this issue, but we should see if we can create a BaseUndulator device with a minimum set of signals.

Comment on lines +387 to +395
_set_pol(value: Pol) -> None
Sets the polarisation and adjusts motor positions based on the current energy.
_read_pol_setpoint(pol: Pol, ...) -> Pol
Reads the polarisation from hardware and updates the setpoint.
_set(value: Apple2Val, energy: float) -> None
Moves the undulator to the specified motor positions and energy.
_get_id_gap_phase(energy: float) -> tuple[float, float]
Converts energy and polarisation to gap and phase motor positions.
_get_poly(new_energy: float, lookup_table: dict) -> np.poly1d
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Given that these are private methods, I probably wouldn't include them on the docstring here. If I were writing plans which need this device, I'd like to quickly see the public methods available to me

self.jaw_phase.user_setpoint_readback,
self.jaw_phase.user_readback,
self.jaw_phase.velocity,
)


class Apple2(StandardReadable, Movable):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Must: This uses the Movable protocol so we need to have have a set function defined. Maybe you can just rename _set?

"""This change the position of all the motors for a given energy and
polarisation_setpoint"""

def _read_pol_setpoint(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: name is implying we are only doing a read. I'd prefer something like def _update_pol_setpoint_using_hardware_read

Copy link
Collaborator

Choose a reason for hiding this comment

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

The raw_to_derived function is for converting raw values to derived values. It seems a bit unexpected for this function to also be changing a setpoint. I'm not too familiar with this device yet though, so I could just be misunderstanding

self,
value: Pol,
) -> None:
# This change the pol setpoint and then change polariastion via set energy.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# This change the pol setpoint and then change polariastion via set energy.
# This changes the pol setpoint and then changes polariastion via set energy.

f"btm_inner={btm_inner}, btm_outer={btm_outer}, gap={gap}."
)

if pol != Pol.LH3:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be useful to have a comment here to explain why we handle the Pol.LH3 case differently. Also, would it be useful to error/warn if pol==None?

from dodal.devices.apple2_undulator import (
from dodal.log import LOGGER

# from dodal.beamlines.i10 import pgm
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: Remove this line

phase = 0.0
return polarisation, phase
LOGGER.info("Determined polarisation: LH (Linear Horizontal).")
return Pol("lh"), 0.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: use Pol.LH3 instead here

async def test_linear_arbitrary_pol_fail(
mock_linear_arbitrary_angle: LinearArbitraryAngle,
):
mock_linear_arbitrary_angle.id_ref().pol = "lh"
# set_mock_value(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: remove this comment

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.

PGM/appl2_undulator timing out early Removes/reduces refenece use on i10 IDs
3 participants