Skip to main content

Query Language

The Sedaro query language (SedaroQL) is used to specify inputs and outputs of statemanagers and external cosimulation blocks.

Queries

Each SedaroQL query consists of a single top-level expression, usually a tuple.

Query Expressions

A query expression is an element of a query that can be evaluated to produce a value.

SyntaxMeaning
agent!(agentId)A reference to a specific agent. agentId is an expression that is evaluated statically, but can be loaded from the model.
block!(blockId)A reference to a specific block on the agent the query is being run on. blockId is an expression that is evaluated statically, but can be loaded from the model.
root!A reference to the root of the agent the query is being run on, even if the query is being run for a block.
()A tuple with no elements.
(a,)A tuple with one element. The trailing comma is not optional.
(a, b) or (a, b,)A tuple with two or more elements. The trailing comma is optional.
expr.BlockTypeAn access of all blocks with type BlockType on the agent specified by expr. The result will be a list.
expr.fieldAn access to a relation or compound field on the block(s) specified by expr. For multi-valued relations, the result will be a list.
expr.block!("base50blockId")A reference to a specific block on the agent specified by expr. The blockId is evaluated statically, but can be loaded from the model.
ephem!("moon")The current orbital ephemeri of a specific celestial body.
expr as QuantityKind.unitConverts expr to a different unit or reference frame.
target!(expr)A dynamic reference to another agent specified by expr.
fieldAn access to a relation or compound field on the block the query is being run on.
expr.(spread1, spread2)A spread expression. The left side is evaluated, and a tuple is constructed where the values are the elements of the right side applied to the left side.
match sel { pattern => expr }A dynamic match expression. The selector (sel) is evaluated on every frame and then compared to the patterns. If it is equal to one of the patterns, the result will be the dynamically-evaluated expression specified by that pattern.
static match sel { pattern => expr }A static match expression. The selector (sel) is evaluated once before the simulation starts and then compared to the patterns. If it is equal to one of the patterns, the result will be the dynamically-evaluated expression specified by that pattern.
type match sel { BlockType => spread }A type match expression. The selector (sel) is evaluated on every frame and then compared to the block types. The result will be the dynamically-evaluated spread applied to the selector for the first pair for which the block type is a supertype of the selector's type.
prev!(expr)The previous value of its child expression.
collection[index]An index into a list, tuple or map.
"string"A string literal.
true or falseA boolean literal.
seed!(agent, all, block, engine, path, sim, sm)A pseudo-random integer, seeded with the specified arguments. For instance, seed!(agent) will seed the pseudo-random number generator with the agent ID the query is being run for, while seed!(engine, sim) will seed it with the engine name and the simulation's global seed.

Aggregates

Tuples and lists are referred to as aggregates. When they appear as the left side of an access or spread, the result will also be an aggregate in which the access or spread is applied to each element of the aggregate individually. For instance, the query (ReactionWheel, Thruster).torque is equivalent to (ReactionWheel.torque, Thruster.torque)

Spreads

Each piece of the right side of a spread expression is referred to as a spread element. They resemble expressions, and most spread elements can be thought of as being like an expression missing its left-hand side, which is instead supplied as the left side of the parent spread expression. Spreads are convenient when accessing multiple fields of a single agent or block. For example, when getting information about battery packs, the query BatteryPack.(battery.(type, current), esr) will be equivalent to the longer query ((BatteryPack.battery.voltage, BatteryPack.battery.current), BatteryPack.esr).

SyntaxMeaning
fieldA field or relation access applied directly to the spread expression's left hand side.
BlockTypeAn access to all blocks of a type, applied directly to the spread's left hand side.
spread as QuantityKind.unitA conversion of the result of spread
block!("base50blockId")An access of a block on the spread's left hand side. The blockId is evaluated statically, but can be loaded from the model.
spread.block!("base50blockId")An access of a block on the result of spread. The blockId is evaluated statically, but can be loaded from the model.
spread.fieldA field or relation access applied to the result of spread. This allows accesses to nested structures.
ephem!("moon")The orbital ephemeris of a celestial body, ignoring the spread's left hand side.
prev!(spread)The previous value of spread as applied to the spread's left hand side.
static match sel { pattern => spread}A static match. The selector is applied to the spread's left hand side, compared to the patterns, and the spread element of the matching pattern is applied to the spread's left hand side.
spread.(spread1, spread2)An inner spread. Results in a tuple in which spread1 and spread2 are applied to the result of spread applied to the parent spread's left hand side
(a, b,)A tuple. Results in a tuple in which each element is applied to the spread's left hand side.

Patterns and Match Pairs

The elements of a match expression are known as match pairs. Each match pair consists of a pattern and an expression, separated by the symbol =>. The pattern specifies which value(s) of the selector the pair corresponds to, while the expression specifies the result of the pair.

Currently the only supported patterns are string literals and the catch-all _ pattern. String literal patterns match when the selector is identical to the pattern, while the catch-all pattern matches any value (provided that it is not matched by an earlier pattern).