sim

package
v1.4.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureInputComponent

func ConfigureInputComponent(comp runtime.Component, signal runtime.SignalID) *runtime.ConfiguredComponent

ConfigureInputComponent takes an input component and creates a Component which outputs signal with given name on its "output" poruntime.

func ConfigureOutputComponent

func ConfigureOutputComponent(signal runtime.SignalID, comp runtime.Component) *runtime.ConfiguredComponent

ConfigureOutputComponent takes an output component and creates a Component which reads signal with a given name on its "input" port.

func NewConstantInput

func NewConstantInput(value float64) runtime.Component

NewConstantInput creates a constant-value input.

func SanitizeYaml

func SanitizeYaml(source string) (string, error)

SanitizeYaml cleans up indentation of multiline string literal with yaml.

This is needed as yaml parsing will otherwise fail on tabs.

func ToRtReadings

func ToRtReadings(readings []Reading) []rt.Reading

ToRtReadings converts Readings to rt.Readings.

Types

type Circuit

type Circuit struct {
	// contains filtered or unexported fields
}

Circuit is a simulated circuit intended to be used in tests.

func NewCircuit

func NewCircuit(
	components []*runtime.ConfiguredComponent,
	inputs Inputs,
	outputSignals OutputSignals,
) (*Circuit, error)

NewCircuit creates a new simulated Circuit.

func NewCircuitFromYaml

func NewCircuitFromYaml(
	circuitYaml string,
	inputs Inputs,
	outputSignals OutputSignals,
) (*Circuit, error)

NewCircuitFromYaml creates a new simulated Circuit based on yaml circuit description.

Differences from real circuit: * Fx options for components will be ignored.

func (*Circuit) Run

func (s *Circuit) Run(steps int) Outputs

Run runs given number of tick of circuit execution and returns values of output signals.

func (*Circuit) RunDrainInputs

func (s *Circuit) RunDrainInputs() Outputs

RunDrainInputs runs the circuit for as long as inputs are defined.

Returns values of output signals. There must be at least one input of type Input defined and all of them must have same lengths.

func (*Circuit) Step

func (s *Circuit) Step() StepOutputs

Step runs one tick of circuit execution and returns values of output signals.

type Input

type Input []runtime.Reading

Input is a component that will emit signal from the given array – one Reading per tick. On subsequent ticks, it will emit Invalid readings.

func NewInput

func NewInput(values []float64) *Input

NewInput creates an input from an array of floats.

func (*Input) DynamicConfigUpdate

func (i *Input) DynamicConfigUpdate(_ notifiers.Event, _ config.Unmarshaller)

DynamicConfigUpdate implements runtime.Component.

func (*Input) Execute

Execute implements runtime.Component.

func (*Input) IsActuator added in v1.1.0

func (*Input) IsActuator() bool

IsActuator implements runtime.Component.

func (*Input) Name

func (i *Input) Name() string

Name implements runtime.Component.

func (*Input) ShortDescription added in v0.22.0

func (i *Input) ShortDescription() string

ShortDescription implements runtime.Component.

func (*Input) Type

func (i *Input) Type() runtime.ComponentType

Type implements runtime.Component.

type Inputs

type Inputs map[string]runtime.Component

Inputs map root signal names to components that will emit test input. Input components are required to emit an "output" signal, such as Input or components.Variable. These can be created with NewInput and NewConstantInput.

type OutputSignals

type OutputSignals []string

OutputSignals is a list of root signal names that comprise test output.

type Outputs

type Outputs map[string][]Reading

Outputs map signal names to captured output readings.

type Reading

type Reading struct {
	// contains filtered or unexported fields
}

Reading is implementation of rt.Reading designed for tests.

It avoids the problem of invalid readings being non-equal due to being represented as NaNs, so that comparing invalid readings works as expected.

func InvalidReading

func InvalidReading() Reading

InvalidReading creates a new invalid Reading.

func NewReading

func NewReading(value float64) Reading

NewReading creates a Reading from a float. NaN is treated as invalid reading.

func NewReadings

func NewReadings(values []float64) []Reading

NewReadings creates a slice of readings from a slice of floats.

func ReadingFromRt

func ReadingFromRt(rtReading rt.Reading) Reading

ReadingFromRt converts runtime.Reading to Reading.

func ReadingsFromRt

func ReadingsFromRt(rtReadings []rt.Reading) []Reading

ReadingsFromRt converts runtime.Readings to Readings.

func (Reading) Valid

func (r Reading) Valid() bool

Valid implements runtime.Reading.

func (Reading) Value

func (r Reading) Value() float64

Value implements runtime.Reading.

type StepOutputs added in v0.22.0

type StepOutputs map[string]Reading

StepOutputs map signal names to captured output readings for a single step.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL