  Many dynamical systems -- from robots interacting with their surroundings to
large-scale multiphysics systems -- involve a number of interacting subsystems.
Toward the objective of learning composite models of such systems from data, we
present i) a framework for compositional neural networks, ii) algorithms to
train these models, iii) a method to compose the learned models, iv)
theoretical results that bound the error of the resulting composite models, and
v) a method to learn the composition itself, when it is not known a priori. The
end result is a modular approach to learning: neural network submodels are
trained on trajectory data generated by relatively simple subsystems, and the
dynamics of more complex composite systems are then predicted without requiring
additional data generated by the composite systems themselves. We achieve this
compositionality by representing the system of interest, as well as each of its
subsystems, as a port-Hamiltonian neural network (PHNN) -- a class of neural
ordinary differential equations that uses the port-Hamiltonian systems
formulation as inductive bias. We compose collections of PHNNs by using the
system's physics-informed interconnection structure, which may be known a
priori, or may itself be learned from data. We demonstrate the novel
capabilities of the proposed framework through numerical examples involving
interacting spring-mass-damper systems. Models of these systems, which include
nonlinear energy dissipation and control inputs, are learned independently.
Accurate compositions are learned using an amount of training data that is
negligible in comparison with that required to train a new model from scratch.
Finally, we observe that the composite PHNNs enjoy properties of
port-Hamiltonian systems, such as cyclo-passivity -- a property that is useful
for control purposes.
