-
Notifications
You must be signed in to change notification settings - Fork 1
Add YAML file specification #19
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
Conversation
e31aa30 to
677ca76
Compare
|
At the moment the validator seems to be failing on the included .yaml data, both before and after rebase. Inclined to rebase, add it to CI, and fix before merging. |
|
I think the main reason for that is #50 - not sure if you want to do that in here or in a separate PR + will likely need input from instrument scientists |
|
I see! Changing the default e_init for chopper instruments should not be too controversial as in practice this will nearly always be provided. |
172e600 to
e8eebc3
Compare
|
I can't tweak IDEAL2D YAML to pass validation because it isn't implemented. Shall we delete this for now, and restore with an implementation later? |
|
I think that one is basically a holdover from copying everything from AbINS and hasn't been changed since the beginning - I'd say delete it and if we want the functionality, it could be implemented in #45 or similar |
|
For TOSCA we are getting the validation error This seems to be caused by a conflict between the declared
update A-ha, I see we can use the |
|
Seems like I forgot to remove the constants for TFXA and TOSCA1 when refactoring (TOSCA does not have |
|
Ah, so the problem is that
Whereas for the Abins TOSCA model, |
|
TOSCA has only the common stuff in |
| average_secondary_flight_path: 0.671 # m | ||
| average_final_energy: 3.909 # meV | ||
| average_bragg_angle_graphite: 43. # deg | ||
| change_average_bragg_angle_graphite: 5.0814852427945665 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this value supposed to be the same for TFXA and TOSCA1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better check the book when I have access to it tomorrow! But I think it's the same analyzer technology?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some of the underlying constants that go into the calculation might have changed between the two
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right you are! With this script:
from dataclasses import dataclass
import math
@dataclass
class BookModelData:
d_i: float # Primary flightpath (m)
d_f: float # Average secondary flightpath (m)
E_f: float # Average final energy (meV)
θ_B: float # Average Bragg angle for graphite (°)
A: float # ISIS water moderator constant (μs)
Δt_ch: float # Time channel uncertainty (μs)
d_s: float # Sample thickness (m)
d_g: float # Graphite thickness (m)
d_d: float # Detector thickness (m)
Δd_i: float # Uncertainty in primary flightpath (m)
w_s: float # Sample width (m)
w_d: float # Detector width (m)
η_g: float = 2.5 # Mosaic of the graphite analyser (°)
ħ2: float = 4.18019 # Conversion factor (meV Å)
def cot(x: float) -> float:
return 1 / math.tan(x)
def get_Δθ_B(data: BookModelData) -> float:
α_2 = data.w_s / 2 * (1 + cot(data.θ_B * math.pi / 180.)**2) / data.d_g
α_3 = data.w_d / 2 * (1 + cot(data.θ_B * math.pi / 180.)**2) / data.d_g
Δθ_B = (math.sqrt(α_2**2 * α_3**2 + α_2**2 * data.η_g**2 + α_3**2 * data.η_g**2)
/ math.sqrt(α_2**2 + α_3**2 + (2 * data.η_g)**2))
return Δθ_B
txfa_data = BookModelData(12.13, 0.671, 2.909, 43.0, 44., 2., 0.002, 0.002, 0.006, 0.0021, 0.02, 0.012)
tosca1_data = BookModelData(12.264, 0.7456, 3.51, 46.03, 44., 2., 0.002, 0.002, 0.0025, 0.0021, 0.020, 0.012)
print("TXFA Δθ_B: ", get_Δθ_B(txfa_data))
print("TOSCA1 Δθ_B: ", get_Δθ_B(tosca1_data))I get
TXFA Δθ_B: 5.637684123246608
TOSCA1 Δθ_B: 5.0814852427945665
Is there somewhere more responsible I should store that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned earlier, there's developer_utils.py, though it seems like you have made a more elaborate version
|
Hmm, PANTHER is failing because e_init is a mandatory argument and the validator doesn't supply anything. If we want this validator to pass all our YAML files, we can't have mandatory arguments without defaults. Or we need to provide the validation defaults somewhere else. |
|
Looks like we have green checkmark. We're still in alpha and the spec can change if necessary. The docs and validator from this PR will help guide and implement that. Apart from that TXFA parameter, are there any other blockers to this PR? |
|
If we're looking to rewrite the entire script anyway, there's no point harping on the details, so, yes, i thing this could go ahead. |
oerc0122
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the validate want to be added as a script in the pyproject.toml? Or are we keeping it for debugging?
|
I think we want to make it available to people who design their own models, which can be done with ResINS only pip-installed (without having to pull the entire repo), so it's probably a good idea. Maybe it could be hidden behind a flag? e.g. |
|
It would be good if it can be hidden in a dev tools option: I don't think it should be pip-installed for anyone who pulled in ResINS as a dependency. But I don't think pyproject.toml makes that easy? Probably the official technical solution is a separate repository as an optional dependency... |
|
I don't think it's possible with the current pyproject spec (using setuptools) it's one of the issues we're having with castep outputs You can, however, set up an optional dependency as a |
|
I do expect that some CLI tools will be added for general users, though. In which case it is less annoying for the validator to be hidden behind a general Let's leave it uninstalled for now and revisit when other CLI tools are added. |
ajjackson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this already does a lot of good. We are still in alpha and can change details if necessary; let's reduce the PR/merge backlog first.
uv requires that optional dependencies are _resolvable_ even when it doesn't install them. The optional mantid dependency for testing is a problem as it is not available from PyPI. Hopefully we can soon ditch this in favour of tests against reference data, and move to uv-based development and testing.
Adds a detailed specification for the YAML data files to the documentation.
Additionally, adds a script that validates a given YAML file - that it is structured correctly as well as that it can be run with ResINS. It currently raises an exception on the first issue it finds, but maybe it should instead log all of them into a given output? On that note, it seems like the default values of
e_initandchopper_frequencyfor the ARCS instrument result inNoTransmissionError, so I suppose we should change the defaults, not sure whether to do that here or separately though.