Skip to content

Add 2nd order polynomial supermirror efficiency function #67

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

Merged
merged 4 commits into from
Jul 8, 2024

Conversation

SimonHeybrock
Copy link
Member

@SimonHeybrock SimonHeybrock commented Jul 8, 2024

Fixes #65

I slightly extended the Zoom notebook with a usage example.

@SimonHeybrock SimonHeybrock marked this pull request as ready for review July 8, 2024 06:46
@SimonHeybrock SimonHeybrock requested a review from astellhorn July 8, 2024 06:46
@dataclass
class SecondOrderPolynomialEfficiency(SupermirrorEfficiencyFunction[PolarizingElement]):
"""
Efficiency of a supermirror as a second-order polynomial
Copy link
Contributor

Choose a reason for hiding this comment

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

(minor) second degree polynomial?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed!

c: sc.Variable

def __post_init__(self):
if self.a.unit != sc.Unit('1/angstrom**2'):
Copy link
Contributor

@jokasimr jokasimr Jul 8, 2024

Choose a reason for hiding this comment

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

Maybe it's better like this, not sure. But alternatively we could keep the parameters dimensionless and deal with the units in the __call__ method. The advantage is that we / the users don't have to care about the parameter units.

Copy link
Member Author

@SimonHeybrock SimonHeybrock Jul 8, 2024

Choose a reason for hiding this comment

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

Maybe it's better like this, not sure.

The core philosophy of Scipp is to avoid values without units wherever possible. It avoids really bad and hard to track-down bugs, as well as being self-documenting. Fewer bugs + documentation is what we chose over minor inconvenience.

Copy link
Contributor

@jokasimr jokasimr Jul 8, 2024

Choose a reason for hiding this comment

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

Oh but I didn't suggest not having units. I suggested to define the parameters as dimensionless. We would still do unit checks in the __call__ function.

Copy link
Contributor

Choose a reason for hiding this comment

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

But sure, it's probably better like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh but I didn't suggest not having units. I suggested to define the parameters as dimensionless.

Don't the values of the parameters depend on their units? That is, if the user has in mind "b is 123/nm" and sets b=123 we get nonsense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

But you are also testing wrong powers, e.g. a, b, c all in 1/angstrom (first part of the test) - and that does not give an error?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean code like this?

    with pytest.raises(sc.UnitError, match=" to `dimensionless` is not valid"):
        eff = pol.SecondDegreePolynomialEfficiency(
            a=sc.scalar(1.0, unit='1/angstrom'),
            b=sc.scalar(1.0, unit='1/angstrom'),
            c=sc.scalar(1.0),
        )
        eff(wavelength=wav)

Note the with pytest.raises(sc.UnitError, match=" to dimensionless is not valid"): --- this checks that the code raises the expected exception.

Copy link
Collaborator

@astellhorn astellhorn Jul 8, 2024

Choose a reason for hiding this comment

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

Ah ok, and the following code which in principle is correct from dimensions of a,b,c checks that it does not comply with some wavelength/time , i.e., for comparing a,b,c in their respective angstrom units with a "wavelength" in angstrom/s ?

with pytest.raises(sc.UnitError, match=" to `dimensionless` is not valid"):
eff = pol.SecondDegreePolynomialEfficiency(
            a=sc.scalar(1.0, unit='1/angstrom**2'),
            b=sc.scalar(1.0, unit='1/angstrom'),
            c=sc.scalar(1.0),
        )
        eff(wavelength=wav / sc.scalar(1.0, unit='s'))

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, perfect, understood! Will be tested on the zoom data this week :)

Copy link
Contributor

@jokasimr jokasimr left a comment

Choose a reason for hiding this comment

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

Looks good to me. Left some minor comments.

@SimonHeybrock SimonHeybrock merged commit 44aeafc into main Jul 8, 2024
3 checks passed
@SimonHeybrock SimonHeybrock deleted the supermirror-efficiency branch July 8, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Implement missing supermirror function
3 participants