From bdfbff25c541f5c654a20d274cad857edf27716b Mon Sep 17 00:00:00 2001 From: Brock Dyer Date: Tue, 1 Sep 2026 22:08:46 -0400 Subject: [PATCH 1/5] Nexus: Remove several unused variables from `nexus_core`, simplify `Simulation` and `ProjectManager` accordingly --- nexus/nexus/__init__.py | 37 ------ nexus/nexus/nexus_base.py | 33 ++--- nexus/nexus/project_manager.py | 47 +++---- nexus/nexus/simulation.py | 134 ++++++-------------- nexus/nexus/tests/__init__.py | 3 - nexus/nexus/tests/test_project_manager.py | 15 --- nexus/nexus/tests/test_settings.py | 21 ++- nexus/nexus/tests/test_simulation_module.py | 11 -- 8 files changed, 74 insertions(+), 227 deletions(-) diff --git a/nexus/nexus/__init__.py b/nexus/nexus/__init__.py index 80a2b2a3fc..c1e4540bce 100644 --- a/nexus/nexus/__init__.py +++ b/nexus/nexus/__init__.py @@ -587,43 +587,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: diff --git a/nexus/nexus/nexus_base.py b/nexus/nexus/nexus_base.py index fc371a94eb..d22b7bf971 100644 --- a/nexus/nexus/nexus_base.py +++ b/nexus/nexus/nexus_base.py @@ -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 @@ -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, @@ -86,19 +76,12 @@ 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 diff --git a/nexus/nexus/project_manager.py b/nexus/nexus/project_manager.py index b07da096ff..0f5c716baa 100644 --- a/nexus/nexus/project_manager.py +++ b/nexus/nexus/project_manager.py @@ -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() @@ -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 diff --git a/nexus/nexus/simulation.py b/nexus/nexus/simulation.py index f1990e250e..863010f102 100644 --- a/nexus/nexus/simulation.py +++ b/nexus/nexus/simulation.py @@ -65,27 +65,26 @@ #====================================================================# -import contextlib import os -import sys import shutil +import sys import tempfile import traceback -from functools import partial from copy import deepcopy from datetime import datetime from pathlib import Path from string import Template from subprocess import Popen from typing import ClassVar -from .developer import DevBase, obj, unavailable, FileFormatError, NexusError -from .structure import Structure, read_structure -from .physical_system import PhysicalSystem + +from .developer import DevBase, FileFormatError, NexusError, obj, unavailable from .machines import Job, Workstation, get_machine -from .nexus_base import NexusCore, nexus_core, dynamic_storage +from .nexus_base import NexusCore, dynamic_storage, nexus_core +from .physical_system import PhysicalSystem +from .structure import Structure, read_structure from .utilities import path_string - + class SimulationInput(NexusCore): def is_valid(self): raise NotImplementedError @@ -279,7 +278,7 @@ class Simulation(NexusCore): 'identifier','path','infile','outfile','errfile','imagefile', 'input','job','files','dependencies','analysis_request', 'block','block_subcascade','app_name','app_props','system', - 'skip_submit','force_write','simlabel','fake_sim', + 'skip_submit','simlabel','fake_sim', 'restartable','force_restart' }) sim_imagefile = 'sim.p' @@ -390,7 +389,6 @@ def __init__(self,**kwargs): self.block = False self.block_subcascade = False self.skip_submit = nexus_core.skip_submit - self.force_write = False self.loaded = False self.ordered_dependencies = [] self.process_id = None @@ -1374,96 +1372,36 @@ def block_dependents(self,*,block_self=True): def progress(self,dependency_id=None): if dependency_id is not None: self.wait_ids.remove(dependency_id) - #end if - if len(self.wait_ids)==0 and not self.block and not self.failed: - modes = nexus_core.modes - mode = nexus_core.mode - progress = True - if mode==modes.none: - return - elif mode==modes.setup: - self.write_inputs() - elif mode==modes.send_files: - self.send_files() - elif mode==modes.submit: - self.submit() - progress = self.finished - elif mode==modes.get_output: + + if len(self.wait_ids) > 0 or self.block or self.failed: + return # No progression if we are waiting or blocked or failed + + progress = True + conds_ops = ( + (self.created_directories, self.create_directories), + (self.got_dependencies, self.get_dependencies), + (self.setup, self.write_inputs), + (self.sent_files, self.send_files), + (self.finished, self.submit), + ) + for cond, op in conds_ops: + if not cond: + op() + + progress_post = self.finished + progress = self.finished and self.analyzed + + if progress_post: + if not self.got_output: self.get_output() - progress = self.finished - elif mode==modes.analyze: + + if not self.analyzed: self.analyze() - progress = self.finished - elif mode==modes.stages: - if not self.created_directories: - self.create_directories() - #end if - if not self.got_dependencies: - self.get_dependencies() - #end if - if not self.setup and 'setup' in nexus_core.stages: - self.write_inputs() - #end if - if not self.sent_files and 'send_files' in nexus_core.stages: - self.send_files() - #end if - if not self.finished and 'submit' in nexus_core.stages: - self.submit() - #end if - if nexus_core.dependent_modes <= nexus_core.stages_set: - progress_post = self.finished - progress = self.finished and self.analyzed - else: - progress_post = progress - #end if - if progress_post: - if not self.got_output and 'get_output' in nexus_core.stages: - self.get_output() - #end if - if not self.analyzed and 'analyze' in nexus_core.stages: - self.analyze() - #end if - #end if - elif mode==modes.all: - if not self.setup: - self.write_inputs() - self.send_files(enter=False) - #end if - if not self.finished: - self.submit() - #end if - if self.finished: - if not self.got_output: - self.get_output() - #end if - if not self.analyzed: - self.analyze() - #end if - #end if - progress = self.finished - #end if - if progress and not self.block_subcascade and not self.failed: - for sim in self.dependents.values(): - if not sim.bundled: - sim.progress(self.simid) - #end if - #end for - #end if - elif len(self.wait_ids)==0 and self.force_write: - modes = nexus_core.modes - mode = nexus_core.mode - if mode==modes.stages: - if not self.got_dependencies: - self.get_dependencies() - #end if - if 'setup' in nexus_core.stages: - self.write_inputs() - #end if - if not self.sent_files and 'send_files' in nexus_core.stages: - self.send_files() - #end if - #end if - #end if + + if progress and not (self.block_subcascade or self.failed): + for sim in self.dependents.values(): + if not sim.bundled: + sim.progress(self.simid) #end def progress diff --git a/nexus/nexus/tests/__init__.py b/nexus/nexus/tests/__init__.py index f35b7a13f9..6b55b53003 100644 --- a/nexus/nexus/tests/__init__.py +++ b/nexus/nexus/tests/__init__.py @@ -14,9 +14,6 @@ NEXUS_CORE_KEYS = ( "local_directory", "remote_directory", - "mode", - "stages", - "stages_set", "status", "sleep", "timeout", diff --git a/nexus/nexus/tests/test_project_manager.py b/nexus/nexus/tests/test_project_manager.py index b953d79d38..c0b396a686 100644 --- a/nexus/nexus/tests/test_project_manager.py +++ b/nexus/nexus/tests/test_project_manager.py @@ -9,13 +9,10 @@ def test_init(): from ..developer import obj - from ..nexus_base import nexus_core from ..project_manager import ProjectManager pm = ProjectManager() - modes = nexus_core.modes - assert(pm.persistent_modes==set([modes.submit,modes.all])) def check(v): assert isinstance(v,obj) assert len(v)==0 @@ -413,20 +410,8 @@ def test_run_project(tmp_path): nexus_core.remote_directory = str(tmp_path) nexus_core.file_locations = nexus_core.file_locations + [str(tmp_path)] - assert(nexus_core.mode==nexus_core.modes.stages) - assert(len(nexus_core.stages)==0) - - nexus_core.stages = list(nexus_core.primary_modes) - nexus_core.stages_set = set(nexus_core.stages) - - primary_modes = ['setup','send_files','submit','get_output','analyze'] - assert(value_eq(nexus_core.stages,primary_modes)) - assert(value_eq(nexus_core.stages_set,set(primary_modes))) - nexus_core.sleep = 0.1 - log = generic_settings.devlog - flags = ['setup','sent_files','submitted','finished','got_output','analyzed'] def finished(s): diff --git a/nexus/nexus/tests/test_settings.py b/nexus/nexus/tests/test_settings.py index 98afdda17e..79c19f0a1d 100644 --- a/nexus/nexus/tests/test_settings.py +++ b/nexus/nexus/tests/test_settings.py @@ -45,12 +45,12 @@ def aux_defaults(): def check_settings_core_noncore(): nckeys_check = set([ - 'command_line','debug', 'dependent_modes', 'emulate', + 'command_line','debug', 'file_locations', 'generate_only', 'graph_sims', 'indent', - 'load_images', 'local_directory', 'mode', 'modes', 'monitor', - 'primary_modes', 'progress_tty', 'pseudo_dir', + 'load_images', 'local_directory', 'monitor', + 'progress_tty', 'pseudo_dir', 'remote_directory', 'results', 'runs', - 'skip_submit', 'sleep', 'stages', 'stages_set', 'status', 'timeout', + 'skip_submit', 'sleep', 'status', 'timeout', 'status_modes', 'status_only', 'trace', 'verbose', 'dynamic' ]) nnckeys_check = set([ @@ -58,11 +58,11 @@ def check_settings_core_noncore(): ]) setkeys_check = set([ 'command_line','basis_dir', 'basissets', 'debug', - 'dependent_modes', 'emulate', 'file_locations', 'generate_only', - 'graph_sims', 'indent', 'load_images', 'local_directory', 'mode', - 'modes', 'monitor', 'primary_modes', 'progress_tty', + 'file_locations', 'generate_only', + 'graph_sims', 'indent', 'load_images', 'local_directory', + 'monitor', 'progress_tty', 'pseudo_dir', 'remote_directory', 'results', - 'runs', 'skip_submit', 'sleep', 'stages', 'stages_set', 'status', + 'runs', 'skip_submit', 'sleep', 'status', 'timeout', 'status_modes', 'status_only', 'trace', 'verbose', 'dynamic' ]) @@ -102,12 +102,9 @@ def check_empty_settings(): settings.command_line = True nexus_core.command_line = True check_settings_core_noncore() - # nexus core sets basic run stages and PseudoSet registries are empty - assert(nexus_core.stages_set==set(nexus_core_defaults.primary_modes)) + # PseudoSet registries are empty assert(len(PseudoSet.pseudo_files)==0) assert(len(PseudoSet.labeled_pseudosets)==0) - nexus_core.stages_set = set() - nexus_core.stages = [] assert(object_eq(nexus_core,nexus_core_defaults)) # nexus noncore sets a BasisSets object assert(isinstance(nexus_noncore.basissets,BasisSets)) diff --git a/nexus/nexus/tests/test_simulation_module.py b/nexus/nexus/tests/test_simulation_module.py index df50fe39ca..a0cb9b8791 100644 --- a/nexus/nexus/tests/test_simulation_module.py +++ b/nexus/nexus/tests/test_simulation_module.py @@ -743,7 +743,6 @@ def test_init(): files = set([]), finished = False, force_restart = False, - force_write = False, got_dependencies = False, got_output = False, identifier = 'sim', @@ -2187,16 +2186,6 @@ def test_progress(tmp_path): nexus_core.remote_directory = str(tmp_path) nexus_core.file_locations = nexus_core.file_locations + [str(tmp_path)] - assert(nexus_core.mode==nexus_core.modes.stages) - assert(len(nexus_core.stages)==0) - - nexus_core.stages = list(nexus_core.primary_modes) - nexus_core.stages_set = set(nexus_core.stages) - - primary_modes = ['setup','send_files','submit','get_output','analyze'] - assert(value_eq(nexus_core.stages,primary_modes)) - assert(value_eq(nexus_core.stages_set,set(primary_modes))) - template = ''' name = "$name" From 5e35c6ed5a38e82f35b19080a4ad0ae977f11342 Mon Sep 17 00:00:00 2001 From: Brock Dyer Date: Tue, 1 Sep 2026 22:27:12 -0400 Subject: [PATCH 2/5] Nexus: Remove unnecessary `status_modes` and `status` from `nexus_core`, and simplify code that referenced them --- nexus/nexus/__init__.py | 15 ------------ nexus/nexus/nexus_base.py | 10 -------- nexus/nexus/project_manager.py | 23 +++---------------- nexus/nexus/tests/__init__.py | 1 - nexus/nexus/tests/test_project_manager.py | 28 ----------------------- nexus/nexus/tests/test_settings.py | 23 +++++++++---------- 6 files changed, 14 insertions(+), 86 deletions(-) diff --git a/nexus/nexus/__init__.py b/nexus/nexus/__init__.py index c1e4540bce..bc8138be24 100644 --- a/nexus/nexus/__init__.py +++ b/nexus/nexus/__init__.py @@ -572,21 +572,6 @@ def process_core_settings(self,kw): 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 - elif kw.status==True: - nexus_core.status = nexus_core.status_modes.standard - elif kw.status in nexus_core.status_modes: - nexus_core.status = nexus_core.status_modes[kw.status] - else: - msg = 'invalid status mode specified: {0}\nvalid status modes are: {1}'.format(kw.status,sorted(nexus_core.status_modes.keys())) - raise ValueError(msg) - #end if - #end if - if nexus_core.status_only and nexus_core.status==nexus_core.status_modes.none: - nexus_core.status = nexus_core.status_modes.standard - #end if # process simulation settings if 'local_directory' in kw: diff --git a/nexus/nexus/nexus_base.py b/nexus/nexus/nexus_base.py index d22b7bf971..c412469888 100644 --- a/nexus/nexus/nexus_base.py +++ b/nexus/nexus/nexus_base.py @@ -45,14 +45,6 @@ nexus_noncore = obj() nexus_core_noncore = obj() -status_modes = obj( - none = 0, - standard = 1, - active = 2, - failed = 3, - ready = 4, - ) - nexus_noncore_defaults = obj( basis_dir = None, basissets = None, @@ -80,8 +72,6 @@ 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 progress_tty = False, # used by: ProjectManager graph_sims = False, # used by: ProjectManager command_line = True, # used by: Settings diff --git a/nexus/nexus/project_manager.py b/nexus/nexus/project_manager.py index 0f5c716baa..24363464e4 100644 --- a/nexus/nexus/project_manager.py +++ b/nexus/nexus/project_manager.py @@ -97,7 +97,7 @@ def run_project(self,*,status=False,status_only=False): self.log('\nProject starting',n=0) self.init_cascades() status_only = status_only or nexus_core.status_only - status = status or status_only or nexus_core.status!=nexus_core.status_modes.none + status = status or status_only if status: self.write_simulation_status() if status_only: @@ -281,33 +281,16 @@ def traverse_cascades(self,operation=trivial,*args,**kwargs): def write_simulation_status(self): - status = nexus_core.status - status_modes = nexus_core.status_modes self.log('\ncascade status',n=1) self.log('setup, sent_files, submitted, finished, got_output, analyzed, failed',n=2) all_sids = set() for sim in self.simulations.values(): - add = False - if status==status_modes.active: - add = sim.active() - elif status==status_modes.ready: - add = sim.ready() - elif status==status_modes.failed: - add = sim.failed - else: - add = True - #end if - if add: - all_sids.add(sim.simid) - #end if - #end for + all_sids.add(sim.simid) + sids = set() for isim in sorted(all_sids): sim = self.simulations[isim] if not sim.bundled: - if status==status_modes.active and not sim.active(): - continue - #end if self.status_line(sim) sids.add(sim.simid) if sim.is_bundle: diff --git a/nexus/nexus/tests/__init__.py b/nexus/nexus/tests/__init__.py index 6b55b53003..a24cf2ce04 100644 --- a/nexus/nexus/tests/__init__.py +++ b/nexus/nexus/tests/__init__.py @@ -14,7 +14,6 @@ NEXUS_CORE_KEYS = ( "local_directory", "remote_directory", - "status", "sleep", "timeout", "file_locations", diff --git a/nexus/nexus/tests/test_project_manager.py b/nexus/nexus/tests/test_project_manager.py index c0b396a686..8f05aa7d95 100644 --- a/nexus/nexus/tests/test_project_manager.py +++ b/nexus/nexus/tests/test_project_manager.py @@ -290,8 +290,6 @@ def test_write_simulation_status(): pm = ProjectManager() pm.add_simulations(list(sims.values())) - status_modes = nexus_core.status_modes - def status_log(): log.reset() pm.write_simulation_status() @@ -299,7 +297,6 @@ def status_log(): return '\n'.join(line.rstrip() for line in s.splitlines()) #end def status_log - assert(nexus_core.status==status_modes.none) status_ref = ''' cascade status setup, sent_files, submitted, finished, got_output, analyzed, failed @@ -314,31 +311,6 @@ def status_log(): ''' assert(status_log().strip()==status_ref.strip()) - nexus_core.status = status_modes.standard - assert(status_log().strip()==status_ref.strip()) - - nexus_core.status = status_modes.active - status_ref = ''' - cascade status - setup, sent_files, submitted, finished, got_output, analyzed, failed - 000000 ------ test_sim_s11 ./runs/ - 000000 ------ test_sim_s12 ./runs/ - setup, sent_files, submitted, finished, got_output, analyzed, failed - ''' - assert(status_log().strip()==status_ref.strip()) - - nexus_core.status = status_modes.ready - assert(status_log().strip()==status_ref.strip()) - - nexus_core.status = status_modes.failed - status_ref = ''' - cascade status - setup, sent_files, submitted, finished, got_output, analyzed, failed - (No simulations present) - setup, sent_files, submitted, finished, got_output, analyzed, failed - ''' - assert(status_log().strip()==status_ref.strip()) - sim = sims.s11 sim.setup = True sim.sent_files = True diff --git a/nexus/nexus/tests/test_settings.py b/nexus/nexus/tests/test_settings.py index 79c19f0a1d..43fb7bcc98 100644 --- a/nexus/nexus/tests/test_settings.py +++ b/nexus/nexus/tests/test_settings.py @@ -44,34 +44,33 @@ def aux_defaults(): #end def aux_defaults def check_settings_core_noncore(): - nckeys_check = set([ + nckeys_check = { 'command_line','debug', 'file_locations', 'generate_only', 'graph_sims', 'indent', 'load_images', 'local_directory', 'monitor', 'progress_tty', 'pseudo_dir', 'remote_directory', 'results', 'runs', - 'skip_submit', 'sleep', 'status', 'timeout', - 'status_modes', 'status_only', 'trace', 'verbose', 'dynamic' - ]) - nnckeys_check = set([ + 'skip_submit', 'sleep', 'timeout', + 'status_only', 'trace', 'verbose', 'dynamic' + } + nnckeys_check = { 'basis_dir', 'basissets', 'pseudo_dir' - ]) - setkeys_check = set([ + } + setkeys_check = { 'command_line','basis_dir', 'basissets', 'debug', 'file_locations', 'generate_only', 'graph_sims', 'indent', 'load_images', 'local_directory', 'monitor', 'progress_tty', 'pseudo_dir', 'remote_directory', 'results', - 'runs', 'skip_submit', 'sleep', 'status', - 'timeout', - 'status_modes', 'status_only', 'trace', 'verbose', 'dynamic' - ]) + 'runs', 'skip_submit', 'sleep', + 'timeout', 'status_only', 'trace', 'verbose', 'dynamic' + } setkeys_allowed = setkeys_check | Settings.allowed_vars nckeys = set(nexus_core.keys()) nnckeys = set(nexus_noncore.keys()) setkeys = set(settings.keys()) - + assert(nckeys==nckeys_check) assert(nnckeys==nnckeys_check) assert(setkeys>=setkeys_check) From 95e282d5444abf7e3ae28d42af07f4feae9e4cee Mon Sep 17 00:00:00 2001 From: Brock Dyer Date: Tue, 1 Sep 2026 22:34:06 -0400 Subject: [PATCH 3/5] Nexus: Remove unused/redundant `verbose`, `debug`, and `trace` variables from `nexus_core` --- nexus/nexus/__init__.py | 9 ------- nexus/nexus/nexus_base.py | 40 ++++++++++++++---------------- nexus/nexus/tests/test_settings.py | 8 +++--- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/nexus/nexus/__init__.py b/nexus/nexus/__init__.py index bc8138be24..04ae54349d 100644 --- a/nexus/nexus/__init__.py +++ b/nexus/nexus/__init__.py @@ -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.' @@ -568,11 +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 - # process simulation settings if 'local_directory' in kw: nexus_core.file_locations.append(kw.local_directory) diff --git a/nexus/nexus/nexus_base.py b/nexus/nexus/nexus_base.py index c412469888..39d9422543 100644 --- a/nexus/nexus/nexus_base.py +++ b/nexus/nexus/nexus_base.py @@ -68,9 +68,6 @@ monitor = True, # used by: ProjectManager,Simulation,Machine skip_submit = False, # used by: Simulation load_images = True, # used by: ProjectManager - verbose = True, # used by: NexusCore - debug = False, # used by: NexusCore - trace = False, # used by: NexusCore indent = ' ', # used by: NexusCore progress_tty = False, # used by: ProjectManager graph_sims = False, # used by: ProjectManager @@ -159,26 +156,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 diff --git a/nexus/nexus/tests/test_settings.py b/nexus/nexus/tests/test_settings.py index 43fb7bcc98..1346c06c23 100644 --- a/nexus/nexus/tests/test_settings.py +++ b/nexus/nexus/tests/test_settings.py @@ -45,25 +45,25 @@ def aux_defaults(): def check_settings_core_noncore(): nckeys_check = { - 'command_line','debug', + 'command_line', 'file_locations', 'generate_only', 'graph_sims', 'indent', 'load_images', 'local_directory', 'monitor', 'progress_tty', 'pseudo_dir', 'remote_directory', 'results', 'runs', 'skip_submit', 'sleep', 'timeout', - 'status_only', 'trace', 'verbose', 'dynamic' + 'status_only', 'dynamic' } nnckeys_check = { 'basis_dir', 'basissets', 'pseudo_dir' } setkeys_check = { - 'command_line','basis_dir', 'basissets', 'debug', + 'command_line', 'basis_dir', 'basissets', 'file_locations', 'generate_only', 'graph_sims', 'indent', 'load_images', 'local_directory', 'monitor', 'progress_tty', 'pseudo_dir', 'remote_directory', 'results', 'runs', 'skip_submit', 'sleep', - 'timeout', 'status_only', 'trace', 'verbose', 'dynamic' + 'timeout', 'status_only', 'dynamic' } setkeys_allowed = setkeys_check | Settings.allowed_vars From 11090d34f57933855beacb6d39387e7657a4f38d Mon Sep 17 00:00:00 2001 From: Brock Dyer Date: Tue, 1 Sep 2026 22:40:13 -0400 Subject: [PATCH 4/5] Nexus: Remove removed variables from `Settings` vars --- nexus/nexus/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nexus/nexus/__init__.py b/nexus/nexus/__init__.py index 04ae54349d..43e9ef5fe3 100644 --- a/nexus/nexus/__init__.py +++ b/nexus/nexus/__init__.py @@ -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'}) From 45f40e3595ac6ac0ffc289a99851f8b97613f6ef Mon Sep 17 00:00:00 2001 From: brockdyer03 Date: Wed, 2 Sep 2026 10:14:59 -0400 Subject: [PATCH 5/5] Revert "Nexus: Remove unnecessary `status_modes` and `status` from `nexus_core`, and simplify code that referenced them" This reverts commit 5e35c6ed5a38e82f35b19080a4ad0ae977f11342. --- nexus/nexus/__init__.py | 16 +++++++++++++ nexus/nexus/nexus_base.py | 10 ++++++++ nexus/nexus/project_manager.py | 23 ++++++++++++++++--- nexus/nexus/tests/__init__.py | 1 + nexus/nexus/tests/test_project_manager.py | 28 +++++++++++++++++++++++ nexus/nexus/tests/test_settings.py | 11 +++++---- 6 files changed, 81 insertions(+), 8 deletions(-) diff --git a/nexus/nexus/__init__.py b/nexus/nexus/__init__.py index 43e9ef5fe3..eb4c29e68c 100644 --- a/nexus/nexus/__init__.py +++ b/nexus/nexus/__init__.py @@ -564,6 +564,22 @@ def process_machine_settings(self,mset): def process_core_settings(self,kw): + if 'status' in kw: + if kw.status==None or kw.status==False: + nexus_core.status = nexus_core.status_modes.none + elif kw.status==True: + nexus_core.status = nexus_core.status_modes.standard + elif kw.status in nexus_core.status_modes: + nexus_core.status = nexus_core.status_modes[kw.status] + else: + msg = 'invalid status mode specified: {0}\nvalid status modes are: {1}'.format(kw.status,sorted(nexus_core.status_modes.keys())) + raise ValueError(msg) + #end if + #end if + if nexus_core.status_only and nexus_core.status==nexus_core.status_modes.none: + nexus_core.status = nexus_core.status_modes.standard + #end if + # process simulation settings if 'local_directory' in kw: nexus_core.file_locations.append(kw.local_directory) diff --git a/nexus/nexus/nexus_base.py b/nexus/nexus/nexus_base.py index 39d9422543..8ff8f14aae 100644 --- a/nexus/nexus/nexus_base.py +++ b/nexus/nexus/nexus_base.py @@ -45,6 +45,14 @@ nexus_noncore = obj() nexus_core_noncore = obj() +status_modes = obj( + none = 0, + standard = 1, + active = 2, + failed = 3, + ready = 4, + ) + nexus_noncore_defaults = obj( basis_dir = None, basissets = None, @@ -69,6 +77,8 @@ skip_submit = False, # used by: Simulation load_images = True, # used by: ProjectManager indent = ' ', # used by: NexusCore + status_modes = status_modes, # used by: ProjectManager + status = status_modes.none, # used by: ProjectManager progress_tty = False, # used by: ProjectManager graph_sims = False, # used by: ProjectManager command_line = True, # used by: Settings diff --git a/nexus/nexus/project_manager.py b/nexus/nexus/project_manager.py index 24363464e4..0f5c716baa 100644 --- a/nexus/nexus/project_manager.py +++ b/nexus/nexus/project_manager.py @@ -97,7 +97,7 @@ def run_project(self,*,status=False,status_only=False): self.log('\nProject starting',n=0) self.init_cascades() status_only = status_only or nexus_core.status_only - status = status or status_only + status = status or status_only or nexus_core.status!=nexus_core.status_modes.none if status: self.write_simulation_status() if status_only: @@ -281,16 +281,33 @@ def traverse_cascades(self,operation=trivial,*args,**kwargs): def write_simulation_status(self): + status = nexus_core.status + status_modes = nexus_core.status_modes self.log('\ncascade status',n=1) self.log('setup, sent_files, submitted, finished, got_output, analyzed, failed',n=2) all_sids = set() for sim in self.simulations.values(): - all_sids.add(sim.simid) - + add = False + if status==status_modes.active: + add = sim.active() + elif status==status_modes.ready: + add = sim.ready() + elif status==status_modes.failed: + add = sim.failed + else: + add = True + #end if + if add: + all_sids.add(sim.simid) + #end if + #end for sids = set() for isim in sorted(all_sids): sim = self.simulations[isim] if not sim.bundled: + if status==status_modes.active and not sim.active(): + continue + #end if self.status_line(sim) sids.add(sim.simid) if sim.is_bundle: diff --git a/nexus/nexus/tests/__init__.py b/nexus/nexus/tests/__init__.py index a24cf2ce04..6b55b53003 100644 --- a/nexus/nexus/tests/__init__.py +++ b/nexus/nexus/tests/__init__.py @@ -14,6 +14,7 @@ NEXUS_CORE_KEYS = ( "local_directory", "remote_directory", + "status", "sleep", "timeout", "file_locations", diff --git a/nexus/nexus/tests/test_project_manager.py b/nexus/nexus/tests/test_project_manager.py index 8f05aa7d95..c0b396a686 100644 --- a/nexus/nexus/tests/test_project_manager.py +++ b/nexus/nexus/tests/test_project_manager.py @@ -290,6 +290,8 @@ def test_write_simulation_status(): pm = ProjectManager() pm.add_simulations(list(sims.values())) + status_modes = nexus_core.status_modes + def status_log(): log.reset() pm.write_simulation_status() @@ -297,6 +299,7 @@ def status_log(): return '\n'.join(line.rstrip() for line in s.splitlines()) #end def status_log + assert(nexus_core.status==status_modes.none) status_ref = ''' cascade status setup, sent_files, submitted, finished, got_output, analyzed, failed @@ -311,6 +314,31 @@ def status_log(): ''' assert(status_log().strip()==status_ref.strip()) + nexus_core.status = status_modes.standard + assert(status_log().strip()==status_ref.strip()) + + nexus_core.status = status_modes.active + status_ref = ''' + cascade status + setup, sent_files, submitted, finished, got_output, analyzed, failed + 000000 ------ test_sim_s11 ./runs/ + 000000 ------ test_sim_s12 ./runs/ + setup, sent_files, submitted, finished, got_output, analyzed, failed + ''' + assert(status_log().strip()==status_ref.strip()) + + nexus_core.status = status_modes.ready + assert(status_log().strip()==status_ref.strip()) + + nexus_core.status = status_modes.failed + status_ref = ''' + cascade status + setup, sent_files, submitted, finished, got_output, analyzed, failed + (No simulations present) + setup, sent_files, submitted, finished, got_output, analyzed, failed + ''' + assert(status_log().strip()==status_ref.strip()) + sim = sims.s11 sim.setup = True sim.sent_files = True diff --git a/nexus/nexus/tests/test_settings.py b/nexus/nexus/tests/test_settings.py index 1346c06c23..d2c0b53323 100644 --- a/nexus/nexus/tests/test_settings.py +++ b/nexus/nexus/tests/test_settings.py @@ -50,8 +50,8 @@ def check_settings_core_noncore(): 'load_images', 'local_directory', 'monitor', 'progress_tty', 'pseudo_dir', 'remote_directory', 'results', 'runs', - 'skip_submit', 'sleep', 'timeout', - 'status_only', 'dynamic' + 'skip_submit', 'sleep', 'status', 'timeout', + 'status_modes', 'status_only', 'dynamic' } nnckeys_check = { 'basis_dir', 'basissets', 'pseudo_dir' @@ -62,15 +62,16 @@ def check_settings_core_noncore(): 'graph_sims', 'indent', 'load_images', 'local_directory', 'monitor', 'progress_tty', 'pseudo_dir', 'remote_directory', 'results', - 'runs', 'skip_submit', 'sleep', - 'timeout', 'status_only', 'dynamic' + 'runs', 'skip_submit', 'sleep', 'status', + 'timeout', + 'status_modes', 'status_only', 'dynamic' } setkeys_allowed = setkeys_check | Settings.allowed_vars nckeys = set(nexus_core.keys()) nnckeys = set(nexus_noncore.keys()) setkeys = set(settings.keys()) - + assert(nckeys==nckeys_check) assert(nnckeys==nnckeys_check) assert(setkeys>=setkeys_check)