Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print current n_live #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions ns_analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ def read_inputs(args, line_skip=0, line_end=None, interval=1):
(n_walkers, n_cull, n_Extra_DOF) = fields
flat_V_prior = "False"
N_atoms = "0"
variable_n_live = "False"
elif len(fields) == 5:
(n_walkers, n_cull, n_Extra_DOF, flat_V_prior, N_atoms) = fields
variable_n_live = "False"
elif len(fields) == 6:
(n_walkers, n_cull, n_Extra_DOF, flat_V_prior, N_atoms, variable_n_live) = fields
else:
raise ValueError("unknown number of fields %d (not 3 or 5) in first line of energies file" % len(fields))
n_walkers = int(n_walkers)
Expand All @@ -26,6 +30,13 @@ def read_inputs(args, line_skip=0, line_end=None, interval=1):
else:
sys.stderr.write("Unknown flat_V_prior string '%s'\n" % flat_V_prior)
sys.exit(1)
if variable_n_live.lower() == "t" or variable_n_live.lower() == "true":
variable_n_live = True
elif variable_n_live.lower() == "f" or variable_n_live.lower() == "false":
variable_n_live = False
else:
sys.stderr.write("Unknown variable_n_live string '%s'\n" % variable_n_live)
sys.exit(1)
N_atoms = int(N_atoms)

Es=[]
Expand All @@ -37,26 +48,26 @@ def read_inputs(args, line_skip=0, line_end=None, interval=1):
if n_fields is not None and n_fields != len(fields):
sys.stderr.write(f'Mismatch field # prev {n_fields} cur {len(fields)}, skipping\n')
continue
if len(fields) == 3:
if (len(fields) == 3 and not variable_n_live) or (len(fields) == 4 and variable_n_live):
try:
E = float(fields[1])
V = float(fields[2])
except:
continue
if n_fields is None:
n_fields = 3
n_fields = len(fields)
Es.append(E)
Vs.append(V)
elif len(fields) == 2:
elif (len(fields) == 2 and not variable_n_live):
try:
E = float(fields[1])
except:
continue
if n_fields is None:
n_fields = 2
n_fields = len(fields)
Es.append(E)
else: # silently skip lines with problems
sys.stderr.write("WARNING: input line with problem: number of fields not 2 or 3, or not floats\n")
sys.stderr.write("WARNING: input line with problem: number of fields not 2 or 3 (without variable_n_live) or 4 (with variable_n_live), or not floats\n")
continue

if len(Vs) == 0:
Expand Down
6 changes: 3 additions & 3 deletions ns_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2368,7 +2368,7 @@ def do_ns_loop():
nExtraDOF = (n_atoms-movement_args['keep_atoms_fixed'])*nD
else:
nExtraDOF = n_atoms*nD
energy_io.write("%d %d %d %s %d\n" % (ns_args['n_walkers'], ns_args['n_cull'], nExtraDOF, movement_args['MC_cell_flat_V_prior'], n_atoms))
energy_io.write("%d %d %d %s %d true\n" % (ns_args['n_walkers'], ns_args['n_cull'], nExtraDOF, movement_args['MC_cell_flat_V_prior'], n_atoms))

## print(print_prefix, ": random state ", np.random.get_state())
## if rank == 0:
Expand Down Expand Up @@ -2522,8 +2522,8 @@ def do_ns_loop():

# record Emax walkers energies
if rank == 0:
for (E, V) in zip(Emax, Vmax):
energy_io.write("%d %.60f %.60f\n" % (i_ns_step, E, V))
for ii, (E, V) in enumerate(zip(Emax, Vmax)):
energy_io.write("%d %.50f %.50f %d\n" % (i_ns_step, E, V, ns_args['n_walkers'] - ii))
energy_io.flush()

## Save the energies and corresponding iteration numbers in a list then print(them out only when printing a snapshot)
Expand Down