<commit_before>import os
import tempfile

import simulation.constants
import simulation.model.constants
import simulation.model.options
import simulation.optimization.constants

import measurements.constants

import util.batch.universal.system
import util.io.env

import util.logging


class CostFunctionJob(util.batch.universal.system.Job):

    def __init__(self, cf_kind, model_options, output_dir=None, model_job_options=None, min_standard_deviations=None, min_measurements_correlations=None, max_box_distance_to_water=None, eval_f=True, eval_df=True, cost_function_job_options=None, include_initial_concentrations_factor_by_default=False):
        util.logging.debug('Initiating cost function job with cf_kind {}, eval_f {} and eval_df {}.'.format(cf_kind, eval_f, eval_df))

        # if no output dir, use tmp output dir
        remove_output_dir_on_close = output_dir is None
        if output_dir is None:
            output_dir = simulation.model.constants.DATABASE_TMP_DIR
            os.makedirs(output_dir, exist_ok=True)
            output_dir = tempfile.mkdtemp(dir=output_dir, prefix='cost_function_tmp_')

        # init job object
        super().__init__(output_dir, remove_output_dir_on_close=remove_output_dir_on_close)

        # convert model options
        model_options = simulation.model.options.as_model_options(model_options)

        # save CF options
        self.options['/cf/kind'] = cf_kind
        self.options['/cf/model_options'] = repr(model_options)
        self.options['/cf/model_job_options'] = repr(model_job_options)
        self.options['/cf/max_box_distance_to_water'] = max_box_distance_to_water
        self.options['/cf/min_standard_deviations'] = min_standard_deviations
        self.options['/cf/min_measurements_correlations'] = min_measurements_correlations
        self.options['/cf/include_initial_concentrations_factor_by_default'] = include_initial_concentrations_factor_by_default

        # prepare job options
        if cost_function_job_options is None:
            cost_function_job_options = {}

        # prepare job name
        try:
            job_name = cost_function_job_options['name']
        except KeyError:
            job_name = cf_kind
            if cf_kind == 'GLS':
                job_name = job_name + '_{min_measurements_correlations}'.format(min_measurements_correlations=min_measurements_correlations)
            job_name = job_name + '_' + model_options.model_name
            if max_box_distance_to_water is not None and max_box_distance_to_water != float('inf'):
                job_name = job_name + '_N{max_box_distance_to_water:d}'.format(max_box_distance_to_water=max_box_distance_to_water)
<commit_msg>MAINT: simulation.optimization.job: time step added to default job name<commit_after>import os
import tempfile

import simulation.constants
import simulation.model.constants
import simulation.model.options
import simulation.optimization.constants

import measurements.constants

import util.batch.universal.system
import util.io.env

import util.logging


class CostFunctionJob(util.batch.universal.system.Job):

    def __init__(self, cf_kind, model_options, output_dir=None, model_job_options=None, min_standard_deviations=None, min_measurements_correlations=None, max_box_distance_to_water=None, eval_f=True, eval_df=True, cost_function_job_options=None, include_initial_concentrations_factor_by_default=False):
        util.logging.debug('Initiating cost function job with cf_kind {}, eval_f {} and eval_df {}.'.format(cf_kind, eval_f, eval_df))

        # if no output dir, use tmp output dir
        remove_output_dir_on_close = output_dir is None
        if output_dir is None:
            output_dir = simulation.model.constants.DATABASE_TMP_DIR
            os.makedirs(output_dir, exist_ok=True)
            output_dir = tempfile.mkdtemp(dir=output_dir, prefix='cost_function_tmp_')

        # init job object
        super().__init__(output_dir, remove_output_dir_on_close=remove_output_dir_on_close)

        # convert model options
        model_options = simulation.model.options.as_model_options(model_options)

        # save CF options
        self.options['/cf/kind'] = cf_kind
        self.options['/cf/model_options'] = repr(model_options)
        self.options['/cf/model_job_options'] = repr(model_job_options)
        self.options['/cf/max_box_distance_to_water'] = max_box_distance_to_water
        self.options['/cf/min_standard_deviations'] = min_standard_deviations
        self.options['/cf/min_measurements_correlations'] = min_measurements_correlations
        self.options['/cf/include_initial_concentrations_factor_by_default'] = include_initial_concentrations_factor_by_default

        # prepare job options
        if cost_function_job_options is None:
            cost_function_job_options = {}

        # prepare job name
        try:
            job_name = cost_function_job_options['name']
        except KeyError:
            job_name = cf_kind
            if cf_kind == 'GLS':
                job_name = job_name + '_{min_measurements_correlations}'.format(min_measurements_correlations=min_measurements_correlations)
            job_name = job_name + '_' + model_options.model_name + '_' + str(model_options.time_step)
            if max_box_distance_to_water is not None and max_box_distance_to_water != float('inf'):
                job_name = job_name + '_N{max_box_distance_to_water:d}'.format(max_box_distance_to_water=max_box_distance_to_water)

{'fraction_non_alphanumeric': 0.08110078367049389, 'fraction_numerical': 0.0, 'mean_word_length': 3.935251798561151, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '753001', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1636, 'n_words': 279}