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

🩹Fix for when the backsweep is a parameter rather than constant #1422

Merged
merged 5 commits into from
Jan 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions glotaran/builtin/items/activation/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from glotaran.model.errors import ItemIssue
from glotaran.model.item import Attribute
from glotaran.model.item import ParameterType
from glotaran.parameter.parameter import Parameter

if TYPE_CHECKING:
from glotaran.parameter import Parameters
Expand Down Expand Up @@ -172,6 +173,8 @@
scales = self.scale or [1.0] * nr_gaussians
backsweep = self.backsweep is not None
backsweep_period = self.backsweep if backsweep else 0
if isinstance(backsweep_period, Parameter):
Copy link
Member

Choose a reason for hiding this comment

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

Since Parameter implements __float__ we could simply change the assignment to

- backsweep_period = self.backsweep if backsweep else 0
+ backsweep_period = float(self.backsweep) if backsweep else 0

That way we also wouldn't need the type ignore in line 185

Copy link
Member Author

@jsnel jsnel Jan 27, 2024

Choose a reason for hiding this comment

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

Tried to adopt that suggestion ...

But:

glotaran\builtin\items\activation\gaussian.py:175: error: Argument 1 to "float" has incompatible type "Parameter | float | str | None"; expected "str | Buffer | SupportsFloat | SupportsIndex" [arg-type]
glotaran\builtin\items\activation\gaussian.py:183: error: Unused "type: ignore" comment [unused-ignore]

Copy link
Member

Choose a reason for hiding this comment

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

That said using a pydantic Model instead of dataclass for GaussianActivationParameters should also take proper care of type coercion.

Copy link
Member

Choose a reason for hiding this comment

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

That said using a pydantic Model instead of dataclass for GaussianActivationParameters should also take proper care of type coercion.

Since it is a drop in replacement, I have no objection to change it.

Copy link
Member

Choose a reason for hiding this comment

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

Tried to adopt that suggestion ...

But:

glotaran\builtin\items\activation\gaussian.py:175: error: Argument 1 to "float" has incompatible type "Parameter | float | str | None"; expected "str | Buffer | SupportsFloat | SupportsIndex" [arg-type]
glotaran\builtin\items\activation\gaussian.py:183: error: Unused "type: ignore" comment [unused-ignore]

This is limitation of mypy, since it cannot understand that the type is narrowed done at that point. Either ignore it or add an assert that is of float instance.

backsweep_period = backsweep_period.value

Check warning on line 177 in glotaran/builtin/items/activation/gaussian.py

View check run for this annotation

Codecov / codecov/patch

glotaran/builtin/items/activation/gaussian.py#L177

Added line #L177 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (llm): Directly accessing the value attribute of a Parameter object could be risky if there's any chance the Parameter could be uninitialized or if the value attribute could be absent. It might be safer to use a getter method or to ensure that Parameter objects always have a value attribute.


parameters: list[GaussianActivationParameters] = [
GaussianActivationParameters(
Expand Down
Loading