neuromancer.dynamics package

Submodules

neuromancer.dynamics.integrators module

Single-step integrators for first-order nonautomonomous ODEs

class neuromancer.dynamics.integrators.DiffEqIntegrator(block, interp_u=None, h=0.001, method='euler')[source]

Bases: Integrator

integrate(x, *args)[source]
class neuromancer.dynamics.integrators.Euler(block, interp_u=None, h=1.0)[source]

Bases: Integrator

integrate(x, *args)[source]
class neuromancer.dynamics.integrators.Euler_Trap(block, interp_u=None, h=1.0)[source]

Bases: Integrator

integrate(x, *args)[source]
Parameters:

x – (torch.Tensor, shape=[batchsize, SysDim])

Return x_{t+1}:

(torch.Tensor, shape=[batchsize, SysDim])

class neuromancer.dynamics.integrators.Integrator(block, interp_u=None, h=1.0)[source]

Bases: Module, ABC

forward(x, *args)[source]

This function needs x only for autonomous systems. x is 2D. It needs x and u for nonautonomous system w/ online interpolation. x and u are 2D tensors.

abstract integrate(x, *args)[source]
reg_error()[source]
class neuromancer.dynamics.integrators.LeapFrog(block, interp_u=None, h=1.0)[source]

Bases: Integrator

integrate(X, *args)[source]
Parameters:

X – (torch.Tensor, shape=[batchsize, 2*SysDim]) where X[:, :SysDim] = x_t and X[:, SysDim:] = dot{x}_t

Return X_{t+1}:

(torch.Tensor, shape=[batchsize, 2*SysDim]) where X_{t+1}[:, :SysDim] = x_{t+1} and X_{t+1}[:, SysDim:] = dot{x}_{t+1}

class neuromancer.dynamics.integrators.Luther(block, interp_u=None, h=1.0)[source]

Bases: Integrator

integrate(x, *args)[source]
class neuromancer.dynamics.integrators.MultiStep_PredictorCorrector(block, interp_u=None, h=1.0)[source]

Bases: Integrator

integrate(x, *args)[source]
Parameters:

x – (torch.Tensor, shape=[batchsize, nsteps, SysDim]) where x[0:1, :, :] = x_{t-3}, x[1:2, :, :] = x_{t-2}, x[2:3, :, :] = x_{t-1}, x[3:4, :, :] = x_{t}

Return x_{t+1}:

(torch.Tensor, shape=[batchsize, SysDim])

class neuromancer.dynamics.integrators.RK2(block, interp_u=None, h=1.0)[source]

Bases: Integrator

integrate(x, *args)[source]
class neuromancer.dynamics.integrators.RK4(block, interp_u=None, h=1.0)[source]

Bases: Integrator

integrate(x, *args)[source]
class neuromancer.dynamics.integrators.RK4_Trap(block, interp_u=None, h=1.0)[source]

Bases: Integrator

predictor-corrector integrator for dx = f(x) predictor: explicit RK4 corrector: implicit trapezoidal rule

integrate(x, *args)[source]
class neuromancer.dynamics.integrators.Runge_Kutta_Fehlberg(block, interp_u=None, h=1.0)[source]

Bases: Integrator

The Runge–Kutta–Fehlberg method has two methods of orders 5 and 4. Therefore, we can calculate the local truncation error to determine if current time step size is suitable or not. # https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods#Adaptive_Runge%E2%80%93Kutta_methods

integrate(x, *args)[source]
Parameters:

x – (torch.Tensor, shape=[batchsize, SysDim])

Return x_{t+1}:

(torch.Tensor, shape=[batchsize, SysDim])

class neuromancer.dynamics.integrators.Yoshida4(block, interp_u=None, h=1.0)[source]

Bases: Integrator

integrate(X, *args)[source]
Parameters:

X – (torch.Tensor, shape=[batchsize, 2*SysDim]) where X[:, :SysDim] = x_t and X[:, SysDim:] = dot{x}_t

Return X_{t+1}:

(torch.Tensor, shape=[batchsize, 2*SysDim]) where X_{t+1}[:, :SysDim] = x_{t+1} and X_{t+1}[:, SysDim:] = dot{x}_{t+1}

neuromancer.dynamics.integrators.make_norm(state)[source]
neuromancer.dynamics.integrators.rms_norm(tensor)[source]

neuromancer.dynamics.interpolation module

class neuromancer.dynamics.interpolation.Interpolation[source]

Bases: ABC

abstract interpolation(tq, t, u)[source]
class neuromancer.dynamics.interpolation.LinInterp_Offline(t, u)[source]

Bases: Interpolation

interpolation(tq, t=None, u=None)[source]
Parameters:

tq – torch.Tensor (# of timesteps, 1), The unit of tq is actual temporal unit, e.g. second, not index.

Returns:

torch.Tensor (# of timesteps, state dim)

class neuromancer.dynamics.interpolation.LinInterp_Online[source]

Bases: Interpolation

interpolation(tq, t, u)[source]

neuromancer.dynamics.ode module

class neuromancer.dynamics.ode.BrusselatorHybrid(block, insize=2, outsize=2)[source]

Bases: ODESystem

ode_equations(x)[source]
class neuromancer.dynamics.ode.BrusselatorParam(insize=2, outsize=2)[source]

Bases: ODESystem

ode_equations(x)[source]
class neuromancer.dynamics.ode.CSTR_Param(insize=3, outsize=2)[source]

Bases: ODESystem

ode_equations(x, u)[source]
class neuromancer.dynamics.ode.DuffingParam(insize=3, outsize=2)[source]

Bases: ODESystem

ode_equations(x, u)[source]
class neuromancer.dynamics.ode.GeneralNetworkedODE(map=None, agents=None, couplings=None, insize=None, outsize=None, inductive_bias='additive')[source]

Bases: ODESystem

Coupled nonlinear dynamical system with heterogeneous agents. This class acts as an aggregator for multiple interacting physics that contribute to the dynamics of one or more agents.

coupling_physics(x, *args)[source]

This coupling physics assumes that each coupling physics nn.Module contains the connection information, including what agents are connected and if the connection is symmetric.

intrinsic_physics(x, *args)[source]

Calculate and return the contribution from all agents’ intrinsic physics

ode_equations(x, *args)[source]
Select the inductive bias to use for the problem:
  • Additive: f(x_i) + sum(g(x_i,x_j))

  • General: f(x_i, sum(g(x_i,x_j)))

  • Composed: f(sum(g(x_i,x_j)))

class neuromancer.dynamics.ode.LorenzControl(insize=5, outsize=3)[source]

Bases: ODESystem

ode_equations(x, u)[source]
class neuromancer.dynamics.ode.LorenzParam(insize=3, outsize=3)[source]

Bases: ODESystem

ode_equations(x)[source]
class neuromancer.dynamics.ode.LotkaVolterraHybrid(block, insize=2, outsize=2)[source]

Bases: ODESystem

ode_equations(x)[source]
class neuromancer.dynamics.ode.LotkaVolterraParam(insize=2, outsize=2)[source]

Bases: ODESystem

ode_equations(x)[source]
class neuromancer.dynamics.ode.ODESystem(insize, outsize)[source]

Bases: Module, ABC

Class for defining RHS of arbitrary ODE functions, can be mix-and-matched according to expert knowledge.

forward(x, *args)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

abstract ode_equations(x, *args)[source]
class neuromancer.dynamics.ode.SSM(fx, fu, nx, nu, fd=None, nd=0)[source]

Bases: Module

Baseline class for (neural) state space model (SSM) Implements discrete-time dynamical system:

x_k+1 = fx(x_k) + fu(u_k) + fd(d_k)

with variables:

x_k - states u_k - control inputs d_k - disturbances

forward(x, u, d=None)[source]
Parameters:
  • x – (torch.Tensor, shape=[batchsize, nx])

  • u – (torch.Tensor, shape=[batchsize, nu])

  • d – (torch.Tensor, shape=[batchsize, nd])

Returns:

(torch.Tensor, shape=[batchsize, outsize])

class neuromancer.dynamics.ode.TwoTankParam(insize=4, outsize=2)[source]

Bases: ODESystem

ode_equations(x, u)[source]
class neuromancer.dynamics.ode.VanDerPolControl(insize=3, outsize=2)[source]

Bases: ODESystem

ode_equations(x, u)[source]

neuromancer.dynamics.physics module

class neuromancer.dynamics.physics.Agent(state_names)[source]

Bases: Module, ABC

An agent is an object in a networked or otherwise distributed system that can: - have some intrinsic physics - serve as anchor for connections (pins)

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

abstract intrinsic(x)[source]
class neuromancer.dynamics.physics.DeltaTemp(R=Parameter containing: tensor(1., requires_grad=True), feature_name='T', symmetric=False, pins=[])[source]

Bases: Interaction

Interaction physics for difference in temperature (assumed) between agents.

interact(x)[source]
class neuromancer.dynamics.physics.DeltaTempSwitch(R=Parameter containing: tensor([1.], requires_grad=True), feature_name='T', symmetric=False, pins=[])[source]

Bases: Interaction

Interaction physics for difference in temperature (assumed) between agents. Switched on/off depending on agent values (zero or nonzero).

interact(x)[source]
class neuromancer.dynamics.physics.HVACConnection(feature_name='T', symmetric=False, pins=[])[source]

Bases: Interaction

Imposition of a source term as an interaction.

interact(x)[source]
class neuromancer.dynamics.physics.Interaction(feature_name, pins, symmetric)[source]

Bases: Module, ABC

An interaction is a physical connection between agents: - interactions are pairwise - interactions can be one-sided or symmetric (influence both agents)

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

abstract interact(x)[source]
class neuromancer.dynamics.physics.RCNode(C=Parameter containing: tensor([1.], requires_grad=True), state_names=['T'], scaling=1.0)[source]

Bases: Agent

RCNode agent. The intrinsic action of the agent is to effectively scale the interaction physics according to the capacitance of the agent. Examples include lumped volumes, rooms, etc.

intrinsic(x)[source]
class neuromancer.dynamics.physics.SourceSink(state_names=['T'])[source]

Bases: Agent

Generic Source / Sink agent. Useful for ‘dummy’ agents to which one can attach external signals.

intrinsic(x)[source]
neuromancer.dynamics.physics.map_from_agents(intrinsic_list)[source]

Quick helper function to construct state mappings:

Module contents