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
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 piracyin the source and collected here.The ones that had a local fix are already gone:
Base.NamedTuple(::NeuralNetworkParameters)is justparams, and theParameterHandling.flattenandSymbolics.Arrmethods went with their callers when #207 moved to NeuralNetworkParameters and SymbolicNeuralNetworks 0.5. What is left needs a release of an upstream package.AbstractNeuralNetworks
applychain(::Tuple, ::Tuple{<:QPTOAT2, <:OptionalParameters}, ::Tuple)src/architectures/generalized_hamiltonian_neural_network.jl(state, system parameters)down the chain. ANN'sapplychain(layers, x, ps::Union{NamedTuple, NeuralNetworkParameters})is already generic inx; widening the@generatedmethod atchain.jl:39the same way would remove the need(::Chain)(qp, problem_params, ps)and three moreChainfunctorsParametricChainwrapper that GML ownsnetworkbackend(::LazyArrays.ApplyArray)networkbackendon array types it does not ownh5save(::HDF5.Group, ::NeuralNetworkParameters, ::AbstractString)ext/HDF5Ext.jlh5save(::H5DataStore, ::NamedTuple, …)andsave(::H5DataStore, ::NeuralNetworkParameters), but nothing for a parameter set nested at a path. Recorded as D10 in NeuralNetworkParameters'PLAN.mdSymbolicNeuralNetworks
Jacobian(f, ::AbstractSymbolicNeuralNetwork, ::Integer)andJacobian(::AbstractSymbolicNeuralNetwork, ::Integer)src/architectures/generalized_hamiltonian_neural_network.jldim2input variables only — the rest are the system parameters, which are not differentiated(::SymbolicPullback)(ps, model, ::Tuple{…, …, <:Union{NamedTuple, AbstractVector}})call operatorssrc/pullbacks/symbolic_hnn_pullback.jlbuild_nn_functiontakes one data argument, so the system parameters have to be concatenated onto the network input. Abuild_nn_functionthat takes more than one data argument would remove both the piracy and the concatenationRelated
NeuralNetworkParameters.jlPLAN.mdPhase 2 moves the parameter container upstream, which is what makes theh5saveentry above someone's to own.🤖 Generated with Claude Code