copapy.LocalTarget#

class copapy.LocalTarget(arch='native', optimization='O3', tick=0.0001)#

Bases: _LocalMemory, _TaskTarget

Target running tasks in this process with simulated time

Initialize the target

Parameters:
  • arch (str) – Target architecture

  • optimization (str) – Optimization level

  • tick (float) – Time step of the simulation in seconds, the periods of the tasks must be multiples of it

bind(variable, channel)#

Binds a value to an I/O channel of the device. Bindings are used by the next deploy.

A copapy value (input) reads the channel at the release of each task using it, it can not be written by write_value anymore. On an output channel it reads back the level of the output.

A value computed by a task writes the output channel when the task publishes its outputs. The value must be an output of the task.

Parameters:
  • variable (value[Any]) – Value to bind, of the type of the channel (see IoChannel.kind)

  • channel (IoChannel) – Channel of the target, e.g. target.io.gpio(‘led’)

Return type:

None

buffer(variable)#

Returns memory of an array on the target as memoryview.

Only available for the local target. All buffers must be released or deleted before a new program is compiled on the same target.

Parameters:

variable (array[Any]) – Array-variable to get the memory of

Return type:

memoryview[Any]

Returns:

Writable memoryview of the array memory

deploy(*tasks)#

Compiles the tasks for the target and loads them. Previously deployed tasks are removed.

Parameters:

tasks (Any) – Tasks or sequences of tasks. All other arguments (values, vectors, tensors, arrays and sequences of them) are the outputs of one additional task without period.

Return type:

None

exec(task=None)#

Runs one job of a deployed task: reading inputs, computing and publishing the outputs.

Parameters:

task (Task | None) – Task to run, can be omitted if only one task is deployed

Return type:

None

read_value(variables)#

Reads the numeric value of a copapy type.

Overloads:
  • variables (value[T]) → T

  • variables (value[int] | value[float] | int | float) → float | int | bool

  • variables (ArrayType[T]) → ArrayType[T]

  • variables (Iterable[T | value[T]]) → list[T]

  • variables (array[T]) → Any

  • variables (Any) → Any

Parameters:

variables (Any) – Variable or multiple variables to read

Returns:

Numeric value or values. Arrays are returned as nested lists, arrays marked with map_to_buffer or map_to_numpy as memoryview or numpy array. Sequences and dicts are returned as lists and dicts of the values of their items.

sdb: stencil_database#
stats(task=None)#

Statistics of a deployed task. On devices the statistics are reset by run().

Parameters:

task (Task | None) – Task, can be omitted if only one task is deployed

Returns:

  • runs: Number of jobs run

  • overruns: Number of skipped releases because the previous job was not finished

  • exec_time: CPU time of the last job in seconds (without the time the job was preempted by other tasks)

  • exec_time_max: Maximum CPU time of a job in seconds

  • exec_time_mean: Mean CPU time of the jobs in seconds

  • response_time_max: Maximum time from the release to the end of a job in seconds (must be below the period)

  • start_delay_max: Maximum time from the release to the start of a job in seconds

  • degraded: The task currently runs with lower priority than the communication with the host, because the tasks used too much CPU time (load shedding on devices)

  • degradations: Number of times the task was degraded

Return type:

dict[str, Any]

step(until)#

Runs the periodic tasks in simulated time up to the given time. All tasks released before this time are run. Outputs are published up to this time: inputs written afterwards are read by the tasks released at this time or later.

Parameters:

until (float) – Simulated time in seconds since deploy, a multiple of the tick

Return type:

None

tick: float#
property time: float#

Simulated time in seconds since deploy

write_value(variables, data)#

Write to a copapy value on the target.

Parameters:
  • variables (value[Any] | array[Any] | Iterable[value[Any]]) – Single variable, array or multiple variables to overwrite

  • value – Single value or multiple values to write, (nested) sequences for arrays

Return type:

None