Along with the release of AnyLogic 8.5, came the new features of AnyLogic Cloud API 8.5.0. Using the API, you can configure and remotely run simulation models in the cloud, as well as create user interfaces for them (here is an example interface). You can find out about these and other features in our previous blog. In this post, the focus is on analyzing the new features and trying out the examples.
- The key for the API. A trial key is provided bellow and a fully functional key is available to users of commercial versions of AnyLogic Cloud.
These examples use the Service System Demo model. It describes a maintenance process where you can set the capacity (Server capacity), analyze the average size of the service queue (Mean queue size parameter), and resource loading (Server utilization parameter). The model is located on our test account and you will connect to it via the API. If you’re ready, let's get started.
(header links lead to a detailed description)
This example shows how to programmatically find the desired model in the Cloud, set the input data, and run a simple experiment without animation.
How does it work?
As soon as the web page and scripts are loaded, a CloudClient object is created with the API key: e05a6efa-ea5f-4adf-b090-ae0ca7d16c20. It allows you to connect to the host from which the API client is loaded. This step is repeated in each example.
After clicking the button, the runSimulation() function is called. This deactivates the button and launches the following commands: select the latest version of the Service System Demo model, set the value of the Server capacity to 8, and create a simulation object with this input. Next, the getOutputsAndRunIfAbsent() command checks if the experiment has completed and displays data on the page.
When the experiment is completed, the APIs of the Inputs and SingleRunOutputs objects are used to display the input and output data. These are the values for Server capacity, Mean queue size, and Server utilization parameters.
If the experiment completes without errors, the finally block is called and the experiment start button becomes active. If there are errors, a catch block is called that provides an error message to the console.
All previous experiments along with input and results are stored in the cloud. If the inputs for an experiment run are the same, AnyLogic Cloud recalls the previous results, speeding up the new experiment and saving computing resources. This example shows how this works, and also how to create a widget to configure experiment parameters directly from a web interface.
In the HTML window, a widget is setup to input a value for the Server capacity parameter.
To see the progress of a simple experiment, you can make an indicator change color when an experiment is running by using the ModelRun.getProgress() function. This example shows how to do this, and also another way to run the model using the run(), waitForCompletion(), and getOutputs() functions.
The startPolling() function calls the simulation.getProgress() function with an interval of 1 second until the stopPolling() function is called. The stopPolling() function is called when the experiment has ended or an error has occurred, it then checks for 2 seconds that the indicator is full.
Calling the simulation.run() function starts the experiment (if it has not already been started with previous input data) and returns a simulation object, without waiting for the experiment to end. The completion of an experiment is tracked with the simulation.waitForCompletion() function, which returns the same object. Next, calling the simulation.getOutputs() function requests the results. Instead of this sequence, you can use one function simulation.getOutputsAndRunIfAbsent().
Here, we examined only 3 examples of using the cloud service API. Other examples are available in the API documentation.
To test the capabilities of the API on your own model, use the test version of AnyLogic Private Cloud Lite. Please note: the current version of the API is compatible only with AnyLogic 8.5 and subsequent versions of the program.
If you have questions about examples, how the API works, or about installing AnyLogic Private Cloud Lite, please contact our technical support team via the feedback form in AnyLogic.