Python API

Lexset has a python package available that can be used to interact with our RESTful API

Install

You can install the python package with a simple pip install. The most recent version is 3.5.0 please be sure you have the most recent version.

pip install lexsetAPI

Create a simulation object

The python package will create a class for each simulation you start. You can use that class to keep track of your data and your simulation's progress.

import lexsetAPI as lexset

token = "Bearer token"
SimulationConfig = "Path to your pipeline config"
numberOfImages = 1000 #The number of data points you want your simulation to generate
userID = 3
nodes = 5
simulationName = "name your simulation"
simulationDescription = "Description of your simulation"
randomSeed = 1

mySimulation = lexset.simulation(token,SimulationConfig,numberOfImages,userID,nodes,simulationName,simulationDescription,randomSeed)

It is also possible to use the python API without creating a class for a simulation. This is necessary if you have already started the simulation via the GUI. You can download, start and stop simulations as well as list all active simulations this way.

Working with already running simulations

If a simulation is already running or "active" you can use the class activateSimulation to easily manage the data associated with your simulation.

mySimulation = lexset.activateSimulation(simulationID,userID,token)

Create a simulation

Once you have created your simulation you then need to send your config to Lexset and create a simulation that you can run on our servers.

mySimulation.createSimulation()

This will send the config to our severs and return your user ID, simulation ID and Dataset ID so that you can work with your data as well as start and stop your simulation.

print(mySimulation.dataID) #get your dataset ID
print(mySimulation.simID)  #get your Simulation ID
print(mySimulation.userID) #get your user ID

Start your simulation

Once you have created a simulation you can then start the simulation and begin collecting data.

Please note that your simulation will first be added to the simulation queue and will be started as soon as resources are available in your account. For more information on the queue please refer to the documentation for the simulation manager.

mySimulation.startSimulation()

If you create a simulation through the GUI you can start it with the following command.

lexset.start(simulationID, token)

Dequeue your simulation

If your simulation is currently in the queue, you can remove it from the queue and place it in a ready state as follows. Please refer to the simulation manager documentation for more information on simulation states.

lexset.dequeue(simulationID,token)

Get your simulation status

If a simulation is complex it might take a long time to run and it may be necessary to check the status periodically.

mySimulation.getStatus()

You can also use getProgress() to print how much of the dataset has been generated as a percentage.

mySimulation.getProgress()

Once you have run this function you can check to see if it is complete or still running.

mySimulation.isComplete

Get Dataset Items

Once your simulation is running and generating data you can check all the datapoints and preview images. To get a full list of all the data generated so far you can use the following.

mySimulation.getDatasetItems()

That will return a list of dataset items rendered so far

[
    {
        "id": 7888,
        "renderjobid": 269,
        "datasetid": 303,
        "renderType": "rgb",
        "filename": "e3c7fb5e-3ab6-4b28-ad6c-811d16a12c01.rgb_0001.png",
        "width": 1920,
        "height": 1080,
        "dateCreated": "04 23 2021 14:53:06",
        "failed": false,
        "endTime": "2021-04-23T14:55:24",
        "startTime": "2021-04-23T14:53:06"
    },
    {
        "id": 7889,
        "renderjobid": 269,
        "datasetid": 303,
        "renderType": "rgb",
        "filename": "44ed74ed-fd60-439b-8dbb-ccf46f7cfa9f.rgb_0001.png",
        "width": 1920,
        "height": 1080,
        "dateCreated": "04 23 2021 14:53:14",
        "failed": false,
        "endTime": "2021-04-23T14:55:30",
        "startTime": "2021-04-23T14:53:14"
    },
    {
        "id": 7890,
        "renderjobid": 269,
        "datasetid": 303,
        "renderType": "seg",
        "filename": "e3c7fb5e-3ab6-4b28-ad6c-811d16a12c01.seg_0001.exr",
        "width": 1920,
        "height": 1080,
        "dateCreated": "04 23 2021 14:55:26",
        "failed": false,
        "endTime": "2021-04-23T14:55:43",
        "startTime": "2021-04-23T14:55:26"
    }
]

You can access the dataset items with this

mySimulation.dataSetItems
#You can also access specific items in the array with
firstSim.dataSetItems[1]

You can also get your progress with the following function.

mySimulation.getProgress()

Stop a simulation

In some situations you might want to stop a simulation early.

mySimulation.stopSimulation()

If you create a simulation through our GUI you can stop with the following command.

lexset.stop(simulationID,token)

Add relationship and colormap files

You can also add relationships and colormaps via our API.

#relationship
lexset.addRule(3,"D:/path/file.yaml",token)
#colormap
lexset.addColorMap(3,"D:/path/file.yaml",token)

List all simulations

If you are running multiple simulations it may be necessary for you get a list of all the simulations.

mySimulation.getSimulations()

If you created your simulation using the GUI you can access a list of simulations as follows.

lexset.listSimulations(userID,token)

Download data

Once your simulation is complete, or after you have forced it to stop, you can download the dataset. You can get an archive to download with the following.

#create the archive
mySimulation.downloadData()
#get the archive URL
mySimulation.datasetURL

It is also possible to download data directly by acquiring your dataset id. You can capture the Dataset id with the getDatasetID() function. Example:

datasetID = lexset.getDatasetID(simulationID,token)
lexset.download(datasetID,token)

//you can also set an optional argument to configure your local filename and directory

lexset.download(datasetID,token, localPath = "NONE")

Track Organization Resources

If you have an enterprise account you will want to track resources being used across all user accounts. You can get the total number of active nodes with the following command.

lexset.getComputeResources(user_id,token)

Get Organization Simulations

Return a list of all simulations created across your organization (enterprise accounts only)

Possible States:

  • RUNNING- a list of all running simulations

  • COMPLETED - a list of completed simulations

  • CREATED- a list of created simulations

  • QUEUED - a list of all simulations currently in the queue

lexset.getOrganizationSimulations(ORGANIZATION-ID,STATE,TOKEN)

This endpoint requires an organization id. Your organization ID is available on your account page.

Multi-Threaded Download

This operation is designed for large datasets. The operation will break your zip archive into multiple parts and download each on a separate thread. You can define the number of threads you want to use with the "workers" argument.

download_multiThread(<SIMULATION ID>,<TOKEN>,"<PATH>.zip",<WORKERS>)

Delete Simulation

You can also delete a simulation using the API through the delete simulation endpoint.

delete_simulation(<SIMULATION ID>,<TOKEN>)

Last updated