I have been trying to call an AIMMS (academic license) procedure from python although this doesn't seem to work. I got the following code from another thread, which seems to work with a paid license. I also saw on another post that the academic licence might have some limitations in this regard.
Is there an API in another language, were I can make Python wrapper around this other language?
or
Is it possible that AIMMS internally allows to run scripts in some language, in which case a script can be built in such a way that they exchange model parameters/inputs/results with the outside world?
Best regards,
Page 1 / 1
@rhserna21
Are you receiving any specific error message when you try this code ?
What happens when you execute the code you have in command, directly in Windows cmd ? If this executes successfully, you’ll know that it is not an issue with your license.
Did you try subprocess.run instead of subprocess.call ? To my knowledge, subprocess.call does not support arguments.
Hi Mohan,
Thanks for your reply, I tried running it in the windows cmd and I get the next error (this line I also ran in a paid license and it worked):
C:\Users\hernandezsernar>"C:\Users\hernandezsernar\AppData\Local\AIMMS\IFA\Aimms\4.79.3.10-x64-VS2017\Bin\AimmsCmd.exe" "C:\Users\hernandezsernar\Documents\COMPETES\Competes_2020.aimms --run-only examplespine" Error: Unable to open AIMMS with "--as-server --ignore-dialogs --hidden "C:\Users\hernandezsernar\Documents\COMPETES\Competes_2020.aimms --run-only examplespine"": Starting up Aimms failed. Program initialization error.
@rhserna21
You are correct that AimmsCmd does not work with the new licensing scheme for Academic Licenses and the Community License. These new types of licenses deliberately do not allow running headless AIMMS sessions, as would be the case with AimmsCmd.
However, we will shortly be releasing a new version of the DataExchange library which will allow procedures in AIMMS models to be run through a REST API. This will form the basis for running AIMMS models through a REST API from our cloud platform later this year, but this functionality will also allow you to access interactive AIMMS sessions on your desktop from e.g. Python. Such a setup will also enable debugging such REST calls, e.g. to figure out possible data problems in your input from Python.
To call your model from within your Python code, you can use the Python requests module.
Prior to making the request, you can call the AIMMS launcher with your project from within Python to get the model ready to accept requests if need be (notice that you will have to accept the use conditions once every day, preventing completely automated continuous runs). You can skip this step if you already have opened your AIMMS project manually.
When calling the REST API, you can either use query parameters in the POST URL to pass e.g. the location of a data file to use or other parameters to configure the optimization, or you can pass the data as the request body and use the Data Exchange library to read it into identifiers in your model, and similarly for the model output.
Thank you Marcel for your reply!
The data exchange library offers and explanation on how to associate a procedure with a dex annotation, by doing this I would be able to expose my procedure under a specific path. My question is where can I insert this annotation in my procedure?. Is there a way to make this more concrete?
e.g. I have this procedure which I would like to call from python
@rhserna21 , procedures have an annotation attribute (under the comments field) where you can specify this.
@mohansx, thanks for the clear description!
At what URL is the REST API exposed? I'm running AIMMS on my machine and would like to call it with e.g. a Python process. Through the documentation I understand this has to happen at:
/api/v1/tasks/{service-name}
What would be the base URL?
Thanks in advance for any help!
To start the HTTP service enabling you to connect with the model from Python, you need to call
dex::api::StartAPIService
from within your model which uses
dex::api::ListenerPort
to specify the listen port (default 8080). So, if you didn't make any changes away from the default port, you can then reach the service at the URL
http://localhost:8080/api/v1/tasks/{service-name}
@jimhommes , were you successful in calling AIMMS from python using the REST API ? If possible, could you share the code and the steps you followed. I am not able to get it done.
Thanks in advance !
Hey @premkrishnan612!
There a few topics on how to use python, did you already read these?
If it still did not work for you, can you send us an email at support@aimms.com with your project for us to understand what is the problem?
Let me know if it helped!
Hi, Thank you for the response, sorry for the delayed reply. I am not a very tech savy person and am still figuring my way around. I had already gone through these topics. I was trying to access the url which leads to the procedure and got a 403 forbidden and then only realised that a key would be needed. How do we get the key for the RESTful API. I am currently using a community edition.
Hello @premkrishnan612
I strongly recommend reading the following section of the documentation to dive a little deeper into the workings of the Rest API capabilities:
I created a procedure named pr_updateName that has the dex::ServiceName newName, hence is my available service/task.
Procedure pr_updateName { Body: { sp_requestParameters(dex::api::reqpar) := dex::api::RequestParameter(dex::api::reqpar); if "newName" in dex::api::RequestPars then sp_name := sp_requestParameters('newName'); endif; } dex::ServiceName: newName; }
Note: the procedure: read all parameters in a request into a string parameter, checks if the newName parameter was sent in the request, if so, updates the string parameter sp_name with that new String.
After which my sp_name string parameter was correctly updated with the string AIMMS
Hope this helps.
Hi @luispinto , Sorry for the delay in responding. Thank you so much for the example, its much clearer now and I was able to adapt it to the application, I was working on.
Reply
Sign up
Already have an account? Login Please use your business or academic e-mail address to register