Custom studies

In a custom study, the behaviour of jobs and tuned parameters is similar to that from the tabular study, however the user interaction is performed automatically in the background using a ‘custom study’ python script (instead of via the GUI). Nontuned parameters will take the default values for that job type unless they are altered explicitly.

Open file

Click here to open the dialog window for locating & opening the custom study python script file. After opening, the filename and time/date of its last modification will be displayed.

Export file

Click here to export the opened custom study script (a .py script will be exported)

Load variables

Click here to load the variables defined in the custom study script.

Run

After the variables of the custom study have been suitably adjusted, the run button will create the jobs and start the study calculations.

Example custom study for creating homogeneously spaced static jobs along an axis

"""
    Example study setup script for creating homogeneously spaced static jobs along an axis
"""

__author__ = 'LB'
__version__ = '2.0'

from more.simulation_package import CustomStudyScript, AxisEnumVariable, LoadCaseContainerEnumVariable
from traits.api import Int, Float, Instance, HasTraits, Enum, List, Union, Tuple, Range, Str, Bool
from traitsui.api import View, Item, EnumEditor
import numpy as np
from more import log
logger = log.getLogger(__name__)


class SomeScript(CustomStudyScript):
    # Example boolean parameter for controlling the optional user defined traits_view
    # flag = Bool()
    position_min: float = Float()
    position_max: float = Float()
    position_count: int = Int()
    axis = AxisEnumVariable()
    load_case_container = LoadCaseContainerEnumVariable()
    boolean = Bool()

    def run(self):
        """ Anything written here will be executed after pressing the run Script button """
        # Variables available by default in the custom study.
        self.run_jobs = True
        print(
            self.study_setup)  # A study setup object with the containing study already pre-set (see scripting api to know what this object is)
        logger.info('Some log message')
        print(self.proj)  # The proj instance
        # And example study setup using the scripting api
        self.study_setup.add_tags(['Tag_0'])
        for position in np.linspace(self.position_min, self.position_max, self.position_count):
            with self.study_setup.create_job_setup(job_name='Static Job') as job:
                job.set_job_specific_parameter(parameter_name='single_load_case_choice',
                                               value=self.load_case_container.value.name) \
                    .set_parameter(obj=self.axis.value, parameter_name='position', value=position) \
                    .set_running_job_settings_parameter(parameter_name='save_result', value=False) \
                    .set_running_job_settings_parameter(parameter_name='tags', value=['Tag_0'])

        job = self.study_setup.create_job_setup(job_name='Static Job Aggregation')
        job.set_job_specific_parameter(parameter_name='chosen_tag', value='Tag_0')
        print(self.load_case_container.value.load_cases)
        # load_case = self.load_case_container.value.load_cases[0]

        # Other examples of parameters:
        # job.set_parameter(obj=load_case, parameter_name='time_dependent_data', value=True)
        # job.set_parameter(obj=load_case, parameter_name='single_data_table_choice', value='data_table_name')
        # job.set_parameter(obj=load_case.partial_find_creator, parameter_name='data_table_column_index', value=0)

        # Create the job
        job.create()

        # the return value of this function has to be None or JSON serializable data to be used and stored with the results
        custom_data_for_evaluation = [{'data': 42, 'other_data': 14324321}, 12]
        return custom_data_for_evaluation
        # The jobs that were added to the study_setup object will be run after this file is finished

    # Optional user defined traits_view - refer to TraitsUI documentation for more information
    # Uncomment this and the boolean 'flag' trait at the top of the class to see an example
    # on how to control the UI
    # traits_view = View(Item('flag'), Item('position_min', enabled_when='flag'))