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 unittest
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_criteria_complete true
ActionExample analyze_name CriteriaWriter
ActionExample analyze_name Energy
ActionExample modify_name PairDistribution
""")
syscode = subprocess.call("../../../build/bin/fst < launch3.txt > launch3.log", 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]:
class TestAnalyzeText(unittest.TestCase):
def test_analyze(self):
run_fst()
file1 = open('action_ex_crit.csv', 'r')
lines = file1.readlines()
file1.close()
exec('iprm={' + lines[0][1:]+'}', globals())
print(iprm)
self.assertEqual(iprm['num_sweeps'], 2)
unittest.main(argv=[''], verbosity=2, exit=False)
test_analyze (__main__.TestAnalyzeText) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.020s
OK
{'num_sweeps': 2, 'soft_min': 0, 'soft_max': 4}
[2]:
<unittest.main.TestProgram at 0x7fda9d036290>
Did this tutorial work as expected? Did you find any inconsistencies or have any comments? Please contact us. Any feedback is appreciated!