Optimization Server on University* Premises
*Also valid for research labs, companies and other organizations
For more than two years, the university shown above has been hosting an Optimization Server — or just Opt-server — in one of its high-end computers, allowing more than 200 students, teachers and researchers to run mathematical programs remotely in the university's computing facilities from inside and outside the campus using only a web browser.
The purpose of this post is to explain how other universities and institutions can do the same, and what benefits are there in doing so.
- What does an Opt-server do?
- Why host an Opt-server in a College Campus?
-
How to setup an Opt-server in an University?
- 1. Create an Enterprise account for the University
- 2. Download and run PIFOP Opt-server on the host machine
- 3. Download and install the solvers and interpreters that you want the Opt-server to support
- 4. Configure the Opt-server
- 5. Test your Opt-server in PIFOP
- 6. Allow students and faculty to use the Opt-server
- 7. Keep the Opt-server running 24/7
What does an Opt-server do?
Simply put, a PIFOP Opt-server is a program that executes commands entered by users in PIFOP IDE terminals. It is a process spawner that executes users' programs in the host machine — e.g. AMPL, GAMS and Python programs — and redirects the output back to the user. It is one of the vertices of the PIFOP triangle Browser IDE — Central server — Opt-server :
For more technical details, see Introduction to Optimization Server Hosting.
Why host an Opt-server in an University?
Here are four reasons why:
- Install solvers in one machine and use them from anywhere: This has at least two benefits. First, it spares students and faculty from the trouble of having to setup solvers and interpreter themselves in their own machines. And second, students and faculty don't need to be in the campus to run optimization models in its computer labs.
- Easy and safe remote execution: Say goodbye to SSH-based remote execution solutions, which not only are hard to use but often give to the user more control over the machine than they should have.
- Save money by making the best use of existing computing resources in your premises: Many universities already have number-crunching machines perfectly capable of running multiple optimization models in parallel. This is especially true for models developed by students, who usually work with small to medium sized problems. This means that the university doesn't need to spend extra money on cloud infrastructure in order to enable remote code execution: it can provide this convenience to its affiliates with the resources that they already have!
- A single solution for every solver. Many proprietary solver vendors offer their own cloud solutions for their users, allowing them to run the solver remotely via a web platform of some kind. However, that solution will only work for that specific solver, whereas the PIFOP Opt-server is compatible with most of them — including open source ones — and does not bind you to any one in particular.
How to setup an Opt-server in an University?
In this tutorial, we are going to explain how to setup an Opt-server in a college campus in such a way that it can be used by its students and faculty to run three of the most used programs among mathematical programmers: AMPL, GAMS and Python. The AMPL and GAMS bundles usually come with a selection of proprietary and open source solvers, which you will also be able to use from PIFOP.
1. Create an Enterprise account for the University
The way that you get PIFOP for multiple students and faculty is by creating an account for the university — which is just like any other account — and upgrading it to the highly discounted Enterprise plan with subscription keys for each student and faculty member.
If you would actually prefer a Provisioned Opt-server managed by us, take a look at this page.
2. Download and run PIFOP Opt-server on the host machine
Follow the first 5 steps of the Hosting an Opt-server guide.
3. Download and install the solvers and interpreters that you want the Opt-server to support
Here we are going to download and install the the academic versions of AMPL and GAMS — both of which come with academic licenses of commercial and free solvers — and Python 3.9.
AMPL for Courses
-
Request the free AMPL for Courses license.
Fill the form and download the license.
Other kinds of licenses should work as well. -
Extract the downloaded .tgz file into $HOME/programs — or into another directory of your choice:
$ mkdir $HOME/programs $ tar -xf ampl*.tgz -C $HOME/programs
-
Test the installation. The following command should display AMPL's version and your license:
$ cd $HOME/programs/ampl* $ ./ampl -v
GAMS Community License
-
Request the free GAMS Community License.
You will receive a license file by email.
Other kinds of licenses should work as well. - Download GAMS for Linux.
-
Execute the downloaded .exe from $HOME/programs
— GAMS will extracted itself inside the directory from which the installer is called:
$ mv ./linux_x64_64_sfx.exe $HOME/programs/ $ cd $HOME/programs $ chmod +x ./linux_x64_64_sfx.exe $ ./linux_x64_64_sfx.exe
-
Save the license that you have received in your email in a file named gamslice.txt
inside the extracted GAMS directory.
$ cd $HOME/programs/gams* $ echo 'GAMS_Demo_license_for_xxxxxxxxxxxx_____________xxxxxxx|xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx______________________________ xxxxxxxxxx_**GAMS_Demo_license_restricted_to_non-commercial_use** xxxxxxxxxx_______________________________________________________ xxxxxxxx_______________________________________C_DEMO____________ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_________________________________ ' > ./gamslice.txt
-
Run the gamsinst. Follow the steps to
configure GAMS default solvers.
$ ./gamsinst
- Test the installation. Running ./gams should display "The installed license is valid" just before its expiration date.
Python 3 (and PIP)
-
Install Python 3.9 — or another version of your choice.
$ sudo add-apt-repository ppa:deadsnakes/ppa $ sudo apt-get install python3.9 $ sudo apt-get install python3.9-distutils
-
Manually install PIP via the get-pip.py script.
$ wget https://bootstrap.pypa.io/get-pip.py $ python3.9 get-pip.py $ python3.9 -m pip install --upgrade setuptools
-
Optional, but recommended: create Python $HOME supporting directories to avoid
potential problems for not having them in-place beforehand when trying to install
Python packages from PIFOP.
$ mkdir -p -- $HOME/.local/lib/python3.9/site-packages $ mkdir -p -- $HOME/.local/bin $ mkdir -p -- $HOME/.cache/pip
-
Test the installation.
$ python3.9 --version
4. Configure the Opt-server
Now we need to tell the Opt-server that we've installed on Step 2 where we have installed AMPL, GAMS and Python and configure the commands that PIFOP users will enter to execute them. We do this by modifying the config.json file inside the Opt-server directory.
Use the file below as a template configuration file for your Opt-server. We have highlighted the parts that you need to modify, which include:
- The server-name — we've used University in this example
- $HOME explicit path — we've used /home/joe in this example
- The directory into which you have extracted AMPL and GAMS — we've used /home/joe/programs in this example
- The version numbers of GAMS and Python — we've used 40.1 and 3.9 in this example
For an explanation of each configuration option, see List of Configuration Options.
{ "server-name" : "University", "credentials-file" : true, "sandboxes" : [ { "name" : "general-purpose", "mount-readable" : [ "/lib", "/lib64", "/dev/random", "/dev/urandom", "/usr/lib/x86_64-linux-gnu", "/home/joe/programs", "/usr/lib/python3.9", "/usr/bin/python3.9", "/usr/bin/python3.9:/usr/bin/python3", "/home/joe/.local/bin", "/home/joe/.local/lib/python3.9/site-packages" ], "mount-writable" : [ "/dev/null" ], "environment-variables" : [ "PATH=/home/joe/programs/ampl.linux-intel64", "LD_LIBRARY_PATH=/home/joe/programs/ampl.linux-intel64/amplapi/lib", "PATH=/home/joe/programs/gams40.1_linux_x64_64_sfx", "PYTHONPATH=/home/joe/programs/gams40.1_linux_x64_64_sfx/apifiles/Python/api_38", "PYTHONPATH=/home/joe/programs/gams40.1_linux_x64_64_sfx/apifiles/Python/gams", "LD_LIBRARY_PATH=/home/joe/programs/gams40.1_linux_x64_64_sfx", "LD_LIBRARY_PATH=/home/joe/programs/gams40.1_linux_x64_64_sfx/apifiles/C++/lib", "PATH=/usr/bin", "PYTHONPATH=/usr/lib/python3.9", "PYTHONPATH=/home/joe/.local/lib/python3.9/site-packages", "PYTHONPATH=/home/joe/.local/bin" ] } ], "commands" : [ { "name" : "ampl", "executable" : "/home/joe/programs/ampl.linux-intel64/ampl", "sandbox" : "general-purpose" }, { "name" : "gams", "executable" : "/home/joe/programs/gams40.1_linux_x64_64_sfx/gams", "sandbox" : "general-purpose" }, { "name" : "python3", "executable" : "/usr/bin/python3.9", "file-extensions" : [ "py" ], "sandbox" : "general-purpose" }, { "name" : "pip3", "executable" : "/usr/bin/python3.9", "prepend-options" : "-m pip", "auto-mount" : "disabled", "enable-network" : true, "inherit-user-id" : true, "admin-only" : true, "mount-readable" : [ "/lib", "/lib64", "/etc/resolv.conf", "/usr/bin/python3.9", "/usr/lib/python3.9" ], "mount-writable" : [ "/home/joe/.cache/pip", "/home/joe/.local/bin", "/home/joe/.local/share", "/home/joe/.local/lib/python3.9/site-packages", "/dev/null" ], "environment-variables" : [ "PYTHONPATH=/usr/lib/python3.9", "PYTHONPATH=/home/joe/.local/lib/python3.9/site-packages", "PYTHONPATH=/home/joe/.local/bin", "PATH=/home/joe/.local/bin" ] } ] }
5. Test your Opt-server in PIFOP
-
Open a PIFOP project and select the Opt-server. If you don't see the option to select
your Opt-server, it is probably because you forgot to start it:
$ ./opt-server --start
- Enter the command help in the terminal. If you don't see one of the commands that you have configured — ampl, gams, python3 and pip3 — make sure that they are properly configured in the Opt-server's config.json (step 4).
-
Try running each of the commands that you have configured.
You can try to execute the AMPL/GAMS examples in this list. If you see error messages containing NSJAIL that means that the sandbox is not properly configured to run the program it is trying to run. Make sure that you have no missing or mispelled paths in the sandbox configuration (step 4). - If everything is working, you are ready to upgrade your account to the Enterprise plan and allow students and faculty to use the Opt-server — see the next step.
6. Allow students and faculty to use the Opt-server
- Go to the subscription keys management page and hand-out the keys that you've got to your students and faculty using their PIFOP user names or emails.
-
Make sure the Opt-server is running.
$ ./opt-server --start
- Go to the Opt-server management page and select the Opt-server.
- Create a New User Group. Name it Enterprise and fill-in the other fields of the form.
-
Once the Enterprise user group is created, every member of your Enterprise will be able to
select the Opt-server and use it from PIFOP.
Every user that you give a subscription key to is considered to be a member of your Enterprise.
7. Recommended: Keep the Opt-server running 24/7
Use screen to keep the Opt-server running even after you logout from the machine
-
Install screen if needed:
$ sudo apt-get install screen
-
Create a new screen session named "opt-server":
$ screen -S opt-server
-
Navigate to the Opt-server directory and run it using the the
run-forever script:
$ cd /path/to/opt-server $ ./run-forever ./opt-server --start
The run-forever script is a small utility script that is shipped in the Opt-server bundle. All that it does is to run whatever command line that you pass to it in a loop so that, in the event a program failure, the command is executed again after 2 seconds. This is its core logic: while true do $@ sleep 2 done
To interrupt the above command, press Ctrl+c twice, the first to interrupt the Opt-server, and the second to interrupt the script. -
To Dettach from the screen session, press Ctrl+a, release,
and then press d. To Reattach to the screen session, enter the command
$ screen -r opt-server
- If you want to learn more screen commands, checkout this screen cheatcheat by Carlos Tosta.
Add a Cron job to start the Opt-server on boot
Cron is a linux program that schedules commands to be executed on specific dates or when special events happen — such as a reboot. See below how to automate the screen session creation shown in the previous section upon reboot.
-
Start editing your cron file.
crontab -e
-
Append the following line to the file and save it — modify paths if needed:
@reboot cd ~/opt-server ; screen -S opt-server -d -m bash -c './run-forever ./opt-server --start ; bash'
Done!
I hope that this guide can help you hosting an Opt-server in your own premises. If you have any questions, don't hesitate to contact us!
Until next time!
— Davi