Skip to content
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

Unify p38 and i22, swap out with env variables #678

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

Conversation

stan-dot
Copy link
Contributor

Fixes #502

Instructions to reviewer on how to test:

  1. Try on i22, try on i38
  2. Confirm the devices are differnent yet experiments run correctly

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}

@stan-dot stan-dot added enhancement New feature or request python Pull requests that update Python code labels Jul 16, 2024
@stan-dot stan-dot self-assigned this Jul 16, 2024
@stan-dot stan-dot linked an issue Jul 16, 2024 that may be closed by this pull request
4 tasks
@stan-dot stan-dot force-pushed the 502-automatically-keep-i22-and-p38-in-sync branch from 89cfdd6 to d02275e Compare July 17, 2024 12:33
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Show resolved Hide resolved
@stan-dot stan-dot force-pushed the 502-automatically-keep-i22-and-p38-in-sync branch 3 times, most recently from 122e734 to 655684a Compare July 24, 2024 16:13
Copy link

codecov bot commented Jul 24, 2024

Codecov Report

Attention: Patch coverage is 95.45455% with 2 lines in your changes missing coverage. Please review.

Project coverage is 94.34%. Comparing base (b39f55c) to head (d0f2612).
Report is 2 commits behind head on main.

Files Patch % Lines
src/dodal/beamlines/i22.py 89.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #678      +/-   ##
==========================================
- Coverage   94.44%   94.34%   -0.10%     
==========================================
  Files         114      115       +1     
  Lines        4588     4561      -27     
==========================================
- Hits         4333     4303      -30     
- Misses        255      258       +3     

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

@stan-dot
Copy link
Contributor Author

/workspaces/dodal/tests/preprocessors/test_filesystem_metadata.py:76:9 - error: Method "trigger" overrides class "Triggerable" in an incompatible manner
Return type mismatch: base method returns type "Status", override returns type "Status"
"Status" is incompatible with protocol "Status"
"exception" is an incompatible type
Type "(timeout: Unknown | None = None) -> (StatusTimeoutError | Exception | type[Exception] | None)" is incompatible with type "(timeout: float | None = 0) -> (BaseException | None)"
Function return type "StatusTimeoutError | Exception | type[Exception] | None" is incompatible with type "BaseException | None"
"bluesky.protocols.Status" is incompatible with "ophyd.status.Status"
"bluesky.protocols.Status" is incompatible with "ophyd.status.Status" (reportIncompatibleMethodOverride)
136 errors, 3 warnings, 0 informations
ERROR: InvocationError for command /venv/bin/pyright src tests (exited with code 1)

type checking fails due to dodal not catching up to ophyd-async changes

@stan-dot stan-dot force-pushed the 502-automatically-keep-i22-and-p38-in-sync branch from 863806f to 703a2fc Compare July 30, 2024 15:51
@stan-dot stan-dot marked this pull request as ready for review July 31, 2024 14:50
@stan-dot
Copy link
Contributor Author

codecov for live beamline connectivity does not make that much sense, please let it merge

@stan-dot
Copy link
Contributor Author

I need this for #673

@stan-dot
Copy link
Contributor Author

stan-dot commented Aug 1, 2024

from @DiamondJoseph

parameterised in such a way that you can either mock the IS_LAB call before the device_instantiation is called or otherwise export BEAMLINE=P38, then you should be able to traverse that alternate path

using https://github.com/DiamondLightSource/dodal/blob/502-automatically-keep-i22-and-p38-in-sync/tests/common/beamlines/test_device_instantiation.py

@stan-dot
Copy link
Contributor Author

stan-dot commented Aug 1, 2024

@coretl would an addition of a 'lab' flag be in the scope for the device instantiation factory decorator?

@stan-dot
Copy link
Contributor Author

stan-dot commented Aug 1, 2024

need to delete LAB_NAME from the CLI, and make it all optimized for testability

src/dodal/beamlines/__init__.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Show resolved Hide resolved
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
def linkam(
wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False
) -> Linkam3:
return device_instantiation(
Linkam3,
"linkam",
"-EA-TEMPC-05",
"-EA-TEMPC-05" if IS_LAB else "-EA-TEMPC-05",
Copy link
Contributor

Choose a reason for hiding this comment

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

split devices like saxs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

???I do not understand

Copy link
Contributor

Choose a reason for hiding this comment

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

if IS_LAB:
    return this_device()
else:
    return that_device()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not agree that it's more readable, but I won't argue, changing now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

You've done

if IS_LAB:
    return this_device()
return that_device()

Which is functionally the same, but harder to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which is functionally the same, but harder to read.

that's a purely stylistic opinion, usefulness of else is a debated point among software engineers

@stan-dot
Copy link
Contributor Author

stan-dot commented Aug 5, 2024

at the core the still not-agreed-on-implementation detail is where to put the i22-p38 mapping?

when we read in the env in the CLI we need to check if the BEAMLINE belongs to the lab set and then load the dodal.beamlines.non-lab-beamline. a dictionary (this time lab: real) sounds like the most Pythonic way to do this and this can easily be hard-coded for the future.
request for comments @callumforrester , @DiamondJoseph

@DiamondJoseph
Copy link
Contributor

when we read in the env in the CLI we need to check if the BEAMLINE belongs to the lab set ...

Which CLI, dodal's?

What I would expect is if you call dodal connect i22, you run i22.py and try and connect to the devices. If the env var $BEAMLINE is set to p38, that gets picked up by BL = get_beamline_name("i22") and mostly you connect to mocked devices. You never try and run dodal connect p38

@stan-dot
Copy link
Contributor Author

stan-dot commented Aug 5, 2024

ok fair rnough

@stan-dot stan-dot force-pushed the 502-automatically-keep-i22-and-p38-in-sync branch from 09b25eb to 73fcee4 Compare August 7, 2024 08:39
@stan-dot
Copy link
Contributor Author

stan-dot commented Aug 7, 2024

@callumforrester please weigh in, me and @DiamondJoseph got stuck

update: this was confirmed as desired behavior:
What I would expect is if you call dodal connect i22, you run i22.py and try and connect to the devices. If the env var $BEAMLINE is set to p38, that gets picked up by BL = get_beamline_name("i22") and mostly you connect to mocked devices. You never try and run dodal connect p38

@stan-dot stan-dot force-pushed the 502-automatically-keep-i22-and-p38-in-sync branch 2 times, most recently from c8012ee to 7d48404 Compare August 19, 2024 11:07
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
_LAB_NAME = "p38"

IS_LAB = BL == _LAB_NAME
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_LAB_NAME = "p38"
IS_LAB = BL == _LAB_NAME
IS_LAB = BL == "p38"

closer to i03/s03

src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/beamlines/i22.py Show resolved Hide resolved
src/dodal/beamlines/i22.py Outdated Show resolved Hide resolved
src/dodal/devices/i22/NXSasAravis.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
@stan-dot stan-dot force-pushed the 502-automatically-keep-i22-and-p38-in-sync branch from 7971fdb to 02eb4d9 Compare August 21, 2024 10:00
@stan-dot stan-dot force-pushed the 502-automatically-keep-i22-and-p38-in-sync branch from 0dbd8a4 to cfe97bf Compare August 27, 2024 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically keep I22 and P38 in sync
3 participants