pySimBlocks.blocks.systems.non_linear_state_space

class pySimBlocks.blocks.systems.non_linear_state_space.NonLinearStateSpace(name: str, state_function: Callable, output_function: Callable, input_keys: List[str], output_keys: List[str], x0: ndarray, sample_time: float | None = None)[source]

Bases: Block

User-defined nonlinear state-space block.

Implements a nonlinear discrete-time system driven by two user-provided callables:

x[k+1] = state_function(t, dt, x, u1, u2, …)

y[k] = output_function(t, dt, x)

Input and output port names are declared dynamically via input_keys and output_keys. All inputs and outputs must be column vectors of shape (n, 1).

input_keys

Names of the input ports.

output_keys

Names of the output ports.

direct_feedthrough = False

True if outputs depend directly on inputs.

is_source = False

True if the block produces signals with no inputs.

classmethod adapt_params(params: Dict[str, Any], params_dir: Path | None = None) Dict[str, Any][source]

Load state and output callables from file_path YAML keys.

Parameters:
  • params – Raw parameter dict loaded from the YAML project file.

  • params_dir – Directory of the project file, for resolving relative paths. Must not be None.

Returns:

Parameter dict with state_function and output_function set to the loaded callables, and file_path, state_function_name, output_function_name keys removed.

Raises:
  • ValueError – If params_dir is None or if required keys are missing from params.

  • FileNotFoundError – If the function file does not exist.

  • AttributeError – If a named function is not found in the module.

  • TypeError – If a resolved attribute is not callable.

initialize(t0: float) None[source]

Validate function signatures and declare input/output ports.

Parameters:

t0 – Initial simulation time in seconds.

output_update(t: float, dt: float) None[source]

Call the output function and write results to the output ports.

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.

state_update(t: float, dt: float) None[source]

Call the state function and store the next state.

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.

Raises:
  • TypeError – If any input value is not a numpy array.

  • ValueError – If any input does not have shape (n, 1).