Wrapper

class pathsim.blocks.wrapper.Wrapper(func=None, T=1, tau=0)[source]

Bases: Block

Wrapper block for discrete implementation and external code integration.

The Wrapper class is designed to call the internal func at fixed intervals using an internal Schedule event. This makes it particularly useful for wrapping external code or implementing discrete-time systems.

Essentially this block does the same as Function with the difference that its not evaluated continuously but periodically at discrete times.

Example

There are two ways to setup the Wrapper, first and standard way is to define a function to be wrapped and pass it to the block initializer:

from pathsim.blocks import Wrapper

#function to be wrapped
def func(a, b, c):
    return a * (b + c)

wrp = Wrapper(func, T=0.1)

Another option is to use the dec classmethod, which might be more convenient in some situations:

from pathsim.blocks import Wrapper

@Wrapper.dec(T=0.1)
def wrp(a, b, c):
    return a * (b + c)

This way the internal function of the block wrp will be evaluated with a period of T=0.1 and its outputs updated accordingly.

Parameters:
  • func (callable) – function that defines algebraic block IO behaviour

  • T (float) – sampling period for the wrapped function

  • tau (float) – delay time for the start time of the event

Evt

internal event. Used for periodic sampling the wrapped method

Type:

Schedule

update(t)[source]

Update system equation for fixed point loop.

Note

No direct passthrough, the Wrapper block doesnt implement the update method. The behavior is defined by the func arg.

Parameters:

t (float) – evaluation time

property tau

Getter for tau

Returns:

tau – delay time for the Schedule event

Return type:

float

property T

Get the sampling period of the block

Returns:

T – sampling period for the Schedule event

Return type:

float

classmethod dec(T=1, tau=0)[source]

decorator for direct instance construction from func

Example

Decorate a function definition to directly make it a Wrapper block instance:


from pathsim.blocks import Wrapper

@Wrapper.dec(T=0.1) def wrp(a, b, c):

return a * (b + c)

Parameters:
  • tau (float) – delay time for the start time of the wrapper sampling

  • T (float) – sampling period for calling the wrapped function