Difference between revisions of "Variable"

From Developer Documents
Jump to navigation Jump to search
Line 63: Line 63:
 
** http://www.acme.org/Projects/MyProject/MyModel/ExperimentConfiguration/RunName/DiagramN/PI_X#PI_MASS_FLOW#DATATYPE
 
** http://www.acme.org/Projects/MyProject/MyModel/ExperimentConfiguration/RunName/DiagramN/PI_X#PI_MASS_FLOW#DATATYPE
  
A common way of identifying a variable is by supplying a '''base variable''' and a '''Relative Variable Identifier (RVI)'''. RVI
+
A common way of identifying a variable is by supplying a '''base variable''' and a '''Relative Variable Identifier (RVI)'''.
  
* Represents the path from '''base variable''' into another variable
+
* RVI represents the path from '''base variable''' into another variable
 
* In textual RVI notation (Variable.browse())
 
* In textual RVI notation (Variable.browse())
 
** '''.''' represents a getParent() query
 
** '''.''' represents a getParent() query

Revision as of 04:58, 30 March 2012

Intro

The Variable interface provides an uniform access model to data in Simantics. It includes

  • Tree-structured address space for accessing model structure and properties
  • Uniform access to model configuration and state

Key use cases include

Main functional requirements include representation of

  • Structural models with procedural features (see Structural)
  • Runtime data of solvers (see Experiments)
  • Historical data from experiments
  • Ontological data

Solution

Variable is a tree-structured view into the Simantics data model. Each variable is either a child or a property and can further contain own children and properties. The difference between a child and a property is that a property contains a value.

The variable space browsing methods are used to obtain

  • all children
  • children by name
  • all properties
  • properties by name
  • variable by path
  • parent variable

Other services are

  • accessing (get/set) the value of a property variable
  • querying adapter interfaces

A set of built-in properties is required for all variables. These properties have also dedicated interface methods.

  • URI, which is an unique string identifier and locator of the variable in the tree structure
  • Parent, which is the tree parent of the variable
  • HasName, which is a local identifier for the variable within its parent. Names are also used to create URIs.
  • HasLabel, which is a short textual representation of the variable
  • hasStandardResource, which returns the context resource in a standard graph-based child variable
  • Represents, which is a resource representing the variable TODO
  • Type, which returns a single type resource classifying the variable
  • Role, which tells whether the variable is a child or a property (TODO: could be deprecated)
  • DATATYPE, which returns the data type of a property variable. (TODO: should be HasDatatype)

Other properties and the structure of the variable space is configured in the semantic graph or contributed by custom variable implementations.

Variables can be located using an URI, which

A common way of identifying a variable is by supplying a base variable and a Relative Variable Identifier (RVI).

  • RVI represents the path from base variable into another variable
  • In textual RVI notation (Variable.browse())
    • . represents a getParent() query
    • /xx represents a getChild(unescaped(xx)) query
    • #yy represents a getProperty(unescaped(yy)) query
  • A literal RVI (Variable.getRVI(), RVI.resolve())
    • Does not need to depend on the names visible in the URI
    • Is based on e.g. resource ids

A model variable represents the root of a Simantics model

  • Model variables correspond directly to instances of SIMU.Model in the database
    • Variable and resource URIs are the same
  • For all variables under a model, the model variable can be obtained using Variables.getModel()

A context variable under a model provides a view into a state of the model

  • A RVI obtained from e.g. model configuration can be used to access similarly identified data from different model states
    • E.g. /DiagramX/ComponentY#PropertyZ can have different values in different contexts

The following general rules about variables apply:

  • Variable.getProperty returns all the variables returned from Variable.browseProperties
  • Variable.getProperty can return variables not returned by Variable.browseProperties
    • E.g. procedural variables

Procedural children and variables are used with large data sets. E.g. query-based views can be exposed. Procedural properties also enable efficient slicing of arrays e.g. URI#Array_Property/0-99

A model typically contains a number of contexts which are browsed using the Variable interface. Typical contexts are//

  • The base context, which can be used to browse the structure and configuration values of the model
  • Configuration value contexts with e.g. set point values for some variables
  • Experiment contexts with structure and values retrieved from simulator using Databoard Accessor interface

Generic tools such as Model Browser, Selection View, Diagram, Chart, Spreadsheet, OperationUI use the the path identifiers to refer to their data. Once a desired Variable has been obtained its value can be accessed using direct database requests or Databoard Accessor.


Path identifiers can also be serialized into graph representation, which is name-independent and survives export/import. In e.g. structural this is an ordered set of path separators and configuration resources.

Refactoring

  • add Collection<Variable> browseProperties(ReadGraph graph, String classification) throws DatabaseException;
  • add standard property classifications, which returns a set of strings
  • deprecate browseChildren, browseProperties => add get

Connection modelling


public interface Connection {

  Collection<Variable> getConnectionPoints(ReadGraph graph) throws DatabaseException;

}

It is assumed that instances of org.simantics.structural2.variables.Connection have proper identities (equals/hashCode) based on flattened connections.

The value of connection point properties can be null. This means that the connection point is not connected.

String editing operations

  • HasDisplayValue is a String-valued property, which is a formatted and unit-converted representation of the property value.
  • expression is a String-valued property, which is an SCL-formula used to compute the value of the property. If the property can be computed using an expression, this property is always available and returns null if an expression has not been defined.
  • validator is a org.simantics.utils.strings.StringInputValidator-valued property. The validator is used for checking values to be written into a property.

public interface StringInputProblem {

  enum Severity {
    Error, Warning
  }

  String getDescription();
  int getBegin();
  int getEnd();
  Severity getSeverity();

}

public interface StringInputValidator {

  Collection<StringInputProblem> validate(String input);

}

  • valid is a Boolean-valued property, which indicates whether the property contains a valid value.

Property properties

  • required is a Boolean-valued property, which indicates that the property should contain a valid value
  • default is a Boolean-valued property, which indicates that the property value is a default value
  • readOnly is a Boolean-valued property, which indicates that the property value can not be written

Assumptions

  • §1 Everything after '#' has a value
  • §2 For all realization resources a variable can be obtained by graph.adapt(r, Variable.class)
  • §3 For all realization resources the variable URI equals graph.getURI(r)
  • §4 A variable can be part of at most one Context
  • §5 A variable can be part of at most one Model
  • $6 All values can be accessed using either Variable.getValue or Variable.getInterface(Accessor.class)
  • $7 All properties retrieved using Variable.browseProperties shall be available using Variable.getProperty

Standard modelling in Layer0

Realizations.png

Child modelling

Standard child modelling assumes a context resource res.

  • childResource : where (res, L0.ConsistsOf, childResource)
  • childVariable = graph.adaptContextual(childResource, this, Variable.class, Variable.class)

Property modelling

Standard property modelling assumes a context resource res.

  • (predicate, object) : where (res, predicate, object) and (predicate <R L0.HasProperty)
  • childProperty = graph.adaptContextual(object, ModelledVariablePropertyDescriptor(this, predicate), Variable.class)

For property variables there are two context resources available, the associated value and the predicate. Properties are found from the value context first and then from the predicate context.

Layer0 properties

For all variables

  • NAME: String

The name of the resource. The URI uses an escaped version of this name. For graph-based variables this is L0.HasName

  • LABEL: String

The standard textual representation for the variable. For graph-based variables this is L0.HasLabel

  • TYPE: Resource

A single type related to the variable.

  • URI: String

The variable URI, see Implementations

  • SERIALIZED: String

An immutable string identified for this part

  • PARENT: Variable

The parent variable

  • ROLE: Role

Is Role.Property if URI contains '#', else is Role.Child. If role is Role.Property, then the variable has a value.

  • CONTEXT : Variable

The context variable of this variable. The URI of the context variable is a prefix of the URI of this variable.

  • CHILD_COUNT: Integer

The amount of children.

  • PROPERTY_COUNT: Integer

The amount of properties.

For variables, where Role is Role.Child

  • REPRESENTS: Resource

The configuration resource related to this variable.

For variables, where Role is Role.Property

  • REPRESENTS: Resource

The literal resource related to this variable.

  • EXPRESSION: String

The expression for determining the value of the property. Null if there is no expression.

  • PREDICATE: Variable

The variable representing the predicate.

  • DATATYPE: Datatype

The data type of the property.

  • INPUT_VALIDATOR: String -> String

A function which performs validation for potential inputs to setValue.

Modelling

  • L0.ConsistsOf determines modelled variable children
  • L0.HasProperty determines the predicates used for producing variable properties
  • L0.Entity defined the adapter org.simantics.db.layer0.variable.StandardGraphChildVariableAdapter
  • L0.Value defines the adapter org.simantics.db.layer0.variable.StandardModelledPropertyVariable
  • L0X.ResourcePropertyRelation defines the adapter org.simantics.db.layer0.variable.ResourcePropertyVariableAdapter

Implementation

  • org.simantics.db.layer0.variable.StandardGraphChildVariable implements a child variable based on a parent variable and on a context resource.
  • org.simantics.db.layer0.variable.StandardGraphPropertyVariable implements a child variable based on a parent variable and on a (subject, predicate <R L0.HasProperty) resource pair.
  • org.simantics.db.layer0.variable.VariableSpaceManipulator: for modifying the variable space
  • org.simantics.db.layer0.variable.InputValidator: for validating user input
  • org.simantics.db.layer0.variable.Formatter: for representing values
  • org.simantics.databoard.units.IUnitConverter: for representing values according to user needs

Frequent cases

1. Given variable v, obtain model

  Procedure: call Variables.getModel(graph, v)

2. Given variable v, obtain realization

  Procedure: call Variables.getRealization(graph, v)

3. Given Variable URI, obtain Variable

  Procedure: call Variables.getVariable(graph, uri)

4. Given Variable URI, obtain textual RVI

  Procedure: call Variables.getRVI(graph, v)

5. Given a configuration resource r and context variable obtain variable

  Procedure: call Variable.browse(graph, r)

6. Given two variables v1 and v2, obtain RVI of second based on first

  call Variables.getRVI(graph, v1, v2)

7. Given Realization URI and RVI, obtain Variable

  call Variables.getVariable(graph, uri, rvi)

8. Obtain string representation for value of Variable v

  -Obtain value val (Object) by v.getValue()
  -Obtain converter c by v.getInterface(IUnitConverter.class)
  -Obtain converted value cval (Object) by c.convert(val)
  -Obtain formatter f by v.getInterface(Formatter.class)
  -Obtain String representation by f.format(cval)

Varible space modelling

Cases

Datatypes

Record

  • All named fields are '/name'
  • Tuples are named after position e.g. '/11'

Union

  • Union does not show in URI

Array

  • Elements are named after position e.g. '/11'

Map

  • Items are named after key

Take for example http://www.asd.org/Project/AprosModel1/BaseRealization/a/TA_1#TA11_POINT_ELEV

Property sets

Two alternatives

Set is also a value

http://www.asd.org/Project/BalasModel1/BaseRealization/Valve1/FSET#Set1/Flowrate

Set1 is now a Databoard record.

Only items are values

http://www.asd.org/Project/BalasModel1/BaseRealization/Valve1/FSET/Set1#Flowrate


Modelling of related concepts

Units

Formatting

Standard variables

Cases

Inferred configuration values from structural

Expressions

Variable syntax in SCL

  • Implement variable interface methods as normal functions
    • Example: browse entrypoint "./Out#sdf"
  • Use . and #-for browsing
    • How to browse parent? Explicit function
    • Example: (parent entrypoint).Out#sdf
    • Special operator for parents (binds stronger than . or #):
    • Example: !entrypoint.Out#sdf
  • Resolve entrypoints in the context
    • Example: Out#sdf
    • Local variable definitions may shadow context


Experiment modelling

Each running or stored historical experiment in Simantics is modelled as a realization under the Model. Realizations have URIs as defined by ReadGraph.getURI. Some realizations are entirely backed by the semantic graph and some are backed by an Accessor provided by a running simulator or a time series stored as a file in the semantic graph. The structure of the Variable tree under the realization is generated from the semantic model configuration and can be implemented in different ways ranging from persistent graph to lazily produced transient virtual graph. The realizations are browsed using Variable interface methods and variable values can be obtained using Variable methods or by obtaining Databoard Accessor using Variable.getInterface. Each variable serves an instantaneous value and each variable can also contain a property which serves a time series associated to the variable such as in historical data or sampled history of a running experiment.

Validation scenario

The standard model is validated in a headless structural-based setup with

  • Structural configuration with joined diagrams and reusable component types
  • Procedural children provided by simulator
  • Accessor-backed simulator