Skip to content

Commit

Permalink
Merge pull request #112 from UCL-CCS/dev
Browse files Browse the repository at this point in the history
Pre-release version
  • Loading branch information
dww100 authored Jun 7, 2019
2 parents 537b37b + 80604e0 commit 7bdc897
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
3 changes: 2 additions & 1 deletion docs/tutorial_files/gauss_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@

# 8. Run Application
# - gauss is executed for each sample
my_campaign.apply_for_each_run_dir(uq.actions.ExecuteLocal(cmd))
my_campaign.apply_for_each_run_dir(uq.actions.ExecuteLocal(cmd,
interpret='python3'))

# 9. Collate output
my_campaign.collate()
Expand Down
10 changes: 8 additions & 2 deletions easyvvuq/actions/execute_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class ExecuteLocal(BaseAction):

def __init__(self, run_cmd):
def __init__(self, run_cmd, interpret=None):
"""
Provides an action element to run a shell command in a specified
directory.
Expand All @@ -43,6 +43,8 @@ def __init__(self, run_cmd):
run_cmd : str
Command to execute.
interpret : str or None
Interpreter to use to execute cmd.
"""

Expand All @@ -54,6 +56,7 @@ def __init__(self, run_cmd):

# Need to expand users, get absolute path and dereference symlinks
self.run_cmd = os.path.realpath(os.path.expanduser(run_cmd))
self.interpreter = interpret

def act_on_dir(self, target_dir):
"""
Expand All @@ -64,7 +67,10 @@ def act_on_dir(self, target_dir):
"""

full_cmd = f'cd {target_dir}\n{self.run_cmd}\n'
if self.interpreter is None:
full_cmd = f'cd {target_dir}\n{self.run_cmd}\n'
else:
full_cmd = f'cd {target_dir}\n{self.interpreter} {self.run_cmd}\n'
result = os.system(full_cmd)
if result != 0:
sys.exit(f'Non-zero exit code from command "{full_cmd}"\n')
29 changes: 15 additions & 14 deletions easyvvuq/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import logging
import tempfile
import json
import easyvvuq as uq
from easyvvuq import constants
from easyvvuq.constants import default_campaign_prefix
from easyvvuq.data_structs import RunInfo
import easyvvuq
from easyvvuq.constants import default_campaign_prefix, Status
from easyvvuq.data_structs import RunInfo, CampaignInfo, AppInfo
from easyvvuq.sampling import BaseSamplingElement
from easyvvuq.collate import BaseCollationElement

__copyright__ = """
Expand Down Expand Up @@ -188,10 +189,10 @@ def init_fresh(self, name, db_type='sql',
logger.critical(message)
raise RuntimeError(message)

info = uq.data_structs.CampaignInfo(
info = CampaignInfo(
name=name,
campaign_dir_prefix=default_campaign_prefix,
easyvvuq_version=uq.__version__,
easyvvuq_version=easyvvuq.__version__,
campaign_dir=self.campaign_dir)
self.campaign_db = CampaignDB(location=self.db_location,
new_campaign=True,
Expand Down Expand Up @@ -364,7 +365,7 @@ def add_app(self, name=None, params=None, fixtures=None,
raise Exception(msg)

# validate application input
app = uq.data_structs.AppInfo(
app = AppInfo(
name=name,
params=params,
fixtures=fixtures,
Expand Down Expand Up @@ -411,7 +412,7 @@ def set_sampler(self, sampler):
-------
"""
if not isinstance(sampler, uq.sampling.BaseSamplingElement):
if not isinstance(sampler, BaseSamplingElement):
msg = "set_sampler() must be passed a sampling element"
logging.error(msg)
raise Exception(msg)
Expand All @@ -431,7 +432,7 @@ def set_collater(self, collater):
-------
"""
if not isinstance(collater, uq.collate.BaseCollationElement):
if not isinstance(collater, BaseCollationElement):
msg = "set_collater() must be passed a collation element"
logging.error(msg)
raise Exception(msg)
Expand Down Expand Up @@ -572,7 +573,7 @@ def scan_completed(self, *args, **kwargs):
-------
"""
return self.list_runs(status=uq.constants.Status.COLLATED)
return self.list_runs(status=Status.COLLATED)

def all_complete(self):
"""
Expand All @@ -584,7 +585,7 @@ def all_complete(self):
"""

num = self.campaign_db.get_num_runs(not_status=constants.Status.COLLATED)
num = self.campaign_db.get_num_runs(not_status=Status.COLLATED)
if num == 0:
return True
return False
Expand Down Expand Up @@ -614,7 +615,7 @@ def populate_runs_dir(self):
runs_dir = self.campaign_db.runs_dir()

# Loop through all runs with status NEW
for run_id, run_data in self.campaign_db.runs(status=constants.Status.NEW):
for run_id, run_data in self.campaign_db.runs(status=Status.NEW):

# Make run directory
target_dir = os.path.join(runs_dir, run_id)
Expand All @@ -632,7 +633,7 @@ def populate_runs_dir(self):
active_encoder.encode(params=run_data['params'],
target_dir=target_dir)

self.campaign_db.set_run_statuses([run_id], constants.Status.ENCODED)
self.campaign_db.set_run_statuses([run_id], Status.ENCODED)

def get_campaign_runs_dir(self):
"""Get the runs directory from the CampaignDB.
Expand Down Expand Up @@ -663,7 +664,7 @@ def apply_for_each_run_dir(self, action):
runs_dir = self.campaign_db.runs_dir()

# Loop through all runs in this campaign with status ENCODED
for run_id, run_data in self.campaign_db.runs(status=constants.Status.ENCODED):
for run_id, run_data in self.campaign_db.runs(status=Status.ENCODED):

dir_name = os.path.join(runs_dir, run_id)
print("Applying " + action.__module__ + " to " + dir_name + "...")
Expand Down
2 changes: 1 addition & 1 deletion easyvvuq/collate/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .. import BaseElement
from easyvvuq.base_element import BaseElement
import json
import logging

Expand Down
7 changes: 4 additions & 3 deletions easyvvuq/data_structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import os
import logging
import json
import easyvvuq as uq
from easyvvuq import constants
from easyvvuq.encoders import BaseEncoder
from easyvvuq.decoders import BaseDecoder

__copyright__ = """
Expand Down Expand Up @@ -235,7 +236,7 @@ def input_encoder(self):

@input_encoder.setter
def input_encoder(self, encoder):
if not isinstance(encoder, uq.encoders.BaseEncoder):
if not isinstance(encoder, BaseEncoder):
msg = f"Provided 'encoder' must be derived from type BaseEncoder"
logger.error(msg)
raise Exception(msg)
Expand All @@ -248,7 +249,7 @@ def output_decoder(self):

@output_decoder.setter
def output_decoder(self, decoder):
if not isinstance(decoder, uq.decoders.BaseDecoder):
if not isinstance(decoder, BaseDecoder):
msg = f"Provided 'decoder' must be derived from type BaseDecoder"
logger.error(msg)
raise Exception(msg)
Expand Down
2 changes: 1 addition & 1 deletion easyvvuq/sampling/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .. import BaseElement
from easyvvuq.base_element import BaseElement
import logging
import json
import jsonpickle
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

author='CCS',

install_requires=['numpy', 'pandas', 'pytest', 'SQLAlchemy', 'chaospy',
install_requires=['numpy', 'pandas>=0.24', 'scipy==1.2.1',
'pytest', 'SQLAlchemy', 'chaospy',
'sqlalchemy-utils', 'matplotlib', 'jsonpickle'],

packages=find_packages(),
Expand Down

0 comments on commit 7bdc897

Please sign in to comment.