Fmi2 directional derivatives - #807
Conversation
Use FMI Library 3.0.4 and carry the repository CI/package updates needed by the FMI 3 stack.
Implement validated FMI 2 directional derivatives with a dedicated fixture, reference-FMU wiring, and contract tests.
kyllingstad
left a comment
There was a problem hiding this comment.
Thanks! Great to finally have some more FMI 2.0 support… :D I have a few comments, mostly on form rather than substance.
| throw error( | ||
| make_error_code(errc::model_error), | ||
| instanceName_ + | ||
| ": invalid lifecycle operation: GetDirectionalDerivative"); |
There was a problem hiding this comment.
I think this error message is misleading. Getting directional derivatives is not a "lifecycle operation", it is an operation that may be invalid at the current state in the FMU's lifecycle. I'm also not sure whether errc::model_error is the right error code for this. Maybe we need a new one, e.g. errc::invalid_operation or something. (It wouldn't be unique to this particular situation; there are many cases in the FMI spec where certain operations are prohibited at a certain lifecycle stage. Could also be used for the "invalid (un)known" errors further down in this function.)
There was a problem hiding this comment.
Updated to throw invalid_operation and text
| // Increment this number whenever the "exported state" changes form, and | ||
| // always consider whether backwards compatibility measures are warranted. | ||
| constexpr std::int32_t export_scheme_version = 1; | ||
| constexpr std::int32_t export_scheme_version = 0; |
There was a problem hiding this comment.
This should not be reverted, IMO. It is a new scheme version, my point was just that shouldn't worry about maintaining compatibility with the previous one.
There was a problem hiding this comment.
Made it back to 1
kyllingstad
left a comment
There was a problem hiding this comment.
Nice, thanks for doing this!
Add FMI 2 directional derivative support
Summary
Adds validated FMI 2.0 directional-derivative support to
fmi::v2::slave_instance, lifecycle-aware FMU state handling, deterministicfixture coverage, and the dependency/CI updates required to build and test it.
Changes
Add
provides_directional_derivatives()andget_directional_derivative().Read and cache directional-derivative metadata from
modelDescription.xml.Validate lifecycle, value-reference type, reference validity, and seed and
sensitivity sizes before calling the FMU.
Compute the Jacobian-vector product:
Accept FMI
OKandWarning; surfaceDiscard,Error,Fatal, andPendingas errors.Preserve caller output when the FMU call fails.
Track
instantiated,initialization,step, andterminatedstates.Serialize lifecycle state in export scheme 1 while retaining safe scheme 0
compatibility.
Add cleanup and ownership checks for imported FMU state.
Test coverage
Real outputs, a fixed 2-by-3 Jacobian, configurable statuses, a call counter,
and a non-Real reference.
fmi_v2_fmu_unittestfor lifecycle behavior, expected derivatives,reordered references, invalid inputs, status handling, output preservation,
and unsupported capabilities.
v0.0.41and package the fixture asFmi2Derivatives.fmu; expose them throughREFERENCE_FMU_V2_DIR.Dependency and CI updates
~3.0.4and proxyFMU to0.4.3@osp/testing.