Make your own custom Action

In this example, a user can follow the instructions in /feasst/plugin/example/include/action_example.h to make their own custom Action.

In this relatively trivial example, the newly implemented Action forces an Analyze or Modify to write to file.

[1]:
import sys
import subprocess
import numpy as np
import pandas as pd

def run_fst():
    with open("launch3.txt", "w") as myfile: myfile.write("""
MonteCarlo
Configuration particle_type=fluid:/feasst/particle/lj_new.txt cubic_side_length=8
Potential Model=IdealGas
ThermoParams beta=1 chemical_potential=1
FlatHistogram Macrostate=MacrostateNumParticles width=1 max=4 min=0 Bias=TransitionMatrix min_sweeps=2
TrialTransfer particle_type=fluid
CriteriaUpdater trials_per_update=1e2
Let [write]=trials_per_write=1e2 output_file=action_ex
Energy [write]_en.csv multistate=true
CriteriaWriter [write]_crit.csv
PairDistribution [write]_gr.csv
Run until=complete
ActionExample analyze_name=CriteriaWriter
ActionExample analyze_name=Energy
ActionExample modify_name=PairDistribution""")
    syscode = subprocess.call("../../../build/bin/fst < launch3.txt", shell=True, executable='/bin/bash')
    if syscode > 0: sys.exit(1)

Check that, with “ActionExample analyze_name CriteriaWriter”, the number of sweeps in the writen file is equal to the number of sweeps requested (i.e., 2).

[2]:
run_fst()
file1 = open('action_ex_crit.csv', 'r')
lines = file1.readlines()
file1.close()
exec('iprm={' + lines[0][1:]+'}', globals())
print(iprm)
assert iprm['num_sweeps'] == 2
# Usage: /home/user/feasst/build/bin/fst < file.txt
FEASST version 0.25.13
MonteCarlo
Configuration cubic_side_length=8 particle_type=fluid:/feasst/particle/lj_new.txt
Potential Model=IdealGas
ThermoParams beta=1 chemical_potential=1
FlatHistogram Bias=TransitionMatrix Macrostate=MacrostateNumParticles max=4 min=0 min_sweeps=2 width=1
TrialTransfer particle_type=fluid
CriteriaUpdater trials_per_update=1e2
Energy multistate=true output_file=action_ex_en.csv trials_per_write=1e2
CriteriaWriter output_file=action_ex_crit.csv trials_per_write=1e2
PairDistribution output_file=action_ex_gr.csv trials_per_write=1e2
Run until=complete
# Initializing random number generator with seed: 1749043512
ActionExample analyze_name=CriteriaWriter
ActionExample analyze_name=Energy
ActionExample modify_name=PairDistribution
{'num_sweeps': 2, 'soft_min': 0, 'soft_max': 4}

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