Run FEASST as server with Python client

In this example, run feasst in server mode and use a Python client to send text interface commands.

[1]:
import multiprocessing
import subprocess
import time
import socket

PORT = 54321
BUFFER_SIZE = 1000

def server():
    subprocess.call('echo "Server port '+str(PORT)+' buffer_size '+str(BUFFER_SIZE)+'" | ../../../build/bin/fst', shell=True, executable='/bin/bash')

def client():
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(("localhost", PORT))
    for line in ['MonteCarlo',
                 'Configuration cubic_side_length 8 particle_type0 /feasst/particle/lj.fstprt',
                 'Potential Model LennardJones',
                 'ThermoParams beta 1 chemical_potential0 1',
                 'Metropolis',
                 'TrialTranslate',
                 'TrialAdd particle_type 0',
                 'Run until_num_particles 20',
                 'Remove name TrialAdd',
                 'Log output_file lj.csv',
                 'Run num_trials 10']:
        sock.send(bytes(line, 'utf-8'))
        message = sock.recv(BUFFER_SIZE)
        #print(str(message))

if __name__ == '__main__':
    proc1 = multiprocessing.Process(target=server, args=())
    proc2 = multiprocessing.Process(target=client, args=())
    proc1.start()
    time.sleep(1)
    proc2.start()
    proc1.join()
    proc2.join()
# FEASST version: v0.24.4-4-g68448a9657-dirty-user/server
# initializing server on localhost:54321
MonteCarlo
Configuration cubic_side_length 8 particle_type0 /home/user/feasst/particle/lj.fstprt
Potential Model LennardJones
ThermoParams beta 1 chemical_potential0 1
Metropolis
TrialTranslate
TrialAdd particle_type 0
Run until_num_particles 20
# initializing random number generator with seed: 1706119047
Remove name TrialAdd
Log output_file lj.csv
Run num_trials 10

Did this tutorial work as expected? Did you find any inconsistencies or have any comments? Please contact us. Any feedback is appreciated!