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

file cleanup, slurm scripts and timeout added to batchtools submit templates #831

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
108fa32
batch tools subpackage
jchen6727 Mar 17, 2024
5446c17
comm update
jchen6727 Mar 18, 2024
f56bac6
new search methods
jchen6727 Mar 19, 2024
b2935c1
fixed import issues
jchen6727 Mar 19, 2024
1bc1eab
updates comm, search
jchen6727 Mar 20, 2024
3d5d0a8
search.py
jchen6727 Mar 21, 2024
cad0574
wrapper tools search
jchen6727 Mar 27, 2024
14502fa
update to batchtools
jchen6727 Mar 30, 2024
d7d3ead
codebase moved to netpyne batchtools
jchen6727 Apr 4, 2024
ccaa1d2
update to comm.py, runners.py
jchen6727 Apr 8, 2024
0b34c0f
update to search (kwargs)
jchen6727 Apr 16, 2024
fbc323e
config update (should delete two keys @ end?)
jchen6727 Apr 18, 2024
9622aa2
replace pubtk with batchtk for compatibility with pip
jchen6727 Apr 25, 2024
c5ffb3d
update the submit (zsh->sh)
jchen6727 Apr 25, 2024
62fbc30
update batchtools, submits
jchen6727 Apr 28, 2024
6273501
fixed socket functionality for submits.py
jchen6727 Apr 30, 2024
0626add
batchtools documentation
jchen6727 May 7, 2024
67108a7
minor updates- search
jchen6727 May 8, 2024
553689b
fixed bug in conn, updated test/examples/* to use dynamic pathing
jchen6727 May 9, 2024
5eb20f8
update CHANGES.md
jchen6727 May 11, 2024
6a98ad5
Batch (#818)
jchen6727 May 13, 2024
98bad60
Updated documentation `batchtools.rst`
jchen6727 May 14, 2024
2908abe
Merge branch 'development' into batch
jchen6727 May 14, 2024
76b6bd6
update `user_documentation.rst`
jchen6727 May 14, 2024
627e7bf
sort init.py
jchen6727 May 14, 2024
d7929dc
updated documentation with new batchtools (beta)
jchen6727 May 14, 2024
6f55c51
updating user documentation
jchen6727 May 14, 2024
05e0656
update per deployment on HPC
jchen6727 May 14, 2024
8cd66ee
Updated logic, bug fix
jchen6727 May 16, 2024
3aae153
Merge branch 'development' into development
jchen6727 May 16, 2024
c1b657a
Merge branch 'batch' into batch
jchen6727 May 16, 2024
8bb241c
Batch update (#822)
jchen6727 May 16, 2024
2ed6d40
Merge remote-tracking branch 'downstate/batch' into batch
jchen6727 May 16, 2024
03ee809
I love git
Jsprouse0 May 31, 2024
d06481b
updated makedirs
jchen6727 Jun 3, 2024
c618bb4
Merge branch 'development' of https://github.com/jchen6727/netpyne in…
jchen6727 Jun 3, 2024
1131d84
fixed typo
jchen6727 Jul 2, 2024
19098e2
moved set_map from batchtk, additional support for n-dim lists
jchen6727 Jul 7, 2024
56b9721
various examples (using rosenbrock)
jchen6727 Jul 15, 2024
a124b0b
updated .rst documentation
jchen6727 Jul 16, 2024
aa8fc35
Merge remote-tracking branch 'origin/development' into development
jchen6727 Jul 16, 2024
56aa212
updates to batchtools to allow 'cfg' initialization with supplied dic…
jchen6727 Jul 16, 2024
e71b2f5
Merge remote-tracking branch 'jchen6727/development' into batch
jchen6727 Jul 16, 2024
1b6b042
fixed save.py
jchen6727 Jul 17, 2024
648395f
updated documentation to batch
jchen6727 Jul 17, 2024
c1de7a8
Batch (#826)
jchen6727 Jul 17, 2024
0d9088a
updates to batchtools
jchen6727 Jul 23, 2024
d661c44
fANOVA importance evaluator (implement in batchtk?)
jchen6727 Jul 30, 2024
fd35529
fanova example
jchen6727 Aug 1, 2024
c4a9c3f
updated user documentation
jchen6727 Aug 1, 2024
f9b7f9c
Merge branch 'batch' into batch
jchen6727 Aug 1, 2024
4bfb81a
update documentation (.rst)
jchen6727 Aug 14, 2024
b63f7ec
Merge branch 'batch' of https://github.com/jchen6727/netpyne into batch
jchen6727 Aug 14, 2024
540c8ec
updating w/ element -> container validation.
jchen6727 Aug 23, 2024
24c97db
wip--- validate &recursive set_map
jchen6727 Aug 25, 2024
3f5c7f7
testing mapping
jchen6727 Aug 26, 2024
14c8109
test_case
jchen6727 Aug 26, 2024
a867592
updates to coupled_rosenbrock example, test_map testing
jchen6727 Aug 26, 2024
8cabf38
update runners, test_map.py
jchen6727 Aug 26, 2024
af06e04
update to runners.py, cfg set mapping
jchen6727 Aug 26, 2024
1c56efb
updating map testing, runners.py testing
jchen6727 Aug 27, 2024
cdae933
updates with mapping function, batch entry checking, map_example2.py d
jchen6727 Aug 30, 2024
0ceec3a
Merge branch 'suny-downstate-medical-center:development' into develop…
jchen6727 Aug 30, 2024
092dbe2
Merge branch 'batch' into development
jchen6727 Aug 30, 2024
7f95e83
update to batchtools submit scripts to reference correct templates
jchen6727 Sep 10, 2024
39b7078
slurm submission script templates added.
jchen6727 Sep 10, 2024
491433a
Merge remote-tracking branch 'downstate/development' into development
jchen6727 Sep 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

cwd = os.getcwd()

# evaluation
def eval_rosenbrock(x0, x1, tid):
cfg = {
'x0': x0,
Expand All @@ -18,8 +19,10 @@ def eval_rosenbrock(x0, x1, tid):
label = 'rosenbrock'
return float(trial(cfg, label, tid, Dispatcher, cwd, '../cma', submit)['fx'])

#data = eval_rosenbrock(1, 1, "x11")



# suggestor
optimizer = CMA(mean=numpy.zeros(2), sigma=1.0)
for generation in range(3):
solutions = []
Expand Down
97 changes: 10 additions & 87 deletions netpyne/batchtools/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
from batchtk.utils import get_path
import numpy
from typing import Any, Callable, Dict, List, Optional, Tuple, Union


import submits

choice = tune.choice
grid = tune.grid_search
Expand Down Expand Up @@ -216,12 +215,14 @@ def run(config):
#should be constant?
constructors = namedtuple('constructors', 'dispatcher, submit')
constructor_tuples = {
('sge', 'socket'): constructors(runtk.dispatchers.INETDispatcher, runtk.submits.SGESubmitSOCK),
('sge', 'socket'): constructors(runtk.dispatchers.INETDispatcher, submits.SGESubmitSOCK),
#('sge', 'unix'): constructors(runtk.dispatchers.UNIXDispatcher, runtk.submits.SGESubmitSOCK), #can't use AF_UNIX sockets on networked machines
('sge', 'sfs' ): constructors(runtk.dispatchers.SFSDispatcher , runtk.submits.SGESubmitSFS ),
('sge', 'sfs' ): constructors(runtk.dispatchers.SFSDispatcher , submits.SGESubmitSFS ),
#('zsh', 'inet'): constructors(runtk.dispatchers.INETDispatcher, runtk.submits.ZSHSubmitSOCK), #TODO preferable to use AF_UNIX sockets on local machines
('sh', 'socket'): constructors(runtk.dispatchers.UNIXDispatcher, runtk.submits.SHSubmitSOCK),
('sh', 'sfs' ): constructors(runtk.dispatchers.SFSDispatcher , runtk.submits.SHSubmitSFS ),
('slurm', 'socket'): constructors(runtk.dispatchers.INETDispatcher, submits.SLURMSubmitSOCK),
('slurm', 'sfs' ): constructors(runtk.dispatchers.SFSDispatcher , submits.SLURMSubmitSFS ),
('sh', 'socket'): constructors(runtk.dispatchers.UNIXDispatcher, submits.SHSubmitSOCK),
('sh', 'sfs' ): constructors(runtk.dispatchers.SFSDispatcher , submits.SHSubmitSFS ),
}#TODO, just say "socket"?

"""
Expand All @@ -237,19 +238,14 @@ def generate_constructors(job_type, comm_type = 'socket', **kwargs):

def generate_parameters(params, algorithm, **kwargs):
"""

Parameters
----------
returns a dictionary of parameters for ray_search based on the input dictionary
from NOTES Salvador:
params = {'synMechTau2': [3.0, 5.0, 7.0], # assumes list of values by default if grid search-like algo
#'synMechTau2': [3.0, 7.0], # assumes lower/upper bounds by default if evol-like algo
'connWeight' : paramtypes.sample_from(lambda _: numpy.random.uniform(0.005, 0.15))} # can optionally pass any of the paramtypes (= ray.tune data types)

Returns
-------
a dictionary of parameters for ray_search based on the input dictionary

#TODO: check coverage of conditional statements (looks okay?)
"""
#TODO: bloated function, prone to error
ray_params = {}
for param, space in params.items():
if isinstance(space, (list, tuple, range, numpy.ndarray)) and algorithm in {'variant_generator'}:
Expand Down Expand Up @@ -334,79 +330,6 @@ def search(job_type: str, # the submission engine to run a single simulation (e.


"""
def ray_search(dispatcher_constructor, submit_constructor, algorithm = "variant_generator", label = 'search',
params = None, concurrency = 1, output_path = '../batch', checkpoint_path = '../ray',
run_config = None, num_samples = 1):
ray.init(
runtime_env={"working_dir": "."}) # needed for python import statements

#TODO class this object for self calls? cleaner? vs nested functions
#TODO clean up working_dir and excludes
if checkpoint_path[0] == '/':
storage_path = os.path.normpath(checkpoint_path)
elif checkpoint_path[0] == '.':
storage_path = os.path.normpath(os.path.join(os.getcwd(), checkpoint_path))
else:
raise ValueError("checkpoint_dir must be an absolute path (starts with /) or relative to the current working directory (starts with .)")
algo = create_searcher(algorithm, max_concurrent=concurrency, batch=True)
#algo = ConcurrencyLimiter(searcher=algo, max_concurrent=concurrency, batch=True)
submit = submit_constructor()
submit.update_templates(
**run_config
)
project_path = os.getcwd()
def run(config):
config.update({'saveFolder': output_path, 'simLabel': LABEL_POINTER})
data = ray_trial(config, label, dispatcher_constructor, project_path, output_path, submit)
session.report({'data': data, 'config': config})

tuner = tune.Tuner(
run,
tune_config=tune.TuneConfig(
search_alg=algo,
num_samples=num_samples, # grid search samples 1 for each param
metric="data"
),
run_config=RunConfig(
storage_path=storage_path,
name=algorithm,
),
param_space=params,
)

results = tuner.fit()
resultsdf = results.get_dataframe()
resultsdf.to_csv("{}.csv".format(label))
"""




"""
from netpyne.batchtools import search, paramtypes
import numpy

https://docs.ray.io/en/latest/tune/api/doc/ray.tune.search.Searcher.html#ray.tune.search.Searcher



params = {'synMechTau2': [3.0, 5.0, 7.0], # assumes list of values by default if grid search-like algo
#'synMechTau2': [3.0, 7.0], # assumes lower/upper bounds by default if evol-like algo
'connWeight' : paramtypes.sample_from(lambda _: numpy.random.uniform(0.005, 0.15))} # can optionally pass any of the paramtypes (= ray.tune data types)

run_config = {'sge': 5, 'command': 'python init.py'}

#TODO rename ray_search to search
search(dispatcher = 'inet', # defaults to 'inet' if no arg is passed?
submit = 'socket', # defaults to 'socket' if no arg is passed?
params = params,
run_config = run_config, #
algorithm = "variant_generator",
concurrency = 9,
output_path = '../batch_func',
checkpoint_path = '../grid_func',
label = 'func_search',
num_samples = 3)
SEE:
'variant_generator'
'random' -> points to variant_generator
Expand Down
105 changes: 102 additions & 3 deletions netpyne/batchtools/submits.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SHSubmitSOCK(SHSubmit):
runtk.SOCKET: '{sockname}'}

class SGESubmit(Submit):
script_args = {'label', 'project_path', 'output_path', 'env', 'command', 'cores', 'vmem', }
script_args = {'label', 'queue', 'cores', 'vmem' 'realtime', 'output_path', 'project_path', 'env', 'command', }
script_template = \
"""\
#!/bin/bash
Expand Down Expand Up @@ -118,7 +118,7 @@ def set_handles(self):


class SGESubmitSFS(SGESubmit):
script_args = {'label', 'project_path', 'output_path', 'env', 'command', 'cores', 'vmem', }
script_args = {'label', 'queue', 'cores', 'vmem' 'realtime', 'output_path', 'project_path', 'env', 'command', }
script_template = \
"""\
#!/bin/bash
Expand All @@ -143,7 +143,7 @@ class SGESubmitSFS(SGESubmit):
}

class SGESubmitSOCK(SGESubmit):
script_args = {'label', 'project_path', 'output_path', 'env', 'command', 'cores', 'vmem', 'sockname'}
script_args = {'label', 'queue', 'cores', 'vmem' 'realtime', 'output_path', 'project_path', 'sockname', 'env', 'command', }
script_template = \
"""\
#!/bin/bash
Expand All @@ -165,3 +165,102 @@ class SGESubmitSOCK(SGESubmit):
runtk.SOCKET: '{sockname}'
}

class SlurmSubmit(Submit):
script_args = {'label', 'allocation', 'walltime', 'nodes', 'coresPerNode', 'output_path', 'email', 'reservation', 'custom', 'project_path', 'command'}
script_template = \
"""\
#SBATCH --job-name={label}
#SBATCH -A {allocation}
#SBATCH -t {walltime}
#SBATCH --nodes={nodes}
#SBATCH --ntasks-per-node={coresPerNode}
#SBATCH -o {output_path}/{label}.run
#SBATCH -e {output_path}/{label}.err
#SBATCH --mail-user={email}
#SBATCH --mail-type=end
export JOBID=$SLURM_JOB_ID
{res}
{custom}
source ~/.bashrc
cd {project_path}
{command}
wait
"""
script_handles = {runtk.SUBMIT: '{output_path}/{label}.sh',
runtk.STDOUT: '{output_path}/{label}.run'}
def __init__(self, **kwargs):
super().__init__(
submit_template = Template(template="sbatch {output_path}/{label}.sh",
key_args={'output_path', 'label'}),
script_template = Template(template=self.script_template,
key_args=self.script_args),
handles = self.script_handles,
)

def submit_job(self, **kwargs):
proc = super().submit_job()
self.job_id = 0 #TODO, what is the output of an sbatch command?
return self.job_id
#validate job id
#try:
# self.job_id = proc.stdout.split(' ')[2]
#except Exception as e: #not quite sure how this would occur
# raise(Exception("{}\nJob submission failed:\n{}\n{}\n{}\n{}".format(e, self.submit, self.script, proc.stdout, proc.stderr)))
#return self.job_id

def set_handles(self):
pass

class SlurmSubmitSFS(SlurmSubmit):
script_args = {'label', 'allocation', 'walltime', 'nodes', 'coresPerNode', 'output_path', 'email', 'custom', 'project_path', 'command'}
script_template = \
"""\
#SBATCH --job-name={label}
#SBATCH -A {allocation}
#SBATCH -t {walltime}
#SBATCH --nodes={nodes}
#SBATCH --ntasks-per-node={coresPerNode}
#SBATCH -o {output_path}/{label}.run
#SBATCH -e {output_path}/{label}.err
#SBATCH --mail-user={email}
#SBATCH --mail-type=end
export JOBID=$SLURM_JOB_ID
export OUTFILE="{output_path}/{label}.out"
export SGLFILE="{output_path}/{label}.sgl"
{custom}
source ~/.bashrc
cd {project_path}
{command}
wait
"""
script_handles = {runtk.SUBMIT: '{output_path}/{label}.sh',
runtk.STDOUT: '{output_path}/{label}.run',
runtk.MSGOUT: '{output_path}/{label}.out',
runtk.SGLOUT: '{output_path}/{label}.sgl',
}

class SlurmSubmitSFS(SlurmSubmit):
script_args = {'label', 'allocation', 'walltime', 'nodes', 'coresPerNode', 'output_path', 'email', 'reservation', 'custom', 'project_path', 'command'}
script_template = \
"""\
#SBATCH --job-name={label}
#SBATCH -A {allocation}
#SBATCH -t {walltime}
#SBATCH --nodes={nodes}
#SBATCH --ntasks-per-node={coresPerNode}
#SBATCH -o {output_path}/{label}.run
#SBATCH -e {output_path}/{label}.err
#SBATCH --mail-user={email}
#SBATCH --mail-type=end
export JOBID=$SLURM_JOB_ID
export SOCNAME="{sockname}"
{custom}
source ~/.bashrc
cd {project_path}
{command}
wait
"""
script_handles = {runtk.SUBMIT: '{output_path}/{label}.sh',
runtk.STDOUT: '{output_path}/{label}.run',
runtk.SOCKET: '{sockname}'
}
Loading