Skip to content

Commit

Permalink
feat(app): stop-training file => graceful exit
Browse files Browse the repository at this point in the history
If a "stop-training" file exists in the directory where
app/train-cloud-microphysics.f90 is running, the program will
initiate normal termination after completing the first epoch
in which the file is found.
  • Loading branch information
rouson committed Sep 12, 2023
1 parent 7b33548 commit d80416e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions app/train-cloud-microphysics.f90
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ program train_cloud_microphysics

call read_train_write

close(plot_unit)
call system_clock(t_finish)
print *,"System clock time: ", real(t_finish - t_start, real64)/real(clock_rate, real64)
print *,new_line('a') // "______training_cloud_microhpysics done _______"
Expand All @@ -97,6 +98,7 @@ subroutine read_train_write
integer, allocatable :: lbounds(:)
integer t, b, t_end
character(len=:), allocatable :: network_input, network_output, network_file
logical stop_requested

network_input = base_name // "_input.nc"
network_output = base_name // "_output.nc"
Expand Down Expand Up @@ -182,7 +184,6 @@ subroutine read_train_write
real(rkind), parameter :: keep = 0.01
real(rkind), allocatable :: cost(:)
real(rkind), allocatable :: harvest(:)
integer, parameter :: mini_batch_size=1
integer i, batch, lon, lat, level, time, network_unit, io_status, final_step, epoch

open(newunit=network_unit, file=network_file, form='formatted', status='old', iostat=io_status, action='read')
Expand Down Expand Up @@ -249,13 +250,20 @@ subroutine read_train_write
call json_file%write_lines(string_t(network_file))
end associate
end associate

close(network_unit)

inquire(file="stop-training", exist=stop_requested)

graceful_exit: &
if (stop_requested) then
print *,'Shutting down because a file named "stop-training" was found.'
return
end if graceful_exit

end do
end associate

close(plot_unit)

end block train_network

end subroutine read_train_write
Expand Down

0 comments on commit d80416e

Please sign in to comment.