<commit_before>#!/usr/bin/env python
"""Defines the `dakota_run_component` console script."""

import os
import shutil
import subprocess
import importlib
import numpy as np
from .utils import (get_configuration_file, deserialize,
                    compute_statistic, write_results, to_iterable)


component_script = 'dakota_run_component'


class ComponentOutput(object):

    """Stores component output variables for processing by Dakota."""

    def __init__(self, component, var_names):
        self.component = component
        self.var_names = to_iterable(var_names)
        for var in self.var_names:
            setattr(self, var, [])

    def update(self):
        for var in self.var_names:
            attr = getattr(self, var)
            attr.append(self.component.get_value(var))

    def get_value(self, var):
        return getattr(self, var)


class RunComponent(object):

    """Provides framework to run a CSDMS component from Dakota."""

    component_path = 'pymt.components'

    def __init__(self, params_file, results_file):
        self.params_file = params_file
        self.results_file = results_file
        self.component = None
        self.input_file = None
        self.n_responses = 0
        self.output = None
        self.results = []

        config_file = get_configuration_file(self.params_file)
        self.config = deserialize(config_file)

    def create_component(self):
        module = importlib.import_module(self.component_path)
        cls = getattr(module, self.config['component'])
        self.component = cls()

    def setup(self):
        self.input_file, _ = os.path.splitext(self.config['template_file'])
        subprocess.call(['dprepro', self.params_file,
                         self.config['template_file'],
                         self.input_file])
        shutil.copy(self.input_file, os.getcwd())
        self.n_responses = len(self.config['response_descriptors'])
        self.output = ComponentOutput(self.component,
                                      self.config['response_descriptors'])

    def run(self):
        self.component.initialize(self.input_file)
        while self.component.get_current_time() < self.component.get_end_time():
            self.component.update()
            self.output.update()
        self.component.finalize()

    def calculate(self):<commit_msg>Fix problem with leftover model config file<commit_after>#!/usr/bin/env python
"""Defines the `dakota_run_component` console script."""

import os
import shutil
import subprocess
import importlib
import numpy as np
from .utils import (get_configuration_file, deserialize,
                    compute_statistic, write_results, to_iterable)


component_script = 'dakota_run_component'


class ComponentOutput(object):

    """Stores component output variables for processing by Dakota."""

    def __init__(self, component, var_names):
        self.component = component
        self.var_names = to_iterable(var_names)
        for var in self.var_names:
            setattr(self, var, [])

    def update(self):
        for var in self.var_names:
            attr = getattr(self, var)
            attr.append(self.component.get_value(var))

    def get_value(self, var):
        return getattr(self, var)


class RunComponent(object):

    """Provides framework to run a CSDMS component from Dakota."""

    component_path = 'pymt.components'

    def __init__(self, params_file, results_file):
        self.params_file = params_file
        self.results_file = results_file
        self.component = None
        self.input_file = None
        self.n_responses = 0
        self.output = None
        self.results = []

        config_file = get_configuration_file(self.params_file)
        self.config = deserialize(config_file)

    def create_component(self):
        module = importlib.import_module(self.component_path)
        cls = getattr(module, self.config['component'])
        self.component = cls()

    def setup(self):
        input_file, _ = os.path.splitext(self.config['template_file'])
        subprocess.call(['dprepro', self.params_file,
                         self.config['template_file'],
                         input_file])
        shutil.move(input_file, os.getcwd())
        self.input_file = os.path.basename(input_file)
        self.n_responses = len(self.config['response_descriptors'])
        self.output = ComponentOutput(self.component,
                                      self.config['response_descriptors'])

    def run(self):
        self.component.initialize(self.input_file)
        while self.component.get_current_time() < self.component.get_end_time():
            self.component.update()
            self.output.update()
        self.component.finalize()

    def calculate(self):
{'fraction_non_alphanumeric': 0.09933082392304475, 'fraction_numerical': 0.0004182350480970305, 'mean_word_length': 2.634498480243161, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4009857', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1328, 'n_words': 283}