-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from rosswhitfield/dakota
Get IPS dakota working again
- Loading branch information
Showing
11 changed files
with
251 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ omit = | |
*/configobj.py | ||
*/six.py | ||
*/_version.py | ||
*/*dakota* | ||
*/utils/HTML.py | ||
|
||
[versioneer] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
To run this test manually do: | ||
ips_dakota_dynamic.py --dakotaconfig=dakota_test_Rosenbrock.in --simulation=dakota_test_Rosenbrock.ips --platform=workstation.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# DAKOTA INPUT FILE - dakota_rosenbrock_syscall.in | ||
|
||
strategy | ||
single_method | ||
graphics | ||
tabular_graphics_data | ||
|
||
method | ||
conmin_frcg | ||
max_iterations = 100 | ||
convergence_tolerance = 1e-4 | ||
speculative | ||
|
||
model | ||
single | ||
|
||
variables | ||
continuous_design = 2 | ||
initial_point 0.5 1.0 | ||
lower_bounds 0.0 0.0 | ||
upper_bounds 2.0 2.0 | ||
descriptors 'ROSE__X1' "ROSE__X2" | ||
|
||
interface | ||
fork asynchronous evaluation_concurrency = 10, file_tag, file_save | ||
analysis_driver = 'ips_dakota_client.py' | ||
parameters_file = 'params.in' | ||
results_file = 'results.out' | ||
|
||
responses | ||
num_objective_functions = 1 | ||
numerical_gradients | ||
method_source dakota | ||
interval_type forward | ||
fd_gradient_step_size = 1.e-5 | ||
no_hessians |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
RUN_ID = DAKOTA_Rosenbrock # Identifier for this simulation run | ||
TOKAMAK_ID = TEST | ||
SHOT_NUMBER = 1 # Numerical identifier for specific case | ||
|
||
SIM_NAME = ${RUN_ID}_${TOKAMAK_ID}_${SHOT_NUMBER} # Name of current simulation | ||
SIM_ROOT = $PWD/${SIM_NAME} # Where to put results from this simulation | ||
|
||
LOG_FILE = $SIM_ROOT/${RUN_ID}.log | ||
LOG_LEVEL = DEBUG | ||
|
||
SIMULATION_MODE = NORMAL | ||
|
||
# A run comment picked up by the portal | ||
RUN_COMMENT = Testing dakota | ||
|
||
# Specification of plasma state files | ||
|
||
# Where to put plasma state files as the simulation evolves | ||
PLASMA_STATE_WORK_DIR = $SIM_ROOT/work/plasma_state | ||
|
||
# Specify what files constitute the plasma state - N.B. not all components need all files | ||
PLASMA_STATE_FILES = | ||
|
||
# Names of ports to be used. An implementation and configuration must be specified for | ||
# each port | ||
|
||
[PORTS] | ||
NAMES = DRIVER | ||
|
||
# DRIVER port is called by the framework. It is required, causes exception. | ||
|
||
[[DRIVER]] # REQUIRED Port section | ||
IMPLEMENTATION = ROSE | ||
|
||
# INIT port is called by the framework. It typically produces the very first set of | ||
# plasma state files for SIMULATION_MODE = NORMAL. It does not raise and exception | ||
# if missing. | ||
|
||
[[INIT]] | ||
IMPLEMENTATION = | ||
|
||
# Specification of IMPLEMENTATION for each physics port called out in PORTS list. | ||
# Additional specifications may be present that are not in the PORTS list | ||
|
||
# Specification of configuration for each port called out in PORTS list. | ||
# Additional specifications may be present that are not in the PORTS list | ||
# NAME variable MUST match the name of the python class that implements the component | ||
|
||
[ROSE] | ||
CLASS = DAKOTA | ||
SUB_CLASS = TEST | ||
NAME = ResenbrockDriver | ||
NPROC = 1 | ||
BIN_PATH = | ||
INPUT_DIR = | ||
INPUT_FILES = | ||
OUTPUT_FILES = | ||
SCRIPT = $PWD/dakota_test_Rosenbrock.py | ||
|
||
# Time loop specification (two modes for now) EXPLICIT | REGULAR | ||
# For MODE = REGULAR, the framework uses the variables START, FINISH, and NSTEP | ||
# For MODE = EXPLICIT, the frame work uses the variable VALUES (space separated list of time values) | ||
|
||
[TIME_LOOP] | ||
MODE = REGULAR | ||
START = 0 | ||
FINISH = 10 | ||
NSTEP = 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Copyright 2006-2012 UT-Battelle, LLC. See LICENSE for more information. | ||
# ------------------------------------------------------------------------------- | ||
import os | ||
from ipsframework import Component | ||
|
||
|
||
class ResenbrockDriver(Component): | ||
|
||
def __init__(self, services, config): | ||
Component.__init__(self, services, config) | ||
|
||
def init(self, timestamp=0): | ||
print('init from dakota test driver') | ||
|
||
def step(self, timestamp=0): | ||
print('step from dakota test driver') | ||
services = self.services | ||
services.stage_input_files(self.INPUT_FILES) | ||
x1 = float(self.X1) | ||
x2 = float(self.X2) | ||
sim_root = services.get_config_param('SIM_ROOT') | ||
result = 100.0 * (x2 - x1 * x1) * (x2 - x1 * x1) + (1. - x1) * (1. - x1) | ||
out_file = os.path.join(sim_root, 'RESULT') | ||
open(out_file, 'w').write('%.9f f' % (result)) | ||
return | ||
|
||
def finalize(self, timestamp=0): | ||
print('finalize from dakota test driver') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from ipsframework.ips_dakota_dynamic import DakotaDynamic | ||
import os | ||
import shutil | ||
import pytest | ||
import glob | ||
|
||
|
||
def copy_config_and_replace(infile, outfile, tmpdir): | ||
with open(infile, "r") as fin: | ||
with open(outfile, "w") as fout: | ||
for line in fin: | ||
if "SCRIPT" in line: | ||
fout.write(line.replace("$PWD", str(tmpdir))) | ||
elif line.startswith("SIM_ROOT"): | ||
fout.write(f"SIM_ROOT = {tmpdir}/$SIM_NAME\n") | ||
else: | ||
fout.write(line) | ||
|
||
|
||
@pytest.mark.skipif(shutil.which('dakota') is None, | ||
reason="Requires dakota to run this test") | ||
def test_dakota(tmpdir): | ||
data_dir = os.path.dirname(__file__) | ||
copy_config_and_replace(os.path.join(data_dir, "dakota_test_Rosenbrock.ips"), tmpdir.join("dakota_test_Rosenbrock.ips"), tmpdir) | ||
shutil.copy(os.path.join(data_dir, "workstation.conf"), tmpdir) | ||
shutil.copy(os.path.join(data_dir, "dakota_test_Rosenbrock.in"), tmpdir) | ||
shutil.copy(os.path.join(data_dir, "dakota_test_Rosenbrock.py"), tmpdir) | ||
|
||
os.chdir(tmpdir) | ||
|
||
sweep = DakotaDynamic(dakota_cfg=os.path.join(tmpdir, "dakota_test_Rosenbrock.in"), | ||
log_file=str(tmpdir.join('test.log')), | ||
platform_filename=os.path.join(tmpdir, "workstation.conf"), | ||
debug=False, | ||
ips_config_template=os.path.join(tmpdir, "dakota_test_Rosenbrock.ips"), | ||
restart_file=None) | ||
sweep.run() | ||
|
||
# check dakota log | ||
log_file = glob.glob(str(tmpdir.join("dakota_*.log")))[0] | ||
with open(log_file, 'r') as f: | ||
lines = f.readlines() | ||
|
||
X1, X2 = lines[-22].split()[1:] | ||
|
||
assert float(X1) == pytest.approx(1, rel=1e-3) | ||
assert float(X2) == pytest.approx(1, rel=1e-3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
HOST = my_laptop | ||
MPIRUN = eval | ||
|
||
####################################### | ||
# resource detection method | ||
####################################### | ||
NODE_DETECTION = manual # checkjob | qstat | pbs_env | slurm_env | ||
|
||
####################################### | ||
# manual allocation description | ||
####################################### | ||
TOTAL_PROCS = 2 | ||
NODES = 1 | ||
PROCS_PER_NODE = 2 | ||
|
||
####################################### | ||
# node topology description | ||
####################################### | ||
CORES_PER_NODE = 2 | ||
SOCKETS_PER_NODE = 1 | ||
|
||
####################################### | ||
# framework setting for node allocation | ||
####################################### | ||
# MUST ADHERE TO THE PLATFORM'S CAPABILITIES | ||
# * EXCLUSIVE : only one task per node | ||
# * SHARED : multiple tasks may share a node | ||
# For single node jobs, this can be overridden allowing multiple | ||
# tasks per node. | ||
NODE_ALLOCATION_MODE = SHARED # SHARED | EXCLUSIVE |