Skip to content
Closed
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
53 changes: 4 additions & 49 deletions nexus/nexus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ class Settings(NexusCore):
})

core_assign_vars = frozenset({
'results', 'load_images', 'remote_directory', 'verbose', 'progress_tty',
'command_line', 'sleep', 'timeout', 'monitor', 'debug', 'skip_submit', 'dynamic', 'runs',
'stages', 'pseudo_dir', 'graph_sims', 'generate_only', 'trace',
'results', 'load_images', 'remote_directory', 'progress_tty',
'command_line', 'sleep', 'timeout', 'monitor', 'skip_submit', 'dynamic', 'runs',
'pseudo_dir', 'graph_sims', 'generate_only',
'local_directory', 'status_only'
})

core_process_vars = frozenset({'file_locations', 'status', 'mode'})
core_process_vars = frozenset({'file_locations'})

noncore_assign_vars = frozenset({'basis_dir'})

Expand Down Expand Up @@ -373,10 +373,6 @@ def process_command_line_settings(self,script_settings):
action='store_true',default=False,
help='Report status of all simulations and then exit.'
)
parser.add_option('--status',dest='status',
default='none',
help="Controls displayed simulation status information. May be set to one of 'standard', 'active', 'failed', or 'ready'."
)
parser.add_option('--generate_only',dest='generate_only',
action='store_true',default=False,
help='Write inputs to all simulations and then exit. Note that no dependencies are processed, e.g. if one simulation depends on another for an orbital file location or for a relaxed structure, this information will not be present in the generated input file for that simulation since no simulations are actually run with this option.'
Expand Down Expand Up @@ -568,10 +564,6 @@ def process_machine_settings(self,mset):


def process_core_settings(self,kw):
# process project manager settings
if nexus_core.debug:
nexus_core.verbose = True
#end if
if 'status' in kw:
if kw.status==None or kw.status==False:
nexus_core.status = nexus_core.status_modes.none
Expand All @@ -587,43 +579,6 @@ def process_core_settings(self,kw):
if nexus_core.status_only and nexus_core.status==nexus_core.status_modes.none:
nexus_core.status = nexus_core.status_modes.standard
#end if
if 'mode' in kw:
if kw.mode in nexus_core.modes:
nexus_core.mode = kw.mode
else:
msg = 'invalid mode specified: {0}\nvalid modes are: {1}'.format(kw.mode,sorted(nexus_core.modes.keys()))
raise ValueError(msg)
#end if
#end if
mode = nexus_core.mode
modes = nexus_core.modes
if mode==modes.stages:
stages = nexus_core.stages
elif mode==modes.all:
stages = list(nexus_core.primary_modes)
else:
stages = [kw.mode]
#end if
allowed_stages = set(nexus_core.primary_modes)
if isinstance(stages,str):
stages = [stages]
#end if
if len(stages)==0:
stages = list(nexus_core.primary_modes)
elif 'all' in stages:
stages = list(nexus_core.primary_modes)
else:
forbidden = set(nexus_core.stages)-allowed_stages
if len(forbidden)>0:
msg = 'some stages provided are not primary stages.\n You provided '+str(list(forbidden))+'\n Options are '+str(list(allowed_stages))
raise ValueError(msg)
#end if
#end if
# overide user input and always use stages mode
# keep processing code above in case a change is desired in the future
nexus_core.mode = modes.stages
nexus_core.stages = stages
nexus_core.stages_set = set(nexus_core.stages)

# process simulation settings
if 'local_directory' in kw:
Expand Down
73 changes: 26 additions & 47 deletions nexus/nexus/nexus_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@


import os
from os import PathLike
from copy import deepcopy
import pickle
from pickle import UnpicklingError
from copy import deepcopy
from enum import Flag, auto
from os import PathLike
from pathlib import Path
from .utilities import path_string
from .nexus_version import nexus_version
from .memory import resident
from .developer import DevBase, obj, log
from pickle import UnpicklingError

from .developer import DevBase, log, obj
from .memory import resident
from .nexus_version import nexus_version
from .utilities import path_string

# Nexus namespaces
# nexus_core: to be used by NexusCore classes only
Expand All @@ -52,17 +53,6 @@
ready = 4,
)

modes = obj(
none = 0,
setup = 1,
send_files = 2,
submit = 3,
get_output = 4,
analyze = 5,
stages = 6,
all = 7
)

nexus_noncore_defaults = obj(
basis_dir = None,
basissets = None,
Expand All @@ -86,19 +76,9 @@
monitor = True, # used by: ProjectManager,Simulation,Machine
skip_submit = False, # used by: Simulation
load_images = True, # used by: ProjectManager
modes = modes, # used by: ProjectManager,Simulation
mode = modes.stages, # used by: Simulation
stages_set = set(), # used by: ProjectManager,Simulation
stages = [], # used by: Simulation
primary_modes = ['setup','send_files','submit','get_output','analyze'], # used by: Settings
dependent_modes = set(['submit']), # used by: ProjectManager,Simulation
verbose = True, # used by: NexusCore
debug = False, # used by: NexusCore
trace = False, # used by: NexusCore
indent = ' ', # used by: NexusCore
status_modes = status_modes, # used by: ProjectManager
status = status_modes.none, # used by: ProjectManager
emulate = False, # unused
progress_tty = False, # used by: ProjectManager
graph_sims = False, # used by: ProjectManager
command_line = True, # used by: Settings
Expand Down Expand Up @@ -186,26 +166,25 @@ def log(self,*texts,**kwargs):
If ``True`` and output is to a terminal, overwrite and update the
last line, rather than scrolling.
"""
if nexus_core.verbose:
if len(kwargs)>0:
n = kwargs['n']
else:
n=0
#end if
is_progress = kwargs.get('progress',False)
text=''
for t in texts:
text+=str(t)+' '
#end for
pad = n*nexus_core.indent
output_text = pad+text.replace('\n','\n'+pad)
if nexus_core.progress_tty and is_progress and self._logfile.isatty():
# spaces to ensure previous line is overwritten. Need better solution.
self._logfile.write(output_text+' \r')
self._logfile.flush()
else:
self._logfile.write(output_text+'\n')
if len(kwargs)>0:
n = kwargs['n']
else:
n=0
#end if
is_progress = kwargs.get('progress',False)
text=''
for t in texts:
text+=str(t)+' '
#end for
pad = n*nexus_core.indent
output_text = pad+text.replace('\n','\n'+pad)
if nexus_core.progress_tty and is_progress and self._logfile.isatty():
# spaces to ensure previous line is overwritten. Need better solution.
self._logfile.write(output_text+' \r')
self._logfile.flush()
else:
self._logfile.write(output_text+'\n')

NexusCore.wrote_something = True
#end def log

Expand Down
47 changes: 21 additions & 26 deletions nexus/nexus/project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def restore_default_settings():
#end def restore_default_settings

def __init__(self):
modes = nexus_core.modes
self.persistent_modes = set([modes.submit,modes.all])
self.simulations = obj()
self.cascades = obj()
self.progressing_cascades = obj()
Expand Down Expand Up @@ -107,35 +105,32 @@ def run_project(self,*,status=False,status_only=False):
#end if
#end if
self.log('\nstarting runs:\n'+30*'~',n=1)
if nexus_core.dependent_modes <= nexus_core.stages_set:
if nexus_core.monitor:
start_time = time.time()
ipoll = 0
while len(self.progressing_cascades)>0:
elapsed_time = time.time() - start_time
self.log('elapsed time %.1f s'%elapsed_time,
' memory %3.2f MB'%(memory.resident(children=True)/1e6),
n=1,progress=True)
NexusCore.wrote_something = False
ipoll+=1
self.machine.query_queue()
self.progress_cascades()
self.machine.submit_jobs()
self.update_process_ids()
time.sleep(nexus_core.sleep)
if NexusCore.wrote_something:
self.log()
#end if
#end while
elif len(self.progressing_cascades)>0:

if nexus_core.monitor:
start_time = time.time()
while len(self.progressing_cascades)>0:
elapsed_time = time.time() - start_time
self.log(
f'elapsed time {elapsed_time:.1f} s',
f' memory {(memory.resident(children=True)/1e6):3.2f} MB',
n=1,
progress=True,
)
NexusCore.wrote_something = False
self.machine.query_queue()
self.progress_cascades()
self.machine.submit_jobs()
self.update_process_ids()
#end if
else:
time.sleep(nexus_core.sleep)
if NexusCore.wrote_something:
self.log()

elif len(self.progressing_cascades)>0:
self.machine.query_queue()
self.progress_cascades()
#end if
self.machine.submit_jobs()
self.update_process_ids()

self.log('Project finished\n')
#end def run_project

Expand Down
Loading
Loading