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

feat: add analysis points #3285

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

AayushSabharwal
Copy link
Member

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Add any other context about the problem here.

Copy link
Contributor

@baggepinnen baggepinnen left a comment

Choose a reason for hiding this comment

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

This PR only includes the get_sensitivity_function, but not get_sensitivity, is this a deliberate choice?

(nameof(inputap), [nameof(outputap)])
]
if input isa Symbol
# broken because MTKStdlib defines the method for
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this method not be moved to MTK?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will look into disabling the method in Stdlib if this one is defined in MTK

src/systems/analysis_points.jl Show resolved Hide resolved
each level in the hierarchy is given by elements of `hierarchy`. For example, if
`hierarchy = [:a, :b, :c]`, the system being searched for will be `root.a.b.c`. Note that
the hierarchy may include the name of the root system, in which the first element will be
ignored. For example, `hierarchy = [:root, :a, :b, :c]` also searches for `root.a.b.c`.
Copy link
Contributor

Choose a reason for hiding this comment

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

will this be problematic if the system contains root.root.a.b.c? How do we know whether one root should be removed or not?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that is a bit of a problem. The main issue here is that with getproperty syntax to access analysis points, the returned analysis point may or may not have the namespace of the outermost system depending on whether the outermost system is marked with complete or not. We have to handle both cases, but it leads to ambiguities. In your example, the best way to do it would be to ensure the outermost root is not marked as complete. I'm open to better suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it has to follow the same convention as for variable access, otherwise it'll be confusing. This is why I was using complete everywhere, and why I was sad to see complete change behavior since it broke my code


function apply_transformation(cst::ComplementarySensitivityTransform, sys::AbstractSystem)
sys, (u,) = apply_transformation(GetInput(cst.ap), sys)
sys, (du,) = apply_transformation(AddVariable(cst.ap, Symbol(:comp_sens_du)), sys)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sys, (du,) = apply_transformation(AddVariable(cst.ap, Symbol(:comp_sens_du)), sys)
sys, (du,) = apply_transformation(AddVariable(cst.ap, :comp_sens_du), sys)

?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is fixed now. Each of these added variables has a name derived from the analysis point to avoid issues where get_comp_sensitivity is called with multiple analysis points in the same (sub-)system.

@AayushSabharwal
Copy link
Member Author

I'd really appreciate feedback on the docstrings, and suggestions for the docstring for the new linearization_function method.

@baggepinnen
Copy link
Contributor

There are lots of docstrings from the old implementation missing, all these + the ones for AnalysisPoint and connect(a, :name, b) have lost a lot of detail

@AayushSabharwal
Copy link
Member Author

Should we make this new interface experimental as well?

@baggepinnen
Copy link
Contributor

baggepinnen commented Jan 3, 2025

Should we make this new interface experimental as well?

we could, but ideally not for too long. We can mark it as stable once we have integrated with JSML and made sure that works?

@AayushSabharwal
Copy link
Member Author

I'm not advocating for it being experimental, so it would be great to have this be stable if you're happy with it.

@baggepinnen
Copy link
Contributor

it would be great to have this be stable if you're happy with it.

If you feel like it should, I'm fine with that as well

@baggepinnen
Copy link
Contributor

@AayushSabharwal
Copy link
Member Author

While that check can be implemented in MTK, the concept of a RealInput and RealOutput doesn't exist here. I can check that the connection variables in the input/output systems have the correct input and output metadata, but that would restrict AnalysisPoint to be used only with such variables

@baggepinnen
Copy link
Contributor

Yeah this would act on the IO metadata, and it only works in setting that have those properties anyways (regardless of the metadata), so that's likely fine. If the user commits the mistake the warnings warn against, the result will be silently wrong, so we have to either warn or error.

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