Skip to content

Fix chopper rotations in optimize_for and Chopper#144

Merged
nvaytet merged 9 commits into
mainfrom
trex-optimize
Jun 24, 2026
Merged

Fix chopper rotations in optimize_for and Chopper#144
nvaytet merged 9 commits into
mainfrom
trex-optimize

Conversation

@nvaytet

@nvaytet nvaytet commented Jun 23, 2026

Copy link
Copy Markdown
Member

When trying to use optimize_for in the Trex instrument case, no neutrons were making it through.
The pulse-shaping and monochromatic choppers were not performing enough rotations and were thus blocking all neutrons.
Giving them a timescale to dictate how long they should rotate for helped (in this PR also), but did not fix everything.
The pulse-shaping chopper 2 was still not performing enough rotations.

It was because it has some cutout angles < -360 deg, meaning that it was still missing at least one rotation to cover the requested timescale.
Instead of guessing from the rotation frequency and timescale alone, we now find the smallest cutout angle and compute how many rotations need to be done to reach the requested timescale.

We can now make a T-rex model, optimized for the choppers in the beamline, with 0 blocked neutrons:
Screenshot_20260623_135055
Figure 1 (17)

@bingli621

Comment thread src/tof/chopper.py Outdated
Comment on lines +226 to +239
nrot = (
max(
int(
sc.ceil(
(
self.omega * time_limit.to(unit='s')
- smallest_angle.to(unit='rad')
)
/ two_pi
).value
),
1,
)
+ 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can a helper variable help with readability here? This is too many lines :D

Comment thread src/tof/chopper.py Outdated
sc.ceil(
(
self.omega * time_limit.to(unit='s')
- smallest_angle.to(unit='rad')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is not completely obvious whether this is correct for "very positive" openings. there are tests like test_chopper_with_very_negative_angles_performs_enough_rotations_to_cover_timescale, but what happens if the smallest angle is so large that one would need to rotate backward to cover the full range?

@nvaytet nvaytet Jun 23, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point, we probably need a safety net in the other direction as well!

@nvaytet nvaytet merged commit ab56630 into main Jun 24, 2026
4 checks passed
@nvaytet nvaytet deleted the trex-optimize branch June 24, 2026 08:08
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