Versions Compared

Key

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

...

Note
titlePrerequisites

Before starting the simulation, make sure you have prepared your projects for server-side simulation.


Setting up Jupyter Notebook


To set up Jupyter Notebook

...

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)

...

ParameterInRequired or optionalDescription
server_hostpathrequiredThe Teamwork Cloud server host name.
server_portpathrequiredThe Teamwork Cloud server port.
TWC_user_namepathoptional

The Teamwork Cloud user name. If you do not specify the user name in the request, an input field will be provided to specify it later.

TWC_user_passwordpathoptionalThe Teamwork Cloud password. If you do not specify the password in the request, an input field will be provided to specify it later.


Get the list of Teamwork Cloud projects

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.get_projects()

...

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.'}]


Run simulation

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.run(<project>, version=<version>, branch=<branch>, element_id=<element_id>, config=<config>, commit_results=<True/False>, verification=<All/None/Fail>, data=json.dumps(<param> ), auto_start=<True/False> )

...

Code Block
titleRequest and response examples
 # SpaceCraftMassRollup sample

parameters = {
    "inputs":
   {
       "telecom.antenna.me":10,
        "telecom.amplifier.me":20
   },
 "outputs": 
    [ 
        "me",
        "propulsion.me",
        "propulsion.tank.me",
        "propulsion.thruster.me",
        "telecom.me",
        "telecom.antenna.me",
        "telecom.amplifier.me"
    ] 
}
        
client.run('SpacecraftMassRollup_SimWeb', config='spacecraft mass analysis', commit_results=False, data=json.dumps(parameters))

Perform a time step

Panel
borderColorlightgrey
borderWidth1

client.step(<simulation_id>)

...

ParameterInRequired or optionalDescription
simulation_idpathrequiredThe ID of a specific simulation.


Start simulation

Panel
borderColorlightgrey
borderWidth1

client.start(<simulation_id>)

...

ParameterInRequired or optionalDescription
simulation_idpathrequiredThe ID of a specific simulation.


Start simulation and get results

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.simulate(<project>, version=<version>, branch=<branch>, element_id=<element_id>, config=<config>, commit_results=<True/False>, verification=<All/None/Fail>, data=json.dumps(<param>))

...

Code Block
titleRequest and response examples
 # SpaceCraftMassRollup sample

parameters = {
    "inputs":
   {
       "telecom.antenna.me":10,
        "telecom.amplifier.me":20
   },
 "outputs": 
    [ 
        "me",
        "propulsion.me",
        "propulsion.tank.me",
        "propulsion.thruster.me",
        "telecom.me",
        "telecom.antenna.me",
        "telecom.amplifier.me"
    ] 
}
        
client.simulate('SpacecraftMassRollup_SimWeb', config='spacecraft mass analysis', commit_results=False, data=json.dumps(parameters))


Get simulation status

Panel
borderColorlightgrey
borderWidth1

client.get_status(<simulation_id>)

...

Code Block
titleRequest and response examples
client.get_status('55089221-8673-4391-aa3e-a8e774ecfa48')
 
{'state': 'RUNNING',
 'simulationId': '55089221-8673-4391-aa3e-a8e774ecfa48',
 'simulationTime': '0 ms',
 'ui': '/simulation/api/ui/55089221-8673-4391-aa3e-a8e774ecfa48/CoffeeMachine.html',
 'project': 'CoffeeMachine',
 'config': 'Coffee Machine Web',
 'elapsedTime': 6598}


client.get_status('ce8c8215-0515-43fd-9d34-92d1d7a95d87')
 
{'state': 'COMPLETED',
 'simulationId': 'ce8c8215-0515-43fd-9d34-92d1d7a95d87',
 'simulationTime': '3000 ms',
 'project': 'SpacecraftMassRollup',
 'config': 'spacecraft mass analysis',
 'elapsedTime': 6598}
 
 
client.get_status('b7bdf933-f58d-4e7e-b73b-8370c60485cd')
 
{'state': 'QUEUED',
 'queueNumber': 3,
 'simulationId': 'b7bdf933-f58d-4e7e-b73b-8370c60485cd',
 'simulationTime': '0 ms',
 'project': 'CarBrakingAnalysis',
 'elapsedTime': 52}


Get simulation variables

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

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

...

ParameterInRequired or optionalDescription
simulation_idpathrequiredThe ID of the running simulation.
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>))

...

Code Block
titleRequest and response examples
var = {
 "variables":
 {
 "position": 40
 }
}

client.set_variables('23ceff24-28fa-47e4-b29f-b6b60b4b12e3', variables=json.dumps(var))


Pause simulation

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.pause(<simulation_id>)

...

ParameterInRequired or optionalDescription
simulation_idpathrequiredThe ID of the running simulation.


Resume simulation

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.resume(<simulation_id>)

...

ParameterInRequired or optionalDescription
simulation_idpathrequiredThe ID of the running simulation.


Get simulation results

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.get_result(<simulation_id>)

...

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


Specifying input and output parameters.

The following table describes the parameters used in the request:

ParameterInRequired or optionalDescription
simulation_idpathrequiredThe ID of the running simulation.


Get the list of running simulations

Panel
borderColorlightgrey
borderWidth1
borderStylesolid
client.get_running()


This REST API request gets the list of all currently running simulations including the queued simulations that are placed in a waiting line.


Terminate simulation

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.terminate(<simulation_id>)

...

ParameterInRequired or optionalDescription
simulation_idpathrequiredThe ID of a specific simulation.


Check for Simulation Configurations

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.has_configurations(<project>, version=<version>, branch=<branch>)

...

ParameterInRequired or optionalDescription
projectpathrequiredThe Teamwork Cloud project name or ID.
versionpathoptionalThe Teamwork Cloud project version.
branchpathoptionalThe project branch name or ID. If the branch is omitted, the trunk is used instead.


Get Simulation Configurations

Panel
borderColorlightgrey
borderWidth1
borderStylesolid

client.get_configurations(<project>, version=<version>, branch=<branch>, element_id=<element_id>)

...

ParameterInRequired or optionalDescription
projectpathrequiredThe Teamwork Cloud project name or ID.
versionpathoptionalThe Teamwork Cloud project version.
branchpathoptionalThe project branch name or ID. If the branch is omitted, the trunk is used instead.
element_idpathoptionalThe server ID of the Instance Specification to be executed.
filterpathoptional

Returns Simulations Configurations with a specified UI tag for a particular project. The only possible value for the filter parameter is ui.

Only Simulations Configurations having at least one of the following UI elements are returned:

  • Frame
  • Table
  • TimeSeries chart


Get Simulation Configuration descriptor

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.

The following table describes the parameters used in the request:

...