Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Add job modfile #1019

Merged
merged 11 commits into from
Oct 27, 2021
Merged
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
18 changes: 11 additions & 7 deletions docs/Subcommand/Job.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
Shell:

~~~
host% gridlabd job [-v|--verbose] [-q|--quiet] [-d|--debug] [-j|--jobfile JOBFILE] [-w|--workdir FOLDER] [-c|--configfile CONFIG] [-T|--threadcount NTHREADS] FILE1 ...
host% gridlabd job [-v|--verbose] [-q|--quiet] [-d|--debug] [-j|--jobfile JOBFILE] [-w|--workdir FOLDER] [-c|--configfile CONFIG] [-m|--modifyfile MODIFY] [-T|--threadcount NTHREADS] FILE1 ...
~~~

GLM:

~~~
#job [-v|--verbose] [-q|--quiet] [-d|--debug] [-j|--jobfile JOBFILE] [-w|--workdir FOLDER] [-c|--configfile CONFIG] [-T|--threadcount NTHREADS] FILE1 ...
#job [-v|--verbose] [-q|--quiet] [-d|--debug] [-j|--jobfile JOBFILE] [-w|--workdir FOLDER] [-c|--configfile CONFIG] [-m|--modifyfile MODIFY] [-T|--threadcount NTHREADS] FILE1 ...
~~~

# Description
Expand All @@ -26,24 +26,28 @@ The default configuration file name is `gridlabd-config.glm`.

### `-c|--configfile CONFIG`

Specifies the name of the configuration file to use instead of `gridlabd-config.glm`.
Specifies the name of the configuration file name to use instead of `gridlabd-config.glm`. The configuration file is created from the job entry in the job control file and loaded before the main GLM file is loaded.

### `-d|--debug`

Enables debugging output.

### `-T|--threadpool NTHREADS`

Enables parallel processing of jobs using a threadpool using the specified number of threads.

### `-j|--jobfile JOBFILE`

Specifies the name of the job control file to use instead of `gridlabd-job.csv`.

### `-m|--modifyfile MODIFY`

Specifies the name of the modify file to use instead of `gridlabd-modify.glm`. The modification file is loaded after the main GLM file is loaded.

### `-q|--quiet`

Disables all but error output.

### `-T|--threadpool NTHREADS`

Enables parallel processing of jobs using a threadpool using the specified number of threads.

### `-v|--verbose`

Enable additional output (useful to diagnose problem).
Expand Down
7 changes: 7 additions & 0 deletions gldcore/scripts/autotest/job-clock.glm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
clock
{
starttime "2020-01-01 00:00:00";
stoptime "2021-01-01 00:00:00";
}
#set suppress_repeat_messages=FALSE
#print clock modified in ${modelname}
8 changes: 8 additions & 0 deletions gldcore/scripts/autotest/test_job_modfile.glm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef TEST1
#ifexist ../gridlabd-job.csv
#define TESTDIR=..
#endif
#job -T 0 ${modelname} -j ${TESTDIR:-.}/gridlabd-job.csv -m ${TESTDIR:-.}/job-clock.glm
#else
#print TEST ${TEST1}: ${TEST2},${TEST3},${TEST4}
#endif
8 changes: 8 additions & 0 deletions gldcore/scripts/autotest/test_job_modfile_err.glm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef TEST1
#ifexist ../gridlabd-job.csv
#define TESTDIR=..
#endif
#job -T 0 ${modelname} -j ${TESTDIR:-.}/gridlabd-job.csv -m ${TESTDIR:-.}/not-found.glm
#else
#print TEST ${TEST1}: ${TEST2},${TEST3},${TEST4}
#endif
20 changes: 16 additions & 4 deletions gldcore/scripts/gridlabd-job
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import subprocess
from multiprocessing import pool, freeze_support
import curses

SYNTAX="Syntax: gridlabd job [-v|--verbose] [-q|--quiet] [-d|--debug] [-j|--jobfile JOBFILE] [-w|--workdir FOLDER] [-c|--configfile CONFIG] [-T|--threadcount NTHREADS] FILE1 ..."
SYNTAX="Syntax: gridlabd job [-v|--verbose] [-q|--quiet] [-d|--debug] [-j|--jobfile JOBFILE] [-w|--workdir FOLDER] [-c|--configfile CONFIG] [-m|--modifyfile MODIFY] [-T|--threadcount NTHREADS] FILE1 ..."
VERBOSE=False
DEBUG=False
QUIET=False
DEBUG=False
JOBFILE="gridlabd-job.csv"
CFGFILE="gridlabd-config.glm"
MODFILE="gridlabd-modify.glm"
WORKDIR=os.getcwd()
THREADS=1
JOBPOOL=None
Expand Down Expand Up @@ -58,6 +59,10 @@ def runjob(jobid):
print(f"#define {var}={value}",file=cfg)
args = ["gridlabd",cfgfile]
args.extend(GLMLIST)
if os.path.exists(MODFILE):
args.append(MODFILE)
elif MODFILE != "gridlabd-modify.glm":
error(f"{MODFILE} does not exist")
verbose(f"running '{' '.join(args)}'")
result = subprocess.run(args,capture_output=True,encoding="utf-8")
if result.stdout:
Expand All @@ -66,7 +71,7 @@ def runjob(jobid):
error(None,result.stderr.strip())
return result

def initializer(verbose,debug,quiet,jobfile,cfgfile,workdir,glmlist,jobdata):
def initializer(verbose,debug,quiet,jobfile,cfgfile,modfile,workdir,glmlist,jobdata):
global VERBOSE
VERBOSE = verbose
global DEBUG
Expand All @@ -77,6 +82,8 @@ def initializer(verbose,debug,quiet,jobfile,cfgfile,workdir,glmlist,jobdata):
JOBFILE = jobfile
global CFGFILE
CFGFILE = cfgfile
global MODFILE
MODFILE = modfile
global WORKDIR
WORKDIR = workdir
global GLMLIST
Expand Down Expand Up @@ -105,11 +112,15 @@ if __name__ == "__main__":
elif sys.argv[n] in ["-j","--jobfile"]:
n+=1
JOBFILE=sys.argv[n]
verbose(f"using control file {CFGFILE}")
verbose(f"using control file {JOBFILE}")
elif sys.argv[n] in ["-c","--configfile"]:
n+=1
CFGFILE=sys.argv[n]
verbose(f"using GLM file {GLMFILE}")
verbose(f"using GLM configuration file {CFGFILE}")
elif sys.argv[n] in ["-m","--modifyfile"]:
n+=1
MODFILE=sys.argv[n]
verbose(f"using GLM modify file {MODFILE}")
elif sys.argv[n] in ["-w","--workdir"]:
n+=1
WORKDIR=sys.argv[n]
Expand Down Expand Up @@ -138,6 +149,7 @@ if __name__ == "__main__":
QUIET,
JOBFILE,
CFGFILE,
MODFILE,
WORKDIR,
GLMLIST,
JOBDATA,
Expand Down
5 changes: 3 additions & 2 deletions gldcore/scripts/gridlabd-version
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ function version-check()
branch=$(${BIN} --version=git-branch)
remote=$( (curl -sL "https://raw.githubusercontent.com/slacgismo/gridlabd/$branch/gldcore/version.h" | grep '#define REV_' | cut -f3 -d' ' | tr '\n' . | cut -f-3 -d.) || echo "none" )
if [ "$remote" == "none" -o -z "$remote" ]; then
[ "$1" != "-q" ] && error 2 "$version ($branch) remote not found"
exit 2
[ "$1" != "-q" -a "$1" != "-w" ] && error 2 "$version ($branch) remote not found"
[ "$1" != "-q" ] && warning "$version ($branch) remote not found"
exit 0
fi
[ "$1" == "-v" ] && echo "REMOTE/$branch $remote"
${BIN} --version="-ge $remote" 2>/dev/null || ( ( [ "$1" != "-q" ] && error 1 "$version ($branch) is outdated" ) ; exit 1 )
Expand Down