Skip to content

Using Python to communicate with MASTERS headless

mchelem edited this page Dec 16, 2014 · 2 revisions

Install

In order to communicate with MASTERS from Python you need to install py4j:

pip install py4j

Usage

Running MASTERS headless server

java -cp .:/usr/local/share/py4j/py4j0.8.2.1.jar MastersServer

Using masters from Python

First you need to obtain a reference to masters:

from py4j.java_gateway import JavaGateway

gateway = JavaGateway()
masters = gateway.entry_point.getMasters()

The you can run the simulation:

# Path to the simulation parameters
parameters = "/home/me/simulation.parameters"

# Start simulation
simulation = masters.Simulation(parameters)
simulation.start()

# Check if simulation has finished
if simulation.has_finished():
   # Print report
   simulation.print_report()

# Force simulation stop
simulation.stop()

Clone this wiki locally