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_type0 /feasst/particle/atom.fstprt cubic_side_length 8
Potential Model IdealGas
ThermoParams beta 1 chemical_potential0 1
FlatHistogram Macrostate MacrostateNumParticles width 1 max 4 min 0 Bias TransitionMatrix min_sweeps 2
TrialTransfer particle_type 0
CriteriaUpdater trials_per_update 1e2
CriteriaWriter trials_per_write 1e2 output_file action_ex_crit.csv
Energy output_file en.csv trials_per_write 1e2 multistate true
PairDistribution output_file grig.csv trials_per_write 1e2
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: ./fst < file.txt
FEASST version 0.25.6
MonteCarlo
Configuration cubic_side_length 8 particle_type0 /home/user/feasst/particle/atom.fstprt
Potential Model IdealGas
ThermoParams beta 1 chemical_potential0 1
FlatHistogram Bias TransitionMatrix Macrostate MacrostateNumParticles max 4 min 0 min_sweeps 2 width 1
TrialTransfer particle_type 0
CriteriaUpdater trials_per_update 1e2
CriteriaWriter output_file action_ex_crit.csv trials_per_write 1e2
Energy multistate true output_file en.csv trials_per_write 1e2
PairDistribution output_file grig.csv trials_per_write 1e2
Run until complete
# initializing random number generator with seed: 1734454620
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!