Skip to content

Definite Targets / Optimizers#175

Draft
pearsonca wants to merge 2 commits intomainfrom
tar_opt_wrapper
Draft

Definite Targets / Optimizers#175
pearsonca wants to merge 2 commits intomainfrom
tar_opt_wrapper

Conversation

@pearsonca
Copy link
Member

@pearsonca pearsonca commented Mar 2, 2026

  • introducing default binding for systems
  • add target abc, wrapper implementation, test
  • add optimizer abc, wrapper implementation, test
  • add examples to flepimop2-demo

module: Literal["flepimop2.system.wrapper"] = "flepimop2.system.wrapper"
state_change: StateChangeEnum
script: Path
options: dict[str, Any] | None = None
Copy link
Member Author

Choose a reason for hiding this comment

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

goes because inherited and not actually overridden

Comment on lines +132 to +141
expected_type = annotations[key]
try:
casted_value = expected_type(value)
combined_params[key] = casted_value
except (ValueError, TypeError) as e:
msg = (
f"Parameter '{key}' (type {type(value).__name__}) could not be "
f"cast to {expected_type.__name__}. Error: {str(e)}"
)
validation_errors.append(ValidationIssue(msg, "binding_values"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems fine for now, but will quickly be obsoleted if we want to support parameters with shape. This gets a lot trickier to manage without a dedicated RealizedParameter class that contains information about the values and shape. Perhaps should expedite the axes development.

Copy link
Member Author

Choose a reason for hiding this comment

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

i think we can treat validating conforming shape as a next level check, that we want to do but don't yet

A stepper from this System with static parameters defined.

Raises:
ValueError: If params contains "time" or "state" keys or if value types
Copy link
Collaborator

Choose a reason for hiding this comment

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

Flepimop2ValidationError?

# Combine params and kwargs, with kwargs taking precedence
combined_params = {**params, **kwargs}

forbidden_keys = {"time", "state"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be good to extract out to a constant?

if validation_errors:
raise Flepimop2ValidationError(validation_errors)

return functools.partial(self._stepper, **combined_params)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a bit of a pro/con trade off returning SystemProtocol vs Self. Pro is this is more simple, but the con is that you loose the extra information that the system provides, so even with binding you still need to keep the system object around on the user side.

Copy link
Member Author

Choose a reason for hiding this comment

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

i anticipate we'll need to figure out returning Self, but I suspect that would also impose that as a module developer requirement vs being able to do it generically here.

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