Simulation data#
Simulation data files are used to represent sequences of values:
they are the outputs of simulation jobs;
they can be used in test harnesses, in data source and oracle blocks, to be used respectively as inputs and expected values.
This library allows to read and edit simulation data files. Look for simulation data in Scade One documentation.
Covered features#
Support of
nonevalues, meaning that the value is not defined at a given cycle:Stimuli operator: a value must be defined at first cycle, for next steps the
nonetype means that a previous value is held.Simulator trace: a
nonevalue means that the variable clock is false.
Support of all Swan types, imported types (stored as a byte array) and combinations of them (native support of Variants & Groups).
Data support: structure, table (when the table size is a static constant), enum, string.
Limitations: partial data is not supported. All values of a complex type must be given.
The variables are organized as a tree of <scope>/<scope>/…/<variable>, each scope and variable has an optional Swan kind: sensors, inputs, outputs, probes, assume, guarantee and so on.
Possibility to specify a repetition of a signal or part of it.
Possibility to open an existing file for modification: elements, types and values.
Design principles#
A file of binary format does not allow a value conversion to or from string.
The values are stored as their binary representation in memory: no structured representation of composite values.
The values sequences are compressed using the zlib data-compression library.
The file size has no limit (more than 4 GB): use of 64 bits positions and C APIs for seek in file.
The entire file content is not loaded in memory when opening: the data is read in file only on demand.
The file content is not entirely rewritten on disk when closing: incremental read and write operations.
Performance#
Appending values to an element: no need to read all the values before appending and use of a write cache.
Updating element: no move of significant data in file.
Example using API simulation data#
import ansys.scadeone.core.svc.simdata as sd
f = sd.create_file("mySimDataFile.sd") # creates a new simulation data file
t_struct1 = sd.create_struct_type([("f1", sd.Bool), ("f2", sd.Int32)], "p1::tStruct1") # creates a new structure type
e_struct1 = f.add_element("eStruct1", t_struct1) # adds an element to the file
clock1 = False
for i in range(10): # number of cycles
clock1 = not clock1
e_struct1.append_value([clock1, i + 14]) # adds values to the element
f.close() # closes the file
Simulation data file preview command line#
The pyscadeone Command line interface is used, in combination with the simdata and -show arguments, to preview the content of a data file with .SD extension in a text editor, without opening the Scade One tool or Signal Editor.
# View content of a .SD file as a text
pyscadeone simdata --show some_file.sd > some_file.txt
notepad some_file.txt # opens the file in notepad, or vi editor and so on
High-level API#
- class ansys.scadeone.core.svc.simdata.csd.Element(file: FileBase, elem_id: int, parent: ElementBase | None, name: str, sd_type: Type | None, kind: SdeKind)#
Bases:
ElementBaseClass for simdata elements
- add_child_element(name: str, sd_type: Type | None = None, kind: SdeKind = SdeKind.NONE) ElementBase#
Add a child to element
- Parameters:
- name
str child element name
- sd_type
Type,optional child element type
- kind
ElementKind,optional child element kind
- name
- Returns:
ElementBaseCreated child element
- remove_child_element(element: Element) None#
Remove a child from element
- Parameters:
- element
Element element to remove
- element
- Raises:
ScadeOneExceptionchild could not be removed
- append_value(py_value: Any) None#
Add a value to an element or appends to the last sequence of values if any. This method shall NOT be used to add a single value after a multiple cycles sequence as it would also be repeated alongside the previous sequence. Prefer using append_values([py_value]) instead in such case.
- Parameters:
- py_value
Any value that has a type corresponding to the element
- py_value
- Raises:
ScadeOneExceptionvalue is invalid or could not be added
- append_nones(count: int) None#
Add a sequence of none values to an element (undefined cycle values)
- Parameters:
- count
int number of Nones to add
- count
- Raises:
ScadeOneExceptioncannot create or append nones sequence
- append_values(py_values: List[Any], repeat_factor: int | None = 1) None#
Create a new sequence of one or multiple values. Do not use repeat factor for array and structure types. Do not use this for structure or array types that already have any value, use append_value() instead in such case.
- Parameters:
- py_values
List[Any] list of value(s) to add
- repeat_factor
Optional[int],optional number of times to add, by default 1 (no repeat), do not use with non scalar values
- py_values
- Raises:
ScadeOneExceptionInvalid repeat, none contained in values, invalid values, cannot create or append values sequence, used repeat factor for array or structure types
- class ansys.scadeone.core.svc.simdata.csd.File(file_id: int)#
Bases:
FileBaseSimdata files class
- add_element(name: str, sd_type: Type | None = None, kind: SdeKind = SdeKind.NONE) ElementBase#
Create and add an element to file
- Parameters:
- name
str element name
- sd_type
Type,optional type of element
- kind
ElementKind,optional kind of element
- name
- Returns:
ElementBaseThe new element that was added to file
- ansys.scadeone.core.svc.simdata.csd.open_file(file_path: str) FileBase#
Open a simdata file in read-only mode
- Parameters:
- file_path
str path of the file
- file_path
- Returns:
FileBaseThe opened file
- Raises:
ScadeOneExceptionfile could not be opened
- ansys.scadeone.core.svc.simdata.csd.create_file(file_path: str) FileBase#
Create a simdata file
- Parameters:
- file_path
str path of the file
- file_path
- Returns:
FileBaseThe created file
- Raises:
ScadeOneExceptionfile could not be created
- ansys.scadeone.core.svc.simdata.csd.edit_file(file_path: str) FileBase#
Open a simdata file in edit mode
- Parameters:
- file_path
str path of the file
- file_path
- Returns:
FileBaseThe opened file
- Raises:
ScadeOneExceptionThe file could not be opened
- ansys.scadeone.core.svc.simdata.csd.create_struct_type(fields: List[Tuple], name: str = '') StructType#
Create a structure type
- Parameters:
- fields
List[Tuple] all fields of the structure
- name
str,optional structure name
- fields
- Returns:
StructTypeThe created structure type
- Raises:
ScadeOneExceptionstructure type could not be created, arguments are invalid, or field names duplicate
- ansys.scadeone.core.svc.simdata.csd.create_array_type(base_type: Type, dims: List[int], name: str = '') ArrayType#
Create a multi dimensional array type
- ansys.scadeone.core.svc.simdata.csd.create_enum_type(values: List[str], name: str = '') EnumType#
Create an enumeration type
- ansys.scadeone.core.svc.simdata.csd.create_variant_type(constructors: List[Tuple], name: str = '') VariantType#
Create a variant type
- Parameters:
- constructors
List[Tuple] constructors of the variant type
- name
str,optional name of variant type
- constructors
- Returns:
VariantTypeCreated variant type
- Raises:
ScadeOneExceptionvariant type could not be created, invalid arguments or duplicate constructor names
- ansys.scadeone.core.svc.simdata.csd.create_imported_type(mem_size: int, name: str = '') ImportedType#
Create an imported type
Type definitions#
Predefined swan types that shall be used for creation of simple elements or user types definitions
Id |
Type |
|---|---|
0 |
Char |
3 |
Bool |
4 |
Int8 |
5 |
Int16 |
6 |
Int32 |
7 |
Int64 |
8 |
UInt8 |
9 |
UInt32 |
10 |
UInt32 |
11 |
UInt64 |
12 |
Float32 |
13 |
Float64 |
Using a predefined type (float 32 here) for new element and custom user type
import ansys.scadeone.core.svc.simdata as sd
my_file = sd.create_file("mySimDataFile.sd")
my_element1 = my_file.add_element("myElement", sd.Float32)
my_array_type = sd.create_array_type(sd.Float32, [3, 4], "my2DArrayType")
my_element2 = my_file.add_element("my2DArrayElement", my_array_type)
- class ansys.scadeone.core.svc.simdata.defs.ArrayType(type_id: int, base_type: Type, dims: List[int], name: str = '')#
Bases:
TypeMultidimensional array type
- class ansys.scadeone.core.svc.simdata.defs.EnumType(type_id: int, base_type: PredefinedType, values: List[EnumTypeValue], name: str = '')#
Bases:
TypeEnumeration type defined with enumeration values
- class ansys.scadeone.core.svc.simdata.defs.EnumTypeValue(name: str, int_value: int)#
Bases:
objectEnumeration type value
- class ansys.scadeone.core.svc.simdata.defs.EnumValue(name: str)#
Bases:
ValueValues for enumeration types
- class ansys.scadeone.core.svc.simdata.defs.ImportedType(type_id: int, mem_size: int, vsize: bool = False, pfn_vsize_get_bytes_size: ~ctypes.CFUNCTYPE.<locals>.CFunctionType | None = None, pfn_vsize_to_bytes: ~ctypes.CFUNCTYPE.<locals>.CFunctionType | None = None, name: str = '')#
Bases:
TypeImported Types (stored as byte arrays)
- class ansys.scadeone.core.svc.simdata.defs.ImportedValue(bytes_data)#
Bases:
ValueValues for imported types
- class ansys.scadeone.core.svc.simdata.defs.ListValue(values: List[Value])#
Bases:
ValueValues for list types
- class ansys.scadeone.core.svc.simdata.defs.PredefinedBoolValue(value: c_ubyte)#
Bases:
PredefinedValueValues for predefined type boolean
- class ansys.scadeone.core.svc.simdata.defs.PredefinedCharValue(value: c_ubyte)#
Bases:
PredefinedValueValues for predefined type char
- class ansys.scadeone.core.svc.simdata.defs.PredefinedFloat32Value(value: c_float)#
Bases:
PredefinedValueValues for predefined type float 32
- class ansys.scadeone.core.svc.simdata.defs.PredefinedFloat64Value(value: c_double)#
Bases:
PredefinedValueValues for predefined type float 64
- class ansys.scadeone.core.svc.simdata.defs.PredefinedInt16Value(value: c_short)#
Bases:
PredefinedValueValues for predefined type int 16
- class ansys.scadeone.core.svc.simdata.defs.PredefinedInt32Value(value: c_int)#
Bases:
PredefinedValueValues for predefined type int 32
- class ansys.scadeone.core.svc.simdata.defs.PredefinedInt64Value(value: c_long)#
Bases:
PredefinedValueValues for predefined type int 64
- class ansys.scadeone.core.svc.simdata.defs.PredefinedInt8Value(value: c_byte)#
Bases:
PredefinedValueValues for predefined type int 8
- class ansys.scadeone.core.svc.simdata.defs.PredefinedType(type_id: int)#
Bases:
TypePredefined Swan types are not stored in file. They have hard-coded identifiers that can be used in user types definitions.
- class ansys.scadeone.core.svc.simdata.defs.PredefinedUInt16Value(value: c_ushort)#
Bases:
PredefinedValueValues for predefined type unsigned int 16
- class ansys.scadeone.core.svc.simdata.defs.PredefinedUInt32Value(value: c_uint)#
Bases:
PredefinedValueValues for predefined type unsigned int 32
- class ansys.scadeone.core.svc.simdata.defs.PredefinedUInt64Value(value: c_ulong)#
Bases:
PredefinedValueValues for predefined type unsigned int 64
- class ansys.scadeone.core.svc.simdata.defs.PredefinedUInt8Value(value: c_ubyte)#
Bases:
PredefinedValueValues for predefined type unsigned int 8
- class ansys.scadeone.core.svc.simdata.defs.PredefinedValue#
Bases:
ValueValues for predefined Swan Types
- class ansys.scadeone.core.svc.simdata.defs.StructType(type_id: int, fields: List[StructTypeField], name: str = '')#
Bases:
TypeStructure type defined with structure type fields
- class ansys.scadeone.core.svc.simdata.defs.StructTypeField(name: str, offset: int, sd_type: Type)#
Bases:
objectStructure type’s fields
- class ansys.scadeone.core.svc.simdata.defs.Type(type_id: int, name: str = '')#
Bases:
objectRepresents an abstract data type.
- class ansys.scadeone.core.svc.simdata.defs.UntypedVariantConstructorValue#
Bases:
ValueNo value to return for untyped variant constructor
- class ansys.scadeone.core.svc.simdata.defs.Value#
Bases:
objectInterface for all element types values that shall provide a readable string representation
- class ansys.scadeone.core.svc.simdata.defs.VariantType(type_id: int, constructors: List[VariantTypeConstructor], name: str = '')#
Bases:
TypeVariant type defined with variant type constructors