Documentation ¶
Index ¶
- Constants
- func CircuitModule() fx.Option
- func Compile(configuredComponents []*ConfiguredComponent, logger *log.Logger) error
- type Circuit
- func (circuit *Circuit) DynamicConfigUpdate(event notifiers.Event, unmarshaller config.Unmarshaller)
- func (circuit *Circuit) Execute(tickInfo TickInfo) error
- func (circuit *Circuit) LockExecution()
- func (circuit *Circuit) RegisterTickEndCallback(ec TickEndCallback)
- func (circuit *Circuit) RegisterTickStartCallback(sc TickStartCallback)
- func (circuit *Circuit) UnlockExecution()
- type CircuitAPI
- type CircuitMetrics
- type Component
- type ComponentID
- type ComponentType
- type ConfiguredComponent
- type ConstantSignal
- type PortMapping
- func (p *PortMapping) AddInPort(portName string, signals []Signal)
- func (p *PortMapping) AddOutPort(portName string, signals []Signal)
- func (p *PortMapping) GetInPort(portName string) ([]Signal, bool)
- func (p *PortMapping) GetOutPort(portName string) ([]Signal, bool)
- func (p *PortMapping) Merge(other PortMapping) error
- type PortToReading
- type PortToSignals
- type Reading
- type Signal
- type SignalID
- type SignalType
- type TickEndCallback
- type TickInfo
- type TickStartCallback
Constants ¶
const ( // NestedComponentDelimiter is the delimiter used to separate the parent circuit ID and the nested circuit ID. NestedComponentDelimiter = "." // RootComponentID is the ID of the root component. RootComponentID = "root" )
const ( // SignalTypeNamed is a named signal. SignalTypeNamed = iota // SignalTypeConstant is a constant signal. SignalTypeConstant )
Variables ¶
This section is empty.
Functions ¶
func CircuitModule ¶
CircuitModule returns fx options of Circuit for the main app.
Types ¶
type Circuit ¶
Circuit manages the runtime state of a set of components and their inter linkages via signals.
func NewCircuitAndOptions ¶
func NewCircuitAndOptions( configuredComponents []*ConfiguredComponent, policyReadAPI iface.Policy, ) (*Circuit, fx.Option)
NewCircuitAndOptions create a new Circuit struct along with fx options.
func (*Circuit) DynamicConfigUpdate ¶ added in v0.4.0
func (circuit *Circuit) DynamicConfigUpdate(event notifiers.Event, unmarshaller config.Unmarshaller)
DynamicConfigUpdate updates the circuit with the new dynamic config.
func (*Circuit) Execute ¶
Execute runs one tick of computations of all the Components in the Circuit.
func (*Circuit) LockExecution ¶
func (circuit *Circuit) LockExecution()
LockExecution locks the execution of the circuit.
func (*Circuit) RegisterTickEndCallback ¶
func (circuit *Circuit) RegisterTickEndCallback(ec TickEndCallback)
RegisterTickEndCallback adds a callback function to be called when a tick ends.
func (*Circuit) RegisterTickStartCallback ¶ added in v0.2.1
func (circuit *Circuit) RegisterTickStartCallback(sc TickStartCallback)
RegisterTickStartCallback adds a callback function to be called when a tick starts.
func (*Circuit) UnlockExecution ¶
func (circuit *Circuit) UnlockExecution()
UnlockExecution unlocks the execution of the circuit.
type CircuitAPI ¶
type CircuitAPI interface { iface.Policy RegisterTickEndCallback(ec TickEndCallback) RegisterTickStartCallback(sc TickStartCallback) LockExecution() UnlockExecution() }
CircuitAPI is for read only access to policy and also provides methods for acquiring & releasing circuit execution lock.
type CircuitMetrics ¶
type CircuitMetrics struct {
SignalSummaryVec *prometheus.SummaryVec
}
CircuitMetrics holds prometheus metrics related circuit.
type Component ¶
type Component interface { Execute(inPortReadings PortToReading, tickInfo TickInfo) (outPortReadings PortToReading, err error) DynamicConfigUpdate(event notifiers.Event, unmarshaller config.Unmarshaller) // Generic name of the component, eg. "Gradient" Name() string Type() ComponentType // ShortDescription is used when generating mermaid or dot diagrams. ShortDescription() string // IsActuator returns true if the component is an actuator. IsActuator() bool }
Component is the interface that all components must implement.
func NewDummyComponent ¶ added in v0.14.0
func NewDummyComponent(name, shortDescription string, componentType ComponentType) Component
NewDummyComponent creates a component with provided name and type.
type ComponentID ¶ added in v0.21.0
type ComponentID interface { String() string ChildID(id string) ComponentID ParentID() (ComponentID, bool) }
ComponentID is a unique identifier for a component.
func NewComponentID ¶ added in v0.21.0
func NewComponentID(id string) ComponentID
NewComponentID creates a new ComponentID.
type ComponentType ¶
type ComponentType string
ComponentType describes the type of a component based on its connectivity in the circuit.
const ( // ComponentTypeStandAlone is a component that does not accept or emit any // signals. ComponentTypeStandAlone ComponentType = "StandAlone" // ComponentTypeSource is a component that emits output signal(s) but does // not accept an input signal. ComponentTypeSource ComponentType = "Source" // ComponentTypeSink is a component that accepts input signal(s) but does // not emit an output signal. ComponentTypeSink ComponentType = "Sink" // ComponentTypeSignalProcessor is a component that accepts input signal(s) // and emits output signal(s). ComponentTypeSignalProcessor ComponentType = "SignalProcessor" )
type ConfiguredComponent ¶ added in v0.15.0
type ConfiguredComponent struct { Component // Which signals this component wants to have connected on its ports. PortMapping PortMapping // Mapstruct representation of proto config that was used to create this // component. This Config is used only for observability purposes. // // Note: PortMapping is also part of Config. Config mapstruct.Object // ComponentID is the unique ID of this component within the circuit. ComponentID ComponentID }
ConfiguredComponent consists of a Component and its PortMapping.
type ConstantSignal ¶ added in v0.21.0
type ConstantSignal struct { SpecialValue string `mapstructure:"special_value"` Value float64 `mapstructure:"value"` }
ConstantSignal is a mirror struct to same proto message.
func ConstantSignalFromProto ¶ added in v1.1.0
func ConstantSignalFromProto(constantSignalProto *policylangv1.ConstantSignal) *ConstantSignal
ConstantSignalFromProto creates a ConstantSignal from a proto message.
func (*ConstantSignal) Description ¶ added in v1.1.0
func (constantSignal *ConstantSignal) Description() string
Description returns a description of the constant signal.
func (*ConstantSignal) Float ¶ added in v1.1.0
func (constantSignal *ConstantSignal) Float() float64
Float returns the float value of the constant signal.
type PortMapping ¶ added in v0.15.0
type PortMapping struct { // Note: Not using policylangv1.InPort and OutPort directly to avoid // runtime depending on proto. Ins PortToSignals `mapstructure:"in_ports"` Outs PortToSignals `mapstructure:"out_ports"` }
PortMapping is description of a component's ports mapping.
This struct is meant to be decodable from Mapstruct representation of _any_ of the components's config. Eg. EMA component defines:
```proto
message Ins { InPort input = 1; }
Ins in_ports = 1; ... ```
And such EMA component's config could be encoded and then decoded into PortMapping as:
```go
PortMapping { InPorts: map[string]InPort { "input": []InPort {{ ... }}, }, }
```
Note how "input" is a concrete field in EMA definition, but a dynamic map key in PortMapping.
func NewPortMapping ¶ added in v0.21.0
func NewPortMapping() PortMapping
NewPortMapping creates a new PortMapping.
func PortsFromComponentConfig ¶ added in v0.15.0
func PortsFromComponentConfig(componentConfig mapstruct.Object, subCircuitID string) (PortMapping, error)
PortsFromComponentConfig extracts Ports from component's config.
func (*PortMapping) AddInPort ¶ added in v0.21.0
func (p *PortMapping) AddInPort(portName string, signals []Signal)
AddInPort adds an input port to the PortMapping.
func (*PortMapping) AddOutPort ¶ added in v0.21.0
func (p *PortMapping) AddOutPort(portName string, signals []Signal)
AddOutPort adds an output port to the PortMapping.
func (*PortMapping) GetInPort ¶ added in v0.21.0
func (p *PortMapping) GetInPort(portName string) ([]Signal, bool)
GetInPort returns true if the port exists in the PortMapping.
func (*PortMapping) GetOutPort ¶ added in v0.21.0
func (p *PortMapping) GetOutPort(portName string) ([]Signal, bool)
GetOutPort returns true if the port exists in the PortMapping.
func (*PortMapping) Merge ¶ added in v0.21.0
func (p *PortMapping) Merge(other PortMapping) error
Merge merges two PortMappings.
type PortToReading ¶ added in v0.21.0
PortToReading is a map from port name to a slice of Readings.
func (PortToReading) ReadRepeatedReadingPort ¶ added in v0.21.0
func (ptr PortToReading) ReadRepeatedReadingPort(portName string) []Reading
ReadRepeatedReadingPort returns the reading of all the signals at port=portName. If no signal is found, []Reading{} empty list is returned.
func (PortToReading) ReadSingleReadingPort ¶ added in v0.21.0
func (ptr PortToReading) ReadSingleReadingPort(portName string) Reading
ReadSingleReadingPort returns the reading of the first signal at port=portName. If no signal is found, InvalidReading() is returned.
type PortToSignals ¶ added in v0.21.0
PortToSignals is a map from port name to a list of signals.
type Reading ¶ added in v0.2.1
Reading is the interface that reading implements which wraps a float Value which can be valid or invalid.
func InvalidReading ¶ added in v0.2.1
func InvalidReading() Reading
InvalidReading creates a reading with 'value' set to math.NaN(), invalid value.
func NewReading ¶ added in v0.2.1
NewReading creates a reading with the given value.
type Signal ¶
type Signal struct { SubCircuitID string SignalName string `mapstructure:"signal_name"` ConstantSignal ConstantSignal `mapstructure:"constant_signal"` Looped bool }
Signal describes an input or output port of a component
Only one field should be set.
func (*Signal) ConstantSignalValue ¶ added in v0.21.0
ConstantSignalValue returns the value of the constant signal.
func (*Signal) SignalType ¶ added in v0.5.0
func (s *Signal) SignalType() SignalType
SignalType returns the Signal type of the port.
type SignalID ¶ added in v0.21.0
SignalID is a unique identifier for a signal.
func MakeRootSignalID ¶ added in v0.21.0
MakeRootSignalID creates SignalID with "root" SubCircuitID.
type TickEndCallback ¶
TickEndCallback is a function that is called when a tick ends.
type TickInfo ¶
type TickInfo interface { Timestamp() time.Time Tick() int Interval() time.Duration Serialize() *policysyncv1.TickInfo String() string }
TickInfo is the interface that trackInfo implements which contains information about the current tick.
type TickStartCallback ¶ added in v0.2.1
TickStartCallback is a function that is called when a tick starts.