Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • In Jupyter Notebook, run the following command to install a Python package from the <install_root>\plugins\com.nomagic.magicdraw.simulation\pyST.zip file:

    Code Block
    %pip install pyST.zip


Use the following requests to simulate Teamwork Cloud projects on the server:

Table of Contents
maxLevel4

Create client/session and authenticate

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client = SimulationWebClient('http(s)://<server_host>:<server_port>', '<TWC_user_name>', '<TWC_user_password>', False)


This request starts a work session and provides authentication to Teamwork Cloud.

...

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.get_projects()


This request provides the list of Teamwork Cloud projects accessible to you depending on your permissions. Only projects that you can read (the Read Resources permission) are returned.

Code Block
titleRequest and response examples
client.get_projects()


[{'id': '1f9fd988-620b-4b3c-8414-7ab96dc53a48',
  'name': 'SpacecraftMassRollup',
  'description': ''},
 {'id': 'c125b91e-7d31-4015-b659-6fd98059b8c7',
  'name': 'BouncingBall',
  'description': 'This project demonstrates the execution of the BouncingBall, including fmu.'},
 {'id': '485dfc82-7b08-43cd-86b1-953b3725e5b1',
  'name': 'CarBrakingAnalysis',
  'description': 'This project calculates the stopping distance based on car speed and mass.'}]

...

ParameterInRequired or optionalDescriptionOptions
projectpathrequiredThe Teamwork Cloud project name or ID.NA
versionpathoptionalThe Teamwork Cloud project version.NA
branchpathoptionalThe project branch name or ID. If the branch is omitted, the trunk is used instead.NA
elementpathoptionalThe qualified name or server ID of the element to be executed.NA
configpathoptionalThe Simulation Configuration name or server ID.NA
started_frompathoptionalAllows specifying the starting location of the simulation. The value of the started_from parameter is provided in the status endpoint response.NA
commit_results pathoptional

Commits a new project version with the simulation results. Available values are True or False (default).

NA
verificationpathoptional

Returns the selected verification results. Available values are:

    • All - all verification results are returned.
    • None - no verification results are returned.
    • Fail (default) - verification results with the fail status are returned.
NA
datapathoptionalA set of output parameters, which will be obtained after the simulation is complete.NA

timeout

pathoptional

Allows specifying the timeout duration in minutes. If the timeout parameter is not provided, the sim.timeout.min property will be taken from the webappplatform.properties instead.

NA

sync

pathoptional

Initiates a synchronous API call. If the sync is set to 'True', the call will return when it is completed. Available values are True or False (default).

NA
simconfig bodyoptionalThe set of simulation configuration properties along with their corresponding values. The simulation configuration options you specify will take precedence over the initial configuration option from a model.
  • "ALLOW_CONCURRENT_ALLOCATED_ACTIVITIES": true,
  • "AUTOMATIC_PARAMETRIC_RECALCULATION": true,
  • "AUTO_CONVERT_UNITS": true,
  • "AUTO_CREATE_FUML_OBJECT_OF_OUTPUT_PIN": true,
  • "AUTO_START": true,
  • "AUTO_START_ACTIVE_OPTIONS": true,
  • "AUTO_TERMINATE": true,
  • "CLOCK_RATIO": 1,
  • "CLONE_REFERENCES": true,
  • "COMPLETION_EVENTS_AND_TRANSITIONS": true,
  • "CONSTRAINT_FAILURE_AS_BREAKPOINT": true,
  • "DECIMAL_PLACES": 4,
  • "DEFAULT_LANGUAGE": "JavaScript Rhino",
  • "DURATION_SIMULATION_MODE": "MIN", // possible values: MIN, MAX, AVERAGE, RANDOM
  • "ENDTIME": 0,
  • "ENGINES_PRIORITY": "[on] fUML Engine\n[on] Interaction Engine\n[on] SCXML Engine",
  • "INITIALIZE_NUMERICAL_VALUE": false,
  • "INITIALIZE_REFERENCES": true,
  • "NUMBER_OF_RUNS": 0,
  • "NUMBER_OF_STEPS": 0,
  • "PASS_CALLER_CONTEXT": true,
  • "RECORD_TIMESTAMP": false,
  • "REMEMBER_FAILURE_STATUS": true,
  • "RESULT_LOCATION": "Results",
  • "RUN_FORKS_IN_PARALLEL": true,
  • "SOLVE_AFTER_INITIALIZATION": true,
  • "START_TIME": 0,
  • "STATE_ACTIVATION_SEMANTICS": "BEFORE_ENTRY", // possible values: "BEFORE_ENTRY", "AFTER_ENTRY"
  • "STEP_DELAY": 0,
  • "STEP_SIZE": 0,
  • "TERMINATE_BEHAVIOR_ON_EXCEPTION_THROWN": true,
  • "TERMINATE_NESTED_BEHAVIORS": true,
  • "TERMINATE_STREAMING_BEHAVIORS_BY_OUTPUT_PARAMETER_MULTIPLICITY": false,
  • "TIME_UNIT": "MILLISECOND",
  • "TIME_VALUE": "Model-based Clock Test::Clock::time",
  • "TIME_VARIABLE_NAME": "simtime",
  • "TREAT_ALL_CLASSIFIERS_AS_ACTIVE": true,
  • "USE_FUML_DECISION_SEMANTICS": false

...

Panel
borderColorlightgrey
borderWidth1

client.step(<simulation_id>, sync=<True/False>)


This request performs a single time step of the specified simulation. To run the simulation by step, it should be run with the
 AUTO_START option of the simconfig parameter set to false.


The following table describes the parameters used in the request:

...

Panel
borderColorlightgrey
borderWidth1

client.start(<simulation_id>)


This request starts the execution of the specified simulation. 
If the initialization phase is still in progress, the start  endpoint is memorized and sent when the initialization phase is completed.

The following table describes the parameters used in the request:

...

ParameterInRequired or optionalDescriptionOptions
projectpathrequiredThe Teamwork Cloud project name or ID.NA
versionpathoptionalThe Teamwork Cloud project version.NA
branchpathoptionalThe project branch name or ID. If the branch is omitted, the trunk is used instead.NA
elementpathoptionalThe qualified name or server ID of the element to be executed.NA
configpathoptionalThe Simulation Configuration name or server ID.NA
commit_results pathoptional

A new project version is committed with the simulation results. Available values are True or False (default).

NA
verificationpathoptional

Returns the selected verification results. Available values are:

    • All - all verification results are returned.
    • None - no verification results are returned.
    • Fail - verification results with the fail status are returned including the main status and the status of requirements and constraints.

If the verification value is not specified, only the verification results with the fail status are returned when the get_results endpoint is called.

NA
datapathoptionalA set of output parameters, which will be obtained after the simulation is complete.NA
simconfig bodyoptionalThe set of simulation configuration properties along with their corresponding values. The simulation configuration options you specify will take precedence over the initial configuration option from a model.
  • "ALLOW_CONCURRENT_ALLOCATED_ACTIVITIES": true,
  • "ANIMATION_SPEED": 95,
  • "AUTOMATIC_PARAMETRIC_RECALCULATION": true,
  • "AUTO_CONVERT_UNITS": true,
  • "AUTO_CREATE_FUML_OBJECT_OF_OUTPUT_PIN": true,
  • "AUTO_START": true,
  • "AUTO_START_ACTIVE_OPTIONS": true,
  • "AUTO_TERMINATE": true,
  • "CAPTURE_TIMESTAMP": false,
  • "CLOCK_RATIO": 1,
  • "CLONE_REFERENCES": true,
  • "COMPLETION_EVENTS_AND_TRANSITIONS": true,
  • "CONSTRAINT_FAILURE_AS_BREAKPOINT": true,
  • "DECIMAL_PLACES": 4,
  • "DEFAULT_LANGUAGE": "JavaScript Rhino",
  • "DURATION_SIMULATION_MODE": "MIN", // possible values: MIN, MAX, AVERAGE, RANDOM
  • "ENDTIME": 0,
  • "ENGINES_PRIORITY": "[on] fUML Engine\n[on] Interaction Engine\n[on] SCXML Engine",
  • "INITIALIZE_NUMERICAL_VALUE": false,
  • "INITIALIZE_REFERENCES": true,
  • "NUMBER_OF_RUNS": 0,
  • "NUMBER_OF_STEPS": 0,
  • "PASS_CALLER_CONTEXT": true,
  • "RECORD_TIMESTAMP": false,
  • "REMEMBER_FAILURE_STATUS": true,
  • "RESULT_LOCATION": "Results",
  • "RUN_FORKS_IN_PARALLEL": true,
  • "SHOW_ANNOTATIONS": false,
  • "SOLVE_AFTER_INITIALIZATION": true,
  • "START_TIME": 0,
  • "STATE_ACTIVATION_SEMANTICS": "BEFORE_ENTRY", // possible values: "BEFORE_ENTRY", "AFTER_ENTRY"
  • "STEP_DELAY": 0,
  • "STEP_SIZE": 0,
  • "TERMINATE_BEHAVIOR_ON_EXCEPTION_THROWN": true,
  • "TERMINATE_NESTED_BEHAVIORS": true,
  • "TERMINATE_STREAMING_BEHAVIORS_BY_OUTPUT_PARAMETER_MULTIPLICITY": false,
  • "TIME_UNIT": "MILLISECOND",
  • "TIME_VALUE": "Model-based Clock Test::Clock::time",
  • "TIME_VARIABLE_NAME": "simtime",
  • "TREAT_ALL_CLASSIFIERS_AS_ACTIVE": true,
  • "USE_FUML_DECISION_SEMANTICS": false

...


This request gets the status of a specific simulation. If the model has a UI mockup, Time Series Chart, Timeline Chart, or HTML Table, you can use the URL provided in the 'ui' or indexUI' key to open the specified UI.

...

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.get_variables(<simulation_id>, variables=json.dumps(<parameters>))


This request returns a list of simulation variables during simulation.

The following table describes the parameters used in the request:

ParameterInRequired or optionalDescription
simulation_idpathoptional

The ID of the running simulation.

Note

If the simulation_id is not specified, the pyST client will use the simulation_id of the last simulation run.


variablespathoptionalThe set of simulation variables that should be obtained. If no variables are specified, the values of all simulation variables are returned.

Set simulation variables

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.set_variables(<simulation_id>, variables=json.dumps(<parameters>), context=<context ID>, property_path=<property path>)

This request provides a list of simulation variables with values. 

The following table describes the parameters used in the request:

ParameterInRequired or optionalDescription
simulation_idpathoptional

The ID of the running simulation.

Note

If the simulation_id is not specified, the pyST client will use the simulation_id of the last simulation run.


variablespathrequiredThe set of simulation variables with values that should be used during the current simulation.
contextpathoptionalThe context ID.
property_pathpathoptionalThe property path of the context specified using property names or IDs.

...


This request returns the results of the specified simulation. If the OutputParameters tag of the executed Simulation Configuration is specified, the results are provided according to the OutputParameters tag value. If a Time Series or Timeline chart is specified for the Simulation Configuration, the chart data is returned in the JSON format.

The figure below demonstrates how to specify input and output parameters.


Specifying input and output parameters.

...

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.terminate(<simulation_id>, sync=<True/False>)


This request terminates the specified simulation.

...

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.get_configurations(<project>, version=<version>, branch=<branch>, element=<element>, filter=<ui>)


This request retrieves the names and descriptions of the Simulation Configurations available for the given project.

...

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.get_descriptor(<project>, version=<version>, branch=<branch>, config=<config>)


This REST API request retrieves Simulation Configuration data (description, execution target, time step, input and output parameters) from the specified project. The set of input and output parameters is specified using the Input Parameters and Output Parameters properties of a Simulation Configuration. The figure below demonstrates how to specify input and output parameters.


Specifying input and output parameters.

...