Skip to content

Type piracy introduced by the parametric Hamiltonian architectures (#207) #243

Description

@michakraus

The parametric generalized Hamiltonian neural networks (#207) need a handful of methods whose generic and every argument type belong to another package. They are marked with TODO: type piracy in the source and collected here.

The ones that had a local fix are already gone: Base.NamedTuple(::NeuralNetworkParameters) is just params, and the ParameterHandling.flatten and Symbolics.Arr methods went with their callers when #207 moved to NeuralNetworkParameters and SymbolicNeuralNetworks 0.5. What is left needs a release of an upstream package.

AbstractNeuralNetworks

method file note
applychain(::Tuple, ::Tuple{<:QPTOAT2, <:OptionalParameters}, ::Tuple) src/architectures/generalized_hamiltonian_neural_network.jl the parameter-dependent layers pass (state, system parameters) down the chain. ANN's applychain(layers, x, ps::Union{NamedTuple, NeuralNetworkParameters}) is already generic in x; widening the @generated method at chain.jl:39 the same way would remove the need
(::Chain)(qp, problem_params, ps) and three more Chain functors same alternatively a ParametricChain wrapper that GML owns
networkbackend(::LazyArrays.ApplyArray) same ANN already dispatches networkbackend on array types it does not own
h5save(::HDF5.Group, ::NeuralNetworkParameters, ::AbstractString) ext/HDF5Ext.jl ANN's own extension has h5save(::H5DataStore, ::NamedTuple, …) and save(::H5DataStore, ::NeuralNetworkParameters), but nothing for a parameter set nested at a path. Recorded as D10 in NeuralNetworkParameters' PLAN.md

SymbolicNeuralNetworks

method file note
Jacobian(f, ::AbstractSymbolicNeuralNetwork, ::Integer) and Jacobian(::AbstractSymbolicNeuralNetwork, ::Integer) src/architectures/generalized_hamiltonian_neural_network.jl Jacobian with respect to the first dim2 input variables only — the rest are the system parameters, which are not differentiated
four (::SymbolicPullback)(ps, model, ::Tuple{…, …, <:Union{NamedTuple, AbstractVector}}) call operators src/pullbacks/symbolic_hnn_pullback.jl these exist because build_nn_function takes one data argument, so the system parameters have to be concatenated onto the network input. A build_nn_function that takes more than one data argument would remove both the piracy and the concatenation

Related

  • NeuralNetworkParameters.jl PLAN.md Phase 2 moves the parameter container upstream, which is what makes the h5save entry above someone's to own.
  • GeometricOptimizers #16 tracks the same class of problem for the optimizer side.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions