Skip to content

prepare solver and cli interfaces for co-simulation - #635

Draft
superwhiskers wants to merge 1 commit into
developfrom
sw/co-simulation-01
Draft

superwhiskers wants to merge 1 commit into
developfrom
sw/co-simulation-01

Conversation

@superwhiskers

Copy link
Copy Markdown
Collaborator

Description

prepares the solver and cli interfaces for co-simulation work

Proposed changes

there's a small amount of diff noise here from breaking this out of the earlier monolithic commit which included formatting changes. that can be reduced further if necessary

  • add a nix development environment
  • extend cli parsing to support positional arguments
  • extend kinsol with callback-based solves
  • improve sundials interface error handling and monitor control
  • add fault support to signal voltage output buses
  • support external signal bindings in jacobian tests

Checklist

  • All tests pass.
  • Code compiles cleanly with flags -Wall -Wpedantic -Wconversion -Wextra.
  • The new code follows GridKit™ style guidelines.
  • There are unit tests for the new code.
  • The new code is documented.
  • The feature branch is rebased with respect to the target branch.
  • The CHANGELOG.md has been updated to reflect the changes. If this is a minor PR that is part of a larger fix already included in the file, state so.

@read-the-docs-community

read-the-docs-community Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 GridKit | 🛠️ Build #35624035 | 📁 Comparing 866f332 against latest (9963c0d)

  🔍 Preview build  

72 files changed · + 23 added · ± 49 modified

+ Added

± Modified

@superwhiskers
superwhiskers force-pushed the sw/co-simulation-01 branch 2 times, most recently from 621e39a to 7d7a0cd Compare November 3, 2026 01:04

@lukelowry lukelowry left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some initial thoughts. Also, I don't know much about .nix, could you give some info? Looks like good architecture changes overall

const int consistentICType = getIDAConsistentICType();
retval = IDACalcIC(solver_, consistentICType, t0 + 0.1);

retval = IDACalcIC(solver_, consistentICType, t0 + 0.1);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Out of scope of PR, but why is this arbitrarily + 0.1? Could this be related to convergence issues post-fault? @Steven-Roberts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The argument should be

the first value of 𝑡 at which a solution will be requested (from IDASolve()). This value is needed here only to determine the direction of integration and rough scale in the independent variable 𝑡.

Since we don't have access to tf yet, I guess + 0.1 was arbitrarily picked. The convergence issues typically occur a couple steps after IDACalcIC is called, we I don't think this is the culprit. Nevertheless, I can check and see if another value is more principled here.

int getDefaultInitialCondition();
int initializeSimulation(RealT t0, bool findConsistent = true);
int initializeSimulation(
RealT t0, bool findConsistent = true, bool printMonitor = true);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This feels like an unfortunate place to add printMonitor, thoughts?

@superwhiskers

Copy link
Copy Markdown
Collaborator Author

Also, I don't know much about .nix, could you give some info?

this was only in here initially due to the patched enzyme to make using it easier for others. i've left it in here as it's a harmless change so i can stop maintaining the environment out of tree, but it can be removed if necessary. as it's used here, it's just a way of describing how to build gridkit / set up an environment for developing it. if you want more information than that / want to try to use it, you can learn more here.

if you have access to the excl cluster, a handful of the machines there have it

@nkoukpaizan

nkoukpaizan commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Also, I don't know much about .nix, could you give some info?

this was only in here initially due to the patched enzyme to make using it easier for others. i've left it in here as it's a harmless change so i can stop maintaining the environment out of tree, but it can be removed if necessary. as it's used here, it's just a way of describing how to build gridkit / set up an environment for developing it. if you want more information than that / want to try to use it, you can learn more here.

if you have access to the excl cluster, a handful of the machines there have it

Perhaps move the relevant nix files to buildsystem/ and add some documentation, similar to what we have for Spack. Note that ExCL is not widely available outside of ORNL.

@superwhiskers

superwhiskers commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

Perhaps move the relevant nix files to buildsystem/

conventionally flake.nix is at the root of the repository, as then you can run nix develop at the root and be placed into a shell containing the software used to develop gridkit. i can remove the .envrc though as this was just to automatically load the dependencies into the shell environment without needing that extra step

additionally, if it weren't at the root, then someone wanting to pull in gridkit as an input to a flake of their own would need to override the directory it is in.

Note that ExCL is not widely available outside of ORNL.

and to clarify, you can use nix on any machine you want, i only mentioned excl as it's already installed on some of the machines there. if you don't have access or want to use it on a personal machine it's something you could freely install yourself as i have

- add a nix development environment
- extend cli parsing to support positional arguments
- extend kinsol with callback-based solves
- improve sundials interface error handling and monitor control
- add fault support to signal voltage output buses
- support external signal bindings in jacobian tests

@pelesh pelesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The proposed changes here need more discussion and a dedicated issue(s).

A few obvious suggestions:

  • Buses wired to signals should not be faulted. Adding fault support for those is a distraction at this point.
  • No changes to Ida should be made in this PR. Most of the changes to Ida as I see are formatting changes and these must be reverted before the review.
  • If changes to Kinsol are required, they need to be discussed in a separate issue.
  • All flake related configuration needs to be removed. We are using Spack for packaging, so any configuration adjustments should be contributed there.

Comment on lines +70 to 71
virtual int setFault(bool status, RealT R, RealT X) override final;
virtual int allocate() override final;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I suggest we make busses with associated signals "unfaultable". When you dedicate a bus as a co-simulation connection point, you typically don't want to fault it.

Suggested change
virtual int setFault(bool status, RealT R, RealT X) override final;
virtual int allocate() override final;
virtual int allocate() override final;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Similarly, remove fault support for signal connected buses elsewhere in the code.

@pelesh
pelesh marked this pull request as draft November 4, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup enhancement New feature or request testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants