Skip to content
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
8 changes: 8 additions & 0 deletions docs/config_keys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ Output Options

Example:
* ``output_every = 1000``

**save_best_data**
If 1, run an extra simulation at the end of fitting using the best-fit parameters, and save the best-fit .gdat and .scan files to the Results directory.

Default: 0

Example:
* ``save_best_data = 1``

**verbosity**
An integer value that specifies the amount of information output to the terminal.
Expand Down
27 changes: 26 additions & 1 deletion pybnf/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .pset import PSet
from .pset import Trajectory

from .pset import NetModel, BNGLModel
from .pset import NetModel, BNGLModel, SbmlModelNoTimeout
from .pset import OutOfBoundsException
from .pset import FailedSimulationError
from .printing import print0, print1, print2, PybnfError
Expand All @@ -29,6 +29,7 @@
import sys
import traceback
import pickle
from glob import glob


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -849,6 +850,30 @@ def run(self, log_prefix, scheduler_node=None, resume=None, debug=False):
logger.error('Cannot find files corresponding to best fit parameter set')
print0('Could not find your best fit gdat file. This could happen if all of the simulations\n'
' in your run failed, or if that gdat file was somehow deleted during the run.')
if self.config.config['delete_old_files'] > 0 and self.config.config['save_best_data']:
# Rerun the best fit parameter set so the gdat file(s) are saved in the Results folder.
logger.info('Rerunning best fit parameter set to save data files.')
# Enable saving files for SBML models
for m in self.model_list:
if isinstance(m, SbmlModelNoTimeout):
m.save_files = True
finaljob = Job(self.model_list, best_pset, 'bestfit',
self.sim_dir, self.config.config['wall_time_sim'], None,
self.config.config['normalization'], self.config.postprocessing,
False)
try:
run_job(finaljob)
except Exception:
logger.exception('Failed to rerun best fit parameter set')
print1('Failed to rerun best fit parameter set. See log for details')
else:
# Copy all gdat and scan to Results
for fname in glob(self.sim_dir+'/bestfit/*.gdat') + glob(self.sim_dir+'/bestfit/*.scan'):
shutil.copy(fname, self.res_dir)
# Disable saving files for SBML models (in case there is future bootstrapping or refinement)
for m in self.model_list:
if isinstance(m, SbmlModelNoTimeout):
m.save_files = False

try:
os.rename('%s/alg_backup.bp' % self.config.config['output_dir'],
Expand Down
2 changes: 1 addition & 1 deletion pybnf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def default_config():
'output_every': 20, 'initialization': 'lh', 'refine': 0, 'bng_command': bng_command, 'smoothing': 1,
'backup_every': 1, 'time_course': (), 'param_scan': (), 'min_objective': -np.inf, 'bootstrap': 0,
'bootstrap_max_obj': None, 'ind_var_rounding': 0, 'local_objective_eval': 0, 'constraint_scale': 1.0,
'sbml_integrator': 'cvode', 'parallel_count': None,
'sbml_integrator': 'cvode', 'parallel_count': None, 'save_best_data': 0,

'mutation_rate': 0.5, 'mutation_factor': 0.5, 'islands': 1, 'migrate_every': 20, 'num_to_migrate': 3,
'stop_tolerance': 0.002, 'de_strategy': 'rand1',
Expand Down
2 changes: 1 addition & 1 deletion pybnf/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'local_min_limit', 'reserve_size', 'burn_in', 'sample_every', 'output_hist_every',
'hist_bins', 'refine', 'simplex_max_iterations', 'wall_time_sim', 'wall_time_gen', 'verbosity',
'exchange_every', 'backup_every', 'bootstrap', 'crossover_number', 'ind_var_rounding',
'local_objective_eval', 'reps_per_beta']
'local_objective_eval', 'reps_per_beta', 'save_best_data']
numkeys_float = ['extra_weight', 'swap_rate', 'min_objective', 'cognitive', 'social', 'particle_weight',
'particle_weight_final', 'adaptive_n_max', 'adaptive_n_stop', 'adaptive_abs_tol', 'adaptive_rel_tol',
'mutation_rate', 'mutation_factor', 'stop_tolerance', 'step_size', 'simplex_step', 'simplex_log_step',
Expand Down