xir

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

README

Documentation

Overview

Package XIR provides Go language bindings to the MergeTB eXperiment Intermediate Representation. XIR is a simple network represenatation where

The primary components are:

  • (sub)networks
  • nodes
  • links

Everything is extensible through a property map member called Props.

Interconnection model supports node-neighbor traversal as well as link-endpoint traversal.

Endpoints are the glue that bind nodes to links. Everything is also upwards traversable. You can follow pointers from an endpoint to a parent node, and then to a parent network, and then to another parent network etc...

Serialization to json is inherent. It does not include the traversal mechanisims as this would create recursively repeditive output.

Properties are represented as map[string]interface{} objects and follow the general notion of being JSON blobs. For Example

 {
   "construction": {
     "procs": [
       {
         "cores": {"constraint__": ">", "value__": 2}
       }
    ]
  },
  "configuration": {
    "os": {"constraint": "=", "value__": "ubuntu-18.04"}
  }
}

Every XIR element has a construction and a configuration. Construction contains the fundamental properites of an element and configuration contains and elements soft configuration.

XIR is used in two contexts:

  1. Experiment specification
  2. Resource specification

For experiment sepcification, properties map to constraints that define what a valid resource is for the given element. For resource specification properties map to simple values over which constraints can be evaluated.

Index

Constants

View Source
const (
	EQ     Operator = "="
	LT              = "<"
	LE              = "<="
	GT              = ">"
	GE              = ">="
	CHOICE          = "?"
	SELECT          = "[]"
)

Variables

This section is empty.

Functions

func B

func B(value uint64) uint64

B scales the given value to bytes

func Bps

func Bps(value uint64) uint64

Bps scales the given value in bits to bits per second

func EB

func EB(value uint64) uint64

EB scales the given value in bytes to exabytes

func Ebps

func Ebps(value uint64) uint64

Ebps scales the given value in bits to exabits per second

func GB

func GB(value uint64) uint64

GB scales the given value in bytes to gigabytes

func GHz

func GHz(value float64) float64

GHz scales the given Hz value to GHz

func Gbps

func Gbps(value uint64) uint64

Gbps scales the given value in bits to gigabits per second

func Hz

func Hz(value float64) float64

Hz scales the given Hz value to Hz

func IsArray

func IsArray(unk interface{}) bool

func IsMap

func IsMap(unk interface{}) bool

func IsValidOp

func IsValidOp(x Operator) bool

func KB

func KB(value uint64) uint64

KB scales the given value in bytes to kilobytes

func KHz

func KHz(value float64) float64

KHz scales the given Hz value to KHz

func Kbps

func Kbps(value uint64) uint64

Kbps scales the given value in bits to kilobits per second

func LiftConstraints

func LiftConstraints(x interface{}) interface{}

LiftConstraints and ExtractConstraints are a pair of mutually recursive functions that traverse a property tree, identify constraints within the tree and lift any identified constraints into the constraint type

func LiftNetConstraints

func LiftNetConstraints(net *Net)

func LinkNetwork

func LinkNetwork(net *Net) error

LinkNetwork performs the business of internal pointer linking within a Net. When we read a Net from a file or database, the traversal pointers are not linked. This function ensures that all the traversal pointers in a Net data structure are linked.

func MB

func MB(value uint64) uint64

MB scales the given value in bytes to megabytes

func MHz

func MHz(value float64) float64

MHz scales the given Hz value to MHz

func Mbps

func Mbps(value uint64) uint64

Mbps scales the given value in bits to megabits per second

func Ms

func Ms(value float64) float64

Ms scales the given value in seconds to milliseconds

func Ns

func Ns(value float64) float64

Ns scales the given value in seconds to nanoseconds

func PB

func PB(value uint64) uint64

PB scales the given value in bytes to petabytes

func ParsePath

func ParsePath(path string) []string

ParsePath takes in a dot separated path and returns and ordered list of path components. For example node.memory.size* -> [node, memory, size*].

func Pbps

func Pbps(value uint64) uint64

Pbps scales the given value in bits to petabits per second

func Percent

func Percent(value float64) float64

Percent scales the given integer value to a percent of 100

func PrepNetwork

func PrepNetwork(net *Net)

PrepNetwork ensures that all the Neighbor maps are ready. They are not ready upon deserialization. This is a precondition to LinkNetwork

func S

func S(value float64) float64

S scales the given value in seconds to seconds

func TB

func TB(value uint64) uint64

TB scales the given value in bytes to terabytes

func THz

func THz(value float64) float64

THz scales the given Hz value to THz

func Tbps

func Tbps(value uint64) uint64

Tbps scales the given value in bits to terabits per second

func ToFile

func ToFile(net *Net, filename string) error

ToFile writes the specified Net to the specified filename

func Unit

func Unit(qual string, value float64, unit string) map[string]interface{}

func Us

func Us(value float64) float64

Us scales the given value in seconds to microseconds

Types

type AssetObject

type AssetObject struct {
	ID   string `json:"id"`
	Type string `json:"type"`
	Size int64  `json:"size"`
}

Asset is object that will reside on the other side of the mount ID: name of the asset object Type: type of device to mount (fs, block, image) Size: total allocated size, required for block sizes

type Bounds

type Bounds struct {
	Left, Right, Top, Bottom float64
}

func (*Bounds) Consume

func (b *Bounds) Consume(x Bounds, c Vec2)

type Constraint

type Constraint struct {
	Op    Operator    `json:"constraint__"`
	Value interface{} `json:"value__"`
}

func Choice

func Choice(value interface{}) Constraint

func Eq

func Eq(value interface{}) Constraint

func ExtractConstraint

func ExtractConstraint(m map[string]interface{}) (Constraint, bool)

func Ge

func Ge(value interface{}) Constraint

func Gt

func Gt(value interface{}) Constraint

func Le

func Le(value interface{}) Constraint

func Lt

func Lt(value interface{}) Constraint

func Select

func Select(value interface{}) Constraint

func (*Constraint) Int

func (c *Constraint) Int() (int, bool)

Int attempts to return a constaint value as an int. If the underlying value is floating point it will be cast to an int.

type Endpoint

type Endpoint struct {
	Id        string               `json:"id"`
	Props     Props                `json:"props"`
	Neighbors map[string]*Neighbor `json:"-" yaml:"-"`
	Parent    *Node                `json:"-" yaml:"-"`

	Loc Vec2 `yaml:"-"`
}

func (*Endpoint) Global

func (n *Endpoint) Global() Point

func (*Endpoint) Label

func (e *Endpoint) Label() string

Label attempts to return the friendliest label that can be applied to a Node. If the Node has a name in its properties, that is returned. Otherwise the Nodes's uuid is returned.

func (*Endpoint) Position

func (n *Endpoint) Position() *Point

func (*Endpoint) Set

func (e *Endpoint) Set(p Props) *Endpoint

Set sets the provided properties on this Endpoint. This is a logical merge, any resident properties with the same key will be overwritten. Non-colliding resident properties will remain in tact.

func (*Endpoint) Tag

func (e *Endpoint) Tag(tags ...string) *Endpoint

Tag an endpoint

func (*Endpoint) Velocity

func (n *Endpoint) Velocity() *Point

type Endpoints

type Endpoints []*Endpoint

func (Endpoints) Has

func (es Endpoints) Has(key string, value interface{}) Endpoints

func (Endpoints) Next

func (es Endpoints) Next() *Endpoint

func (Endpoints) Proto

func (es Endpoints) Proto(proto interface{}) Endpoints

func (Endpoints) RNext

func (es Endpoints) RNext() *Endpoint

func (Endpoints) Tag

func (es Endpoints) Tag(tag string) Endpoints
type Link struct {
	Id        string      `json:"id"`
	Endpoints []*Endpoint `json:"endpoints"`
	Props     Props       `json:"props"`
}

func (*Link) Clone

func (l *Link) Clone() *Link

Clone creates a deep clone of this Link.

func (*Link) IsLocal

func (l *Link) IsLocal() bool

IsLocal determines if all endpoints in a link belong to the same Net.

func (*Link) Label

func (l *Link) Label() string

Label attempts to return the friendliest label that can be applied to a Link. If the Link has a name in its properties, that is returned. Otherwise a a string concatenating the parent Node label of each Endpoint in the link over tildas is returned. For example "a~b~c".

func (*Link) Set

func (l *Link) Set(p Props) *Link

Set sets the provided properties on this Link. This is a logical merge, any resident properties with the same key will be overwritten. Non-colliding resident properties will remain in tact.

type Mount

type Mount struct {
	Path  string      `json:"path"`
	Asset AssetObject `json:"asset"`
}

Mount is a device or filesystem mounted to a device Path: where the mount will reside locally

type Neighbor

type Neighbor struct {
	Link     *Link
	Endpoint *Endpoint
}

type Net

type Net struct {
	Id     string  `json:"id"`
	Nodes  []*Node `json:"nodes"`
	Links  []*Link `json:"links"`
	Nets   []*Net  `json:"nets"`
	Props  Props   `json:"props"`
	Parent *Net    `json:"-" yaml:"-"`

	Loc Vec2 `yaml:"-"`
}

func FromFile

func FromFile(filename string) (*Net, error)

FromFile reads an XIR Net from the given file. The file should contain the JSON representation of a Net as produced by ToFile().

func FromString

func FromString(s string) (*Net, error)

FromString reads and XIR Net from a string. The string should contain the JSON representation of a Net as produced by ToString().

func NewNet

func NewNet() *Net

NewNet creates a new empty Net object.

func (n *Net) AddLink(link *Link)

func (*Net) AddNet

func (n *Net) AddNet(net *Net)

AddNet adds an existing Net object to this Net as a subnetwork.

func (*Net) AddNode

func (n *Net) AddNode(node *Node)

AddNode adds an existing node to this Net

func (n *Net) AllLinks() []*Link

func (*Net) AllNodes

func (n *Net) AllNodes() []*Node

func (*Net) Bounds

func (net *Net) Bounds() Bounds

func (*Net) Clone

func (n *Net) Clone() *Net

Clone creates a deep clone of this Net.

func (n *Net) DeleteLink(uuid string) *Link

DeleteLink deletes a Link from this Net. This is a recursive operation.

func (*Net) DeleteNode

func (n *Net) DeleteNode(uuid string) *Node

DeleteNode deletes a Node from this Net. This is a recursive operation.

func (*Net) DeleteSubnet

func (n *Net) DeleteSubnet(uuid string) *Net

DeleteSubnet deletes a subnet from this network with the specified uuid. This deletion is not recursive.

func (*Net) Dump

func (n *Net) Dump()

func (*Net) GetElementProps

func (n *Net) GetElementProps(uuid string) *Props

GetElementProps searches for a Node or Link in this network with the specified uuid and returns it properties. This search is recursive.

func (n *Net) GetLink(uuid string) (int, *Net, *Link)

GetLink finds a Link with the specified uuid and returns its index within its parent Net, a pointer to its parent Net and a pointer to the Link itself.

func (*Net) GetNode

func (n *Net) GetNode(uuid string) (int, *Net, *Node)

GetNode finds a Node with the specified uuid and returns its index within its parent Net, a pointer to its parent Net, and a pointer to the Node itself.

func (*Net) GetNodeByName

func (n *Net) GetNodeByName(name string) (int, *Net, *Node)

GetNodeByName searches this Net for a node with the given name. This is not a recursive search.

func (*Net) GetNodeEndpointById

func (n *Net) GetNodeEndpointById(id string) *Endpoint

GetNodeEndpointById searches this Net for an Endpoint with the given uuid. This is a recursive search.

func (*Net) GetSubnet

func (n *Net) GetSubnet(uuid string) (int, *Net)

GetSubnet searches for a Network with the specified uuid. This search is not recursive.

func (*Net) Global

func (n *Net) Global() Point

func (*Net) Json

func (n *Net) Json() ([]byte, error)

Json() serializes this Net to a JSON blob in a byte array

func (*Net) Label

func (n *Net) Label() string

Label attempts to return the friendliest label that can be applied to a Net. If the Net has a name in its properties, that is returned. Otherwise the Net's uuid is returned.

func (n *Net) Link(es ...*Endpoint) *Link

Link creates a new Link between the provided Endpoints, adds it to this network and returns a pointer to it.

func (*Net) Net

func (n *Net) Net() *Net

Net creates a new Net object and adds it as a subnetwork to this Net.

func (*Net) Node

func (n *Net) Node() *Node

Node creates a new Node, adds it to this Net and returns a pointer to it.

func (*Net) Position

func (n *Net) Position() *Point

func (*Net) Root

func (net *Net) Root() *Net

Root traverses upward from this Net until the root Net is found.

func (*Net) Select

func (n *Net) Select(f func(x *Node) bool) []*Node

func (*Net) Size

func (n *Net) Size() int

Size returns the total number of Nodes in this network.

func (*Net) String

func (n *Net) String() string

String returns a human digestable string representation of a network. This includes all subnetworks.

func (*Net) Table

func (n *Net) Table()

func (*Net) ToFile

func (n *Net) ToFile(filename string) error

ToFile serializes this Net to a JSON blob and saves it to the specified file.

func (*Net) ToString

func (n *Net) ToString() (string, error)

ToString serializes this Net to a JSON blob in a string.

func (*Net) Velocity

func (n *Net) Velocity() *Point

func (*Net) Yaml

func (n *Net) Yaml() string

type Node

type Node struct {
	Id        string    `json:"id"`
	Endpoints Endpoints `json:"endpoints"`
	Parent    *Net      `json:"-" yaml:"-"`
	Props     Props     `json:"props"`
	Visited   bool      `json:"-" yaml:"-"`
	Mounts    []*Mount  `json:"mounts"`

	Loc Vec2 `yaml:"-"`

	Pos Point `yaml:"-"`
	Vel Point `yaml:"-"`
}

func NewNode

func NewNode(p Props) *Node

NewNode creates a new empty Node object.

func (*Node) AddSoftware deprecated

func (n *Node) AddSoftware(p Props) *Node

Deprecated: do not use

func (*Node) Clone

func (n *Node) Clone() *Node

Clone make a deep clone of this Node.

func (*Node) Endpoint

func (n *Node) Endpoint() *Endpoint

Endpoint creates a new Endpoint, adds it to this Node and returns a pointer to it.

func (*Node) GetEndpoint

func (n *Node) GetEndpoint(label string) *Endpoint

func (*Node) GetEndpointId

func (n *Node) GetEndpointId(id string) *Endpoint

func (*Node) GetNeighbor

func (n *Node) GetNeighbor(id string) (*Endpoint, *Endpoint)

func (*Node) Global

func (n *Node) Global() Point

func (*Node) Label

func (n *Node) Label() string

Label attempts to return the friendliest label that can be applied to a Node. If the Node has a name in its properties, that is returned. Otherwise the Nodes's uuid is returned.

func (*Node) Neighbors

func (n *Node) Neighbors() []*Endpoint

Neighbors returns a list containing all this Node's neighbors. The list of endpoints returned are those of the neighbors.

func (*Node) Next

func (n *Node) Next(kind string) *Endpoint

func (*Node) PNext

func (n *Node) PNext(proto interface{}) *Endpoint

func (*Node) Position

func (n *Node) Position() *Point

func (*Node) RNext

func (n *Node) RNext(kind string) *Endpoint

func (*Node) Set

func (n *Node) Set(p Props) *Node

Set sets the provided properties on this Node. This is a logical merge, any resident properties with the same key will be overwritten. Non-colliding resident properties will remain in tact.

func (*Node) Valence

func (n *Node) Valence() int

Valence returns the number of neigbors this node has.

func (*Node) Velocity

func (n *Node) Velocity() *Point

func (*Node) Weight

func (n *Node) Weight() float64

func (*Node) Yaml

func (n *Node) Yaml() string

type Operator

type Operator string

type Point

type Point struct {
	X, Y float64
}

func Add

func Add(v, x Point) Point

type Prop

type Prop struct {
	Key   string
	Value interface{}
}

type Props

type Props map[string]interface{}

func (*Props) GetArray

func (p *Props) GetArray(key string) ([]Props, bool)

GetArray tries to return the property located at key as an array of props. It returns (value, true) if an object exists at key and is an array of props.

func (*Props) GetBool

func (p *Props) GetBool(key string) (bool, bool)

GetBool tries to return the property located at key as a boolean. It returns (value, true) if an object exists at key and is a boolean.

func (*Props) GetConstraint

func (p *Props) GetConstraint(key string) (Constraint, bool)

GetConstraint tries to return the property located at key as a constraint. It returns (value, true) if an object exists at key and is a constraint.

func (*Props) GetNumber

func (p *Props) GetNumber(key string) (float64, bool)

GetNumber tries to return the property located at key as a number. It returns (value, true) if an object exists at key and is a number.

func (Props) GetProp

func (p Props) GetProp(path string) (interface{}, error)

GetProp takes a path and returns the value at that path within the Props object. If no value is present nil is returned.

func (*Props) GetProps

func (p *Props) GetProps(key string) (Props, bool)

GetProps tries to return the property located at key as a Props object. It returns (value, true) if an object exists at key and is a Props object.

func (*Props) GetString

func (p *Props) GetString(key string) (string, bool)

GetString tries to return the property located at key as a string. It returns (value, true) if an object exists at key and is a string.

func (*Props) Json

func (p *Props) Json() string

Json() marshals a property set to a JSON string

type Software

type Software struct {
	Props        Props `json:"props"`
	Requirements Props `json:"target"`
}

type SortedProps

type SortedProps []Prop

func (SortedProps) Len

func (x SortedProps) Len() int

func (SortedProps) Less

func (x SortedProps) Less(i, j int) bool

func (SortedProps) Swap

func (x SortedProps) Swap(i, j int)

type Vec2

type Vec2 struct {
	X, Y   float64
	DX, DY float64
	CX, CY float64
}

Directories

Path Synopsis
hw

Jump to

Keyboard shortcuts

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