Skip to content

refactor generic hybrid#274

Merged
lazarusA merged 12 commits into
mainfrom
la/refactor_generic
Jul 8, 2026
Merged

refactor generic hybrid#274
lazarusA merged 12 commits into
mainfrom
la/refactor_generic

Conversation

@lazarusA

@lazarusA lazarusA commented Jul 2, 2026

Copy link
Copy Markdown
Member

With this PR all the following will be removed and unified into only one HybridModel struct/function.

  • SingleNNHybridModel [gone!]
  • MultiNNHybridModel [gone!]
  • constructHybridModel (is back!) for backwards compatibility.

and now only

HybridModel is needed.

@BernhardAhrens this will be highly breaking for the user.

Edit:
this works again constructHybridModel!

closes #191

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

📚 Documentation preview 🚀

Preview URL: https://EarthyScience.github.io/EasyHybrid.jl/previews/PR274/

Note

The preview will be available once the documentation build completes successfully, and will reflect the last successful build for this PR.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request consolidates SingleNNHybridModel and MultiNNHybridModel into a unified HybridModel struct, simplifying model construction, initialization, and forward pass logic across the codebase. The review feedback highlights several critical performance and correctness improvements: resolving a recursive configuration nesting issue in tune.jl by excluding the :config field before merging, avoiding inefficient vector comprehensions when constructing NamedTuples in prepare_data.jl, and replacing iterative merge loops with type-stable map operations in GenericHybridModel.jl to prevent excessive allocations and type instability during parameter initialization and the forward pass.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/training/tune.jl Outdated
Comment thread src/data/prepare_data.jl
Comment thread src/models/GenericHybridModel.jl
Comment thread src/models/GenericHybridModel.jl
Comment thread src/models/GenericHybridModel.jl
@BernhardAhrens

Copy link
Copy Markdown
Collaborator

Let's really stick with constructHybridModel - I think in the end that the rename is unnecessary and confusing. When I call a function named HybridModel I would expect that it runs the hybrid model but that's not what the function does. What it does is that it constructs a hybrid model that you have to run/train in the next step

@lazarusA

lazarusA commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

I would expect that it runs the hybrid model

well, with the proposed changes, it actually does that when the arguments are the appropriate ones. This is handle in the forward run definition of HybridModel,

function (m::HybridModel)(ds_k::Tuple, ps, st) ... end

I will bring-back the interface constructHybridModel while we iron things out, and will not merge until things are totally clear.

The recipe is basically,

  1. Define struct
struct test 
a
b
end
  1. constructor
function test(args...)
  a, b = args
  return test(a,b)
end
  1. forward run
function (m::test)(data, ps, st)
  # your logic using `m` and `data`
  return out, st_new
end

@BernhardAhrens

Copy link
Copy Markdown
Collaborator

But the users never does a forward run with this signature (?), it is under the hood:

function (m::test)(data, ps, st)
  # your logic using `m` and `data`
  return out, st_new
end

The constructor is clear but the user then runs a function with the name of his hybrid model? Or can you give any example for a forward run with HybridModel. I would say the constructHybridModel is meant to be similar to SciML's ODEProblem which is then called with a function solve

@lazarusA

lazarusA commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

updated all function constructors to constructHybridModel. Things should be as before now.

@BernhardAhrens good to merge now?

@lazarusA lazarusA requested a review from BernhardAhrens July 7, 2026 17:35
@BernhardAhrens

Copy link
Copy Markdown
Collaborator

Nice! I like the new tutorial @lazarusA Ready to be merged

@BernhardAhrens BernhardAhrens 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.

Thanks :) Nice refactor - should make things easier down the road

@lazarusA lazarusA merged commit 36c9fc6 into main Jul 8, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor generic hybrid

2 participants