Skip to content

Commit

Permalink
Weighted baseline example with JSON committee (i-pi#318)
Browse files Browse the repository at this point in the history
* Added an example of weighted baseline that uses the new JSON committee
* Delta-JSON qtip4p mode in f90 driver
* Updated readme
  • Loading branch information
ceriottm authored Mar 8, 2024
1 parent 5550ce1 commit c24bca1
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 11 deletions.
18 changes: 9 additions & 9 deletions drivers/f90/driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ PROGRAM DRIVER
vstyle = 63
ELSEIF (trim(cmdbuffer) == "qtip4pf-c-2-delta") THEN
vstyle = 64
ELSEIF (trim(cmdbuffer) == "qtip4pf-c-json-delta") THEN
vstyle = 65
ELSEIF (trim(cmdbuffer) == "gas") THEN
vstyle = 0 ! ideal gas
ELSEIF (trim(cmdbuffer) == "dummy") THEN
vstyle = 99 ! returns non-zero but otherwise meaningless values
ELSE
WRITE(*,*) " Unrecognized potential type ", trim(cmdbuffer)
WRITE(*,*) " Use -m [dummy|gas|lj|sg|harm|harm3d|morse|morsedia|zundel|qtip4pf|pswater|lepsm1|lepsm2|qtip4pf-efield|eckart|ch4hcbe|ljpolymer|MB|doublewell|doublewell_1D|water_dip_pol|qtip4pf-sr|qtip4pf-c-1|qtip4pf-c-2|qtip4pf-c-json|qtip4pf-c-1-delta|qtip4pf-c-2-delta|harmonic_bath|meanfield_bath] "
WRITE(*,*) " Use -m [dummy|gas|lj|sg|harm|harm3d|morse|morsedia|zundel|qtip4pf|pswater|lepsm1|lepsm2|qtip4pf-efield|eckart|ch4hcbe|ljpolymer|MB|doublewell|doublewell_1D|water_dip_pol|harmonic_bath|meanfield_bath|qtip4pf-sr|qtip4pf-c-1|qtip4pf-c-2|qtip4pf-c-json|qtip4pf-c-1-delta|qtip4pf-c-2-delta|qtip4pf-c-json-delta] "
STOP "ENDED"
ENDIF
ELSEIF (ccmd == 4) THEN
Expand Down Expand Up @@ -678,7 +680,7 @@ PROGRAM DRIVER
STOP "ENDED"
ENDIF
CALL qtip4pf_sr(atoms,nat,forces,pot,virial)
ELSEIF (vstyle .ge. 60 .and. vstyle .le. 64 ) THEN
ELSEIF (vstyle .ge. 60 .and. vstyle .le. 65 ) THEN
! qtip4pf committee potential. adds two different types of (small)
! LJ potentials just to have variations on a theme

Expand All @@ -693,7 +695,7 @@ PROGRAM DRIVER
WRITE(*,*) " qtip4pf PES only works with orthorhombic cells", cell_h(1,2), cell_h(1,3), cell_h(2,3)
STOP "ENDED"
ENDIF
IF (vstyle == 63 .or. vstyle == 64) THEN
IF (vstyle == 63 .or. vstyle == 64 .or. vstyle == 65) THEN
pot = 0.0
forces = 0.0
virial = 0.0
Expand Down Expand Up @@ -735,7 +737,7 @@ PROGRAM DRIVER
CALL LJ_getall(rc, 2.5d0, 2d-6, nat, atoms, cell_h, cell_ih, index_list, n_list, pot, forces, virial)
ELSEIF (vstyle == 61 .or. vstyle == 64) THEN ! type 2
CALL LJ_getall(rc, 2.1d0, 24d-6, nat, atoms, cell_h, cell_ih, index_list, n_list, pot, forces, virial)
ELSEIF (vstyle == 62) THEN ! returns both as json
ELSEIF (vstyle == 62 .or. vstyle == 65) THEN ! returns both as json
! return both the committee members as a JSON extra string
CALL LJ_getall(rc, 2.5d0, 2d-6, nat, atoms, cell_h, cell_ih, index_list, n_list, pot, forces, virial)

Expand Down Expand Up @@ -1016,7 +1018,7 @@ PROGRAM DRIVER
CALL writebuffer(socket,TRIM(longbuffer),cbuf)
IF (verbose > 1) WRITE(*,*) " !write!=> extra: ", &
& initbuffer
ELSEIF (vstyle==62) THEN ! returns committee data
ELSEIF (vstyle==62 .or. vstyle==65) THEN ! returns committee data
cbuf = LEN_TRIM(initbuffer)
CALL writebuffer(socket,cbuf)
CALL writebuffer(socket,initbuffer,cbuf)
Expand Down Expand Up @@ -1046,9 +1048,7 @@ PROGRAM DRIVER
CONTAINS
SUBROUTINE helpmessage
! Help banner

WRITE(*,*) " SYNTAX: driver.x [-u] -h hostname -p port -m [dummy|gas|lj|sg|harm|harm3d|morse|zundel|qtip4pf|pswater|lepsm1|lepsm2|qtip4p-efield|eckart|ch4hcbe|ljpolymer|..."
WRITE(*,*) "...|MB|doublewell|doublewell_1D|harmonic_bath|meanfield_bath|morsedia|qtip4pf-sr|water_dip_pol]"
WRITE(*,*) " SYNTAX: driver.x [-u] -a address -p port -m [dummy|gas|lj|sg|harm|harm3d|morse|morsedia|zundel|qtip4pf|pswater|lepsm1|lepsm2|qtip4p-efield|eckart|ch4hcbe|ljpolymer|MB|doublewell|doublewell_1D|water_dip_pol|harmonic_bath|meanfield_bath|qtip4pf-sr|qtip4pf-c-1|qtip4pf-c-2|qtip4pf-c-json|qtip4pf-c-1-delta|qtip4pf-c-2-delta|qtip4pf-c-json-delta]"
WRITE(*,*) " -o 'comma_separated_parameters' [-v] "
WRITE(*,*) ""
WRITE(*,*) " For LJ potential use -o sigma,epsilon,cutoff "
Expand All @@ -1058,7 +1058,7 @@ SUBROUTINE helpmessage
WRITE(*,*) " For qtip4pf-efield use -o Ex,Ey,Ez with Ei in V/nm"
WRITE(*,*) " For ljpolymer use -o n_monomer,sigma,epsilon,cutoff "
WRITE(*,*) " For gas, dummy, use the optional -o sleep_seconds to add a delay"
WRITE(*,*) " For the ideal qtip4pf, qtip4p-sr, zundel, ch4hcbe, nasa, doublewell or doublewell_1D no options are needed! "
WRITE(*,*) " For the ideal, qtip4pf*, zundel, ch4hcbe, nasa, doublewell or doublewell_1D no options are needed! "
END SUBROUTINE helpmessage

END PROGRAM
4 changes: 3 additions & 1 deletion examples/features/committee_models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ All the simulations here use an artificial committee model built by arbitrarily

`weighted_baseline` provides an example of how to use the uncertainty estimate to revert the predictions to a baseline model when the error becomes too large. The ML model in this case is meant to describe a correction over the baseline, which is smoothly suppressed if its uncertainty increases beyond a cutoff.

`extra_json` shows how to run this kind of simulations with a model that provides all the estimates in one go as part of a .json formatted `extras`` string
`extra_json` shows how to run this kind of simulations with a model that provides all the estimates in one go as part of a JSON formatted `extras`` string

`weighted_baseline_extra` replicates the `weighted_baseline` model using a JSON-based ensemble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
driver_model dummy
driver_model2 dummy
driver_model3 dummt
driver_model3 dummy
nsteps 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<simulation verbosity='medium' threading='false'>
<output prefix='simulation'>
<properties stride='10' filename='out'> [ step, time{picosecond}, conserved{electronvolt}, temperature{kelvin}, kinetic_cv{electronvolt}, potential{electronvolt}, pressure_cv{megapascal} ] </properties>
<trajectory filename='pos' stride='10'> positions </trajectory>
<trajectory filename='committee_pot' stride='10' extra_type='committee_pot'> extras </trajectory>
<trajectory filename='committee_force' stride='10' extra_type='committee_force'> extras </trajectory>
<trajectory filename='committee_virial' stride='10' extra_type='committee_virial'> extras </trajectory>
<trajectory filename='baseline_pot' stride='10' extra_type='baseline_pot'> extras </trajectory>
<trajectory filename='baseline_force' stride='10' extra_type='baseline_force'> extras </trajectory>
<trajectory filename='baseline_virial' stride='10' extra_type='baseline_virial'> extras </trajectory>
<trajectory filename='weight' stride='10' extra_type='wb_mixing'> extras </trajectory>
<checkpoint stride='100'/>
</output>
<total_steps>100</total_steps>
<prng>
<seed>31415</seed>
</prng>
<ffcommittee name="committee">
<!--
This is just an example of the structure of a baselined-committee model.
The baseline is a QTIP4P/f water potential, while the corrections are
artificial LJ terms.
-->
<baseline_name> base </baseline_name>
<alpha> 1.5 </alpha>
<baseline_uncertainty units="electronvolt"> 0.1 </baseline_uncertainty>
<active_thresh> 0.05 </active_thresh>
<ffsocket name='base' mode='unix' matching="any" pbc="false">
<address> base </address> <latency> 1e-3 </latency>
</ffsocket>
<ffsocket name='driver-combo' mode='unix' matching="any" pbc="false">
<address>h2o-comm.json</address> <latency> 1e-3 </latency>
</ffsocket>
<parse_json> True </parse_json>
</ffcommittee>
<system>
<initialize nbeads='4'>
<file mode='xyz'> water_216.xyz </file>
<velocities mode='thermal' units='kelvin'> 300 </velocities>
</initialize>
<forces>
<force forcefield='committee' nbeads='1'>
<!-- adding these to force_extras will make the committee extras be treated properly with ring-polymer contraction, ect. -->
<force_extras> [committee_pot, committee_force, committee_virial, baseline_pot, baseline_force, baseline_virial, wb_mixing] </force_extras>
</force>
</forces>
<motion mode='dynamics'>
<dynamics mode='nvt'>
<timestep units='femtosecond'> 0.5 </timestep>
<thermostat mode='pile_g'>
<tau units='femtosecond'> 10 </tau>
</thermostat>
</dynamics>
</motion>
<ensemble>
<temperature units='kelvin'> 300 </temperature>
</ensemble>
</system>
</simulation>
18 changes: 18 additions & 0 deletions examples/features/committee_models/weighted_baseline_extra/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ipi=i-pi
driver=i-pi-driver
sleep_time=2

${ipi} input.xml > log.i-pi &
echo "# i-PI is running"

echo "# Waiting for ${sleep_time} (s) before executing driver"
sleep ${sleep_time}

${driver} -u -a base -m qtip4pf &
${driver} -u -a h2o-comm.json -m qtip4pf-c-json-delta &

echo "# All driver instances are running"

wait

echo "# Simulation complete"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
driver_model dummy
driver_model2 dummy
nsteps 10

0 comments on commit c24bca1

Please sign in to comment.