def __init__(self):
        SimulationConfigPanel.__init__(self, MultipleDataAssimilation())

        layout = QFormLayout()

        case_model = CaseSelectorModel()
        case_selector = ComboChoice(case_model, "Current case", "init/current_case_selection")
        layout.addRow(case_selector.getLabel(), case_selector)

        run_path_model = RunPathModel()
        run_path_label = ActiveLabel(run_path_model, "Runpath", "config/simulation/runpath")
        layout.addRow(run_path_label.getLabel(), run_path_label)

        number_of_realizations_model = EnsembleSizeModel()
        number_of_realizations_label = ActiveLabel(number_of_realizations_model, "Number of realizations", "config/ensemble/num_realizations")
        layout.addRow(number_of_realizations_label.getLabel(), number_of_realizations_label)

        target_case_format_model = TargetCaseFormatModel()
        self.target_case_format_field = StringBox(target_case_format_model, "Target case format", "config/simulation/target_case_format")
        self.target_case_format_field.setValidator(ProperNameFormatArgument())
        layout.addRow(self.target_case_format_field.getLabel(), self.target_case_format_field)

        iterated_target_case_format_model = DefaultNameFormatModel(())
        iterated_target_case_format_box = StringBox(iterated_target_case_format_model, "Target case format", "config/simulation/iterated_target_case_format")
        iterated_target_case_format_box.setValidator(ProperNameFormatArgument())

        self.option_widget = TextOrFile(self.getSimulationModel().setWeights)
        layout.addRow("Relative Weights:", self.option_widget)
        layout.addRow('Note:',
                      QLabel("Example Custom Relative Weights: '8,4,2,1'\n"
                             "This means MDA-ES will half the weight\n"
                             "applied to the Observation Errors from one\n"
                             "iteration to the next across 4 iterations."))

        analysis_module_model = AnalysisModuleModel()
        self.analysis_module_choice = ComboChoice(analysis_module_model, "Analysis Module", "config/analysis/analysis_module")

        self.variables_popup_button = QToolButton()
        self.variables_popup_button.setIcon(util.resourceIcon("ide/small/cog_edit.png"))
        self.variables_popup_button.clicked.connect(self.showVariablesPopup)
        self.variables_popup_button.setMaximumSize(20, 20)

        self.variables_layout = QHBoxLayout()
        self.variables_layout.addWidget(self.analysis_module_choice, 0, Qt.AlignLeft)
        self.variables_layout.addWidget(self.variables_popup_button, 0, Qt.AlignLeft)
        self.variables_layout.setContentsMargins(QMargins(0,0,0,0))
        self.variables_layout.addStretch()

        layout.addRow(self.analysis_module_choice.getLabel(), self.variables_layout)

        active_realizations_model = ActiveRealizationsModel()
        self.active_realizations_field = StringBox(active_realizations_model, "Active realizations", "config/simulation/active_realizations")
        self.active_realizations_field.setValidator(RangeStringArgument())
        layout.addRow(self.active_realizations_field.getLabel(), self.active_realizations_field)

        self.target_case_format_field.validationChanged.connect(self.simulationConfigurationChanged)
        self.active_realizations_field.validationChanged.connect(self.simulationConfigurationChanged)
        self.option_widget.validationChanged.connect(self.simulationConfigurationChanged)

        self.setLayout(layout)
Example #2
0
    def __init__(self):
        QWidget.__init__(self)

        layout = QHBoxLayout()
        layout.addSpacing(10)

        workflow_model = WorkflowsModel()

        # workflow_model.observable().attach(WorkflowsModel.CURRENT_CHOICE_CHANGED_EVENT, self.showWorkflow)
        workflow_combo = ComboChoice(workflow_model, "Select Workflow", "run/workflow")
        layout.addWidget(QLabel(workflow_combo.getLabel()), 0, Qt.AlignVCenter)
        layout.addWidget(workflow_combo, 0, Qt.AlignVCenter)

        # simulation_mode_layout.addStretch()
        layout.addSpacing(20)

        self.run_button = QToolButton()
        self.run_button.setIconSize(QSize(32, 32))
        self.run_button.setText("Start Workflow")
        self.run_button.setIcon(util.resourceIcon("ide/gear_in_play"))
        self.run_button.clicked.connect(self.startWorkflow)
        self.run_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        layout.addWidget(self.run_button)
        layout.addStretch(1)

        self.setLayout(layout)

        self.__running_workflow_dialog = None

        self.workflowSucceeded.connect(self.workflowFinished)
        self.workflowFailed.connect(self.workflowFinishedWithFail)
    def __init__(self):
        SimulationConfigPanel.__init__(self, EnsembleExperiment())

        layout = QFormLayout()

        case_model = CaseSelectorModel()
        case_selector = ComboChoice(case_model, "Current case", "init/current_case_selection")
        layout.addRow(case_selector.getLabel(), case_selector)

        runpath_model = RunPathModel()
        runpath_label = ActiveLabel(runpath_model, "Runpath", "config/simulation/runpath")
        layout.addRow(runpath_label.getLabel(), runpath_label)


        number_of_realizations_model = EnsembleSizeModel()
        number_of_realizations_label = ActiveLabel(number_of_realizations_model, "Number of realizations", "config/ensemble/num_realizations")
        layout.addRow(number_of_realizations_label.getLabel(), number_of_realizations_label)

        active_realizations_model = ActiveRealizationsModel()
        self.active_realizations_field = StringBox(active_realizations_model, "Active realizations", "config/simulation/active_realizations")
        self.active_realizations_field.setValidator(RangeStringArgument(number_of_realizations_model.getValue()))
        layout.addRow(self.active_realizations_field.getLabel(), self.active_realizations_field)

        self.active_realizations_field.validationChanged.connect(self.simulationConfigurationChanged)


        self.setLayout(layout)
    def __init__(self):
        '''
        Fills in the input panel for sensitivity study parameters.
        '''

        SimulationConfigPanel.__init__(self, SensitivityStudy())

        layout = QFormLayout()

        case_model = CaseSelectorModel()
        case_selector = ComboChoice(case_model, "Current case",
                                    "init/current_case_selection")
        layout.addRow(case_selector.getLabel(), case_selector)

        runpath_model = RunPathModel()
        runpath_label = ActiveLabel(runpath_model, "Runpath",
                                    "config/simulation/runpath")
        layout.addRow(runpath_label.getLabel(), runpath_label)

        number_of_realizations_model = EnsembleSizeModel()
        number_of_realizations_label = ActiveLabel(
            number_of_realizations_model, "Number of realizations",
            "config/ensemble/num_realizations")
        layout.addRow(number_of_realizations_label.getLabel(),
                      number_of_realizations_label)

        sensitivity_target_case_format_model = SensitivityTargetCaseFormatModel(
        )
        self.iterated_target_case_format_field = StringBox(
            sensitivity_target_case_format_model, "Target case format",
            "config/simulation/sensitivity_target_case_format")
        self.iterated_target_case_format_field.setValidator(
            ProperNameFormatStringArgument())
        layout.addRow(self.iterated_target_case_format_field.getLabel(),
                      self.iterated_target_case_format_field)

        self.parameters_popup_button = QToolButton()
        self.parameters_popup_button.setIcon(
            util.resourceIcon("ide/small/cog_edit.png"))
        self.parameters_popup_button.clicked.connect(self.showParametersPopup)
        self.parameters_popup_button.setMaximumSize(20, 20)

        layout.addRow("Parameters:", self.parameters_popup_button)

        active_realizations_model = ActiveRealizationsModel()
        self.active_realizations_field = StringBox(
            active_realizations_model, "Active realizations",
            "config/simulation/active_realizations")
        self.active_realizations_field.setValidator(
            RangeStringArgument(number_of_realizations_model.getValue()))
        layout.addRow(self.active_realizations_field.getLabel(),
                      self.active_realizations_field)

        self.active_realizations_field.validationChanged.connect(
            self.simulationConfigurationChanged)

        self.setLayout(layout)
    def __init__(self):
        SimulationConfigPanel.__init__(self, MultipleDataAssimilation())

        layout = QFormLayout()

        case_model = CaseSelectorModel()
        case_selector = ComboChoice(case_model, "Current case", "init/current_case_selection")
        layout.addRow(case_selector.getLabel(), case_selector)

        run_path_model = RunPathModel()
        run_path_label = ActiveLabel(run_path_model, "Runpath", "config/simulation/runpath")
        layout.addRow(run_path_label.getLabel(), run_path_label)

        number_of_realizations_model = EnsembleSizeModel()
        number_of_realizations_label = ActiveLabel(number_of_realizations_model, "Number of realizations", "config/ensemble/num_realizations")
        layout.addRow(number_of_realizations_label.getLabel(), number_of_realizations_label)

        target_case_format_model = TargetCaseFormatModel()
        self._target_case_format_field = StringBox(target_case_format_model, "Target case format", "config/simulation/target_case_format")
        self._target_case_format_field.setValidator(ProperNameFormatArgument())
        layout.addRow(self._target_case_format_field.getLabel(), self._target_case_format_field)

        iterated_target_case_format_model = DefaultNameFormatModel(())
        iterated_target_case_format_box = StringBox(iterated_target_case_format_model, "Target case format", "config/simulation/iterated_target_case_format")
        iterated_target_case_format_box.setValidator(ProperNameFormatArgument())

        self._createInputForWeights(layout)

        analysis_module_model = AnalysisModuleModel()
        self._analysis_module_choice = ComboChoice(analysis_module_model, "Analysis Module", "config/analysis/analysis_module")

        self._variables_popup_button = QToolButton()
        self._variables_popup_button.setIcon(util.resourceIcon("ide/small/cog_edit.png"))
        self._variables_popup_button.clicked.connect(self.showVariablesPopup)
        self._variables_popup_button.setMaximumSize(20, 20)

        self._variables_layout = QHBoxLayout()
        self._variables_layout.addWidget(self._analysis_module_choice, 0, Qt.AlignLeft)
        self._variables_layout.addWidget(self._variables_popup_button, 0, Qt.AlignLeft)
        self._variables_layout.setContentsMargins(QMargins(0,0,0,0))
        self._variables_layout.addStretch()

        layout.addRow(self._analysis_module_choice.getLabel(), self._variables_layout)

        active_realizations_model = ActiveRealizationsModel()
        self._active_realizations_field = StringBox(active_realizations_model, "Active realizations", "config/simulation/active_realizations")
        self._active_realizations_field.setValidator(RangeStringArgument())
        layout.addRow(self._active_realizations_field.getLabel(), self._active_realizations_field)

        self._target_case_format_field.validationChanged.connect(self.simulationConfigurationChanged)
        self._active_realizations_field.validationChanged.connect(self.simulationConfigurationChanged)
        self._relative_iteration_weights_box.validationChanged.connect(self.simulationConfigurationChanged)

        self.setLayout(layout)
Example #6
0
class EnsembleSmootherPanel(SimulationConfigPanel):
    def __init__(self):
        SimulationConfigPanel.__init__(self, EnsembleSmoother())

        layout = QFormLayout()

        case_model = CaseSelectorModel()
        case_selector = ComboChoice(case_model, "Current case", "init/current_case_selection")
        layout.addRow(case_selector.getLabel(), case_selector)

        run_path_model = RunPathModel()
        run_path_label = ActiveLabel(run_path_model, "Runpath", "config/simulation/runpath")
        layout.addRow(run_path_label.getLabel(), run_path_label)

        # re_run_path_model = RerunPathModel()
        # re_run_path_label = ActiveLabel(re_run_path_model, "Rerunpath", "config/simulation/rerunpath")
        # layout.addRow(re_run_path_label.getLabel(), re_run_path_label)


        number_of_realizations_model = EnsembleSizeModel()
        number_of_realizations_label = ActiveLabel(number_of_realizations_model, "Number of realizations", "config/ensemble/num_realizations")
        layout.addRow(number_of_realizations_label.getLabel(), number_of_realizations_label)


        target_case_model = TargetCaseModel()
        self.target_case_field = StringBox(target_case_model, "Target case", "config/simulation/target_case")
        self.target_case_field.setValidator(ProperNameArgument())
        layout.addRow(self.target_case_field.getLabel(), self.target_case_field)

        analysis_module_model = AnalysisModuleModel()
        self.analysis_module_choice = ComboChoice(analysis_module_model, "Analysis Module", "config/analysis/analysis_module")
        layout.addRow(self.analysis_module_choice.getLabel(), self.analysis_module_choice)

        active_realizations_model = ActiveRealizationsModel()
        self.active_realizations_field = StringBox(active_realizations_model, "Active realizations", "config/simulation/active_realizations")
        self.active_realizations_field.setValidator(RangeStringArgument())
        layout.addRow(self.active_realizations_field.getLabel(), self.active_realizations_field)


        self.target_case_field.validationChanged.connect(self.simulationConfigurationChanged)
        self.active_realizations_field.validationChanged.connect(self.simulationConfigurationChanged)

        self.setLayout(layout)

    def isConfigurationValid(self):
        return self.target_case_field.isValid() and self.active_realizations_field.isValid()

    def toggleAdvancedOptions(self, show_advanced):
        self.active_realizations_field.setVisible(show_advanced)
        self.layout().labelForField(self.active_realizations_field).setVisible(show_advanced)

        self.analysis_module_choice.setVisible(show_advanced)
        self.layout().labelForField(self.analysis_module_choice).setVisible(show_advanced)
    def __init__(self):
        SimulationConfigPanel.__init__(self, IteratedEnsembleSmoother())

        layout = QFormLayout()

        case_model = CaseSelectorModel()
        case_selector = ComboChoice(case_model, "Current case", "init/current_case_selection")
        layout.addRow(case_selector.getLabel(), case_selector)

        run_path_model = RunPathModel()
        run_path_label = ActiveLabel(run_path_model, "Runpath", "config/simulation/runpath")
        layout.addRow(run_path_label.getLabel(), run_path_label)

        number_of_realizations_model = EnsembleSizeModel()
        number_of_realizations_label = ActiveLabel(
            number_of_realizations_model, "Number of realizations", "config/ensemble/num_realizations"
        )
        layout.addRow(number_of_realizations_label.getLabel(), number_of_realizations_label)

        num_iterations_model = NumberOfIterationsModel()
        num_iterations_spinner = IntegerSpinner(
            num_iterations_model, "Number of iterations", "config/simulation/number_of_iterations"
        )
        layout.addRow(num_iterations_spinner.getLabel(), num_iterations_spinner)

        iterated_target_case_format_model = TargetCaseFormatModel()
        self.iterated_target_case_format_field = StringBox(
            iterated_target_case_format_model, "Target case format", "config/simulation/iterated_target_case_format"
        )
        self.iterated_target_case_format_field.setValidator(ProperNameFormatArgument())
        layout.addRow(self.iterated_target_case_format_field.getLabel(), self.iterated_target_case_format_field)

        iterated_analysis_module_model = IteratedAnalysisModuleModel()
        self.iterated_analysis_module_choice = ComboChoice(
            iterated_analysis_module_model, "Analysis Module", "config/analysis/iterated_analysis_module"
        )
        layout.addRow(self.iterated_analysis_module_choice.getLabel(), self.iterated_analysis_module_choice)

        active_realizations_model = ActiveRealizationsModel()
        self.active_realizations_field = StringBox(
            active_realizations_model, "Active realizations", "config/simulation/active_realizations"
        )
        self.active_realizations_field.setValidator(RangeStringArgument())
        layout.addRow(self.active_realizations_field.getLabel(), self.active_realizations_field)

        self.iterated_target_case_format_field.validationChanged.connect(self.simulationConfigurationChanged)
        self.active_realizations_field.validationChanged.connect(self.simulationConfigurationChanged)

        self.setLayout(layout)
Example #8
0
    def __init__(self):
        QWidget.__init__(self)

        layout = QVBoxLayout()

        simulation_mode_layout = QHBoxLayout()
        simulation_mode_layout.addSpacing(10)
        simulation_mode_model = SimulationModeModel()
        simulation_mode_model.observable().attach(
            SimulationModeModel.CURRENT_CHOICE_CHANGED_EVENT, self.toggleSimulationMode
        )
        simulation_mode_combo = ComboChoice(simulation_mode_model, "Simulation mode", "run/simulation_mode")
        simulation_mode_layout.addWidget(QLabel(simulation_mode_combo.getLabel()), 0, Qt.AlignVCenter)
        simulation_mode_layout.addWidget(simulation_mode_combo, 0, Qt.AlignVCenter)

        # simulation_mode_layout.addStretch()
        simulation_mode_layout.addSpacing(20)

        self.run_button = QToolButton()
        self.run_button.setIconSize(QSize(32, 32))
        self.run_button.setText("Start Simulation")
        self.run_button.setIcon(util.resourceIcon("ide/gear_in_play"))
        self.run_button.clicked.connect(self.runSimulation)
        self.run_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        HelpedWidget.addHelpToWidget(self.run_button, "run/start_simulation")

        simulation_mode_layout.addWidget(self.run_button)
        simulation_mode_layout.addStretch(1)

        layout.addSpacing(5)
        layout.addLayout(simulation_mode_layout)
        layout.addSpacing(10)

        self.simulation_stack = QStackedWidget()
        self.simulation_stack.setLineWidth(1)
        self.simulation_stack.setFrameStyle(QFrame.StyledPanel)

        layout.addWidget(self.simulation_stack)

        self.simulation_widgets = {}

        self.addSimulationConfigPanel(EnsembleExperimentPanel())
        self.addSimulationConfigPanel(SensitivityStudyPanel())
        self.addSimulationConfigPanel(EnsembleSmootherPanel())
        self.addSimulationConfigPanel(IteratedEnsembleSmootherPanel())

        self.setLayout(layout)
Example #9
0
    def __init__(self):
        QWidget.__init__(self)

        layout = QVBoxLayout()

        simulation_mode_layout = QHBoxLayout()
        simulation_mode_layout.addSpacing(10)
        simulation_mode_model = SimulationModeModel()
        simulation_mode_model.observable().attach(SimulationModeModel.CURRENT_CHOICE_CHANGED_EVENT, self.toggleSimulationMode)
        simulation_mode_combo = ComboChoice(simulation_mode_model, "Simulation mode", "run/simulation_mode")
        simulation_mode_layout.addWidget(QLabel(simulation_mode_combo.getLabel()), 0, Qt.AlignVCenter)
        simulation_mode_layout.addWidget(simulation_mode_combo, 0, Qt.AlignVCenter)

        # simulation_mode_layout.addStretch()
        simulation_mode_layout.addSpacing(20)

        self.run_button = QToolButton()
        self.run_button.setIconSize(QSize(32, 32))
        self.run_button.setText("Start Simulation")
        self.run_button.setIcon(util.resourceIcon("ide/gear_in_play"))
        self.run_button.clicked.connect(self.runSimulation)
        self.run_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        HelpedWidget.addHelpToWidget(self.run_button, "run/start_simulation")

        simulation_mode_layout.addWidget(self.run_button)
        simulation_mode_layout.addStretch(1)

        layout.addSpacing(5)
        layout.addLayout(simulation_mode_layout)
        layout.addSpacing(10)

        self.simulation_stack = QStackedWidget()
        self.simulation_stack.setLineWidth(1)
        self.simulation_stack.setFrameStyle(QFrame.StyledPanel)

        layout.addWidget(self.simulation_stack)

        self.simulation_widgets = {}

        self.addSimulationConfigPanel(EnsembleExperimentPanel())
        self.addSimulationConfigPanel(EnsembleSmootherPanel())
        self.addSimulationConfigPanel(MultipleDataAssimilationPanel())
        self.addSimulationConfigPanel(IteratedEnsembleSmootherPanel())

        self.setLayout(layout)
    def __init__(self):
        '''
        Fills in the input panel for sensitivity study parameters.
        '''

        SimulationConfigPanel.__init__(self, SensitivityStudy())

        layout = QFormLayout()

        case_model = CaseSelectorModel()
        case_selector = ComboChoice(case_model, "Current case", "init/current_case_selection")
        layout.addRow(case_selector.getLabel(), case_selector)

        runpath_model = RunPathModel()
        runpath_label = ActiveLabel(runpath_model, "Runpath", "config/simulation/runpath")
        layout.addRow(runpath_label.getLabel(), runpath_label)

        number_of_realizations_model = EnsembleSizeModel()
        number_of_realizations_label = ActiveLabel(number_of_realizations_model, "Number of realizations", "config/ensemble/num_realizations")
        layout.addRow(number_of_realizations_label.getLabel(), number_of_realizations_label)

        sensitivity_target_case_format_model = SensitivityTargetCaseFormatModel()
        self.iterated_target_case_format_field = StringBox(sensitivity_target_case_format_model, "Target case format",
                                                           "config/simulation/sensitivity_target_case_format")
        self.iterated_target_case_format_field.setValidator(ProperNameFormatStringArgument())
        layout.addRow(self.iterated_target_case_format_field.getLabel(), self.iterated_target_case_format_field)

        self.parameters_popup_button = QToolButton()
        self.parameters_popup_button.setIcon(util.resourceIcon("ide/small/cog_edit.png"))
        self.parameters_popup_button.clicked.connect(self.showParametersPopup)
        self.parameters_popup_button.setMaximumSize(20, 20)

        layout.addRow("Parameters:", self.parameters_popup_button)

        active_realizations_model = ActiveRealizationsModel()
        self.active_realizations_field = StringBox(active_realizations_model, "Active realizations", "config/simulation/active_realizations")
        self.active_realizations_field.setValidator(RangeStringArgument(number_of_realizations_model.getValue()))
        layout.addRow(self.active_realizations_field.getLabel(), self.active_realizations_field)

        self.active_realizations_field.validationChanged.connect(self.simulationConfigurationChanged)

        self.setLayout(layout)
Example #11
0
    def __init__(self):
        QWidget.__init__(self)

        layout = QHBoxLayout()
        layout.addSpacing(10)

        workflow_model = WorkflowsModel()

        # workflow_model.observable().attach(WorkflowsModel.CURRENT_CHOICE_CHANGED_EVENT, self.showWorkflow)
        workflow_combo = ComboChoice(workflow_model, "Select Workflow",
                                     "run/workflow")
        layout.addWidget(QLabel(workflow_combo.getLabel()), 0, Qt.AlignVCenter)
        layout.addWidget(workflow_combo, 0, Qt.AlignVCenter)

        # simulation_mode_layout.addStretch()
        layout.addSpacing(20)

        self.run_button = QToolButton()
        self.run_button.setIconSize(QSize(32, 32))
        self.run_button.setText("Start Workflow")
        self.run_button.setIcon(util.resourceIcon("ide/gear_in_play"))
        self.run_button.clicked.connect(self.startWorkflow)
        self.run_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        layout.addWidget(self.run_button)
        layout.addStretch(1)

        self.setLayout(layout)

        self.__running_workflow_dialog = None

        self.workflowSucceeded.connect(self.workflowFinished)
        self.workflowFailed.connect(self.workflowFinishedWithFail)
        self.workflowKilled.connect(self.workflowStoppedByUser)

        self.__workflow_runner = None
        """:type: WorkflowRunner"""
class IteratedEnsembleSmootherPanel(SimulationConfigPanel):
    def __init__(self):
        SimulationConfigPanel.__init__(self, IteratedEnsembleSmoother())

        layout = QFormLayout()

        case_model = CaseSelectorModel()
        case_selector = ComboChoice(case_model, "Current case", "init/current_case_selection")
        layout.addRow(case_selector.getLabel(), case_selector)

        run_path_model = RunPathModel()
        run_path_label = ActiveLabel(run_path_model, "Runpath", "config/simulation/runpath")
        layout.addRow(run_path_label.getLabel(), run_path_label)

        number_of_realizations_model = EnsembleSizeModel()
        number_of_realizations_label = ActiveLabel(number_of_realizations_model, "Number of realizations", "config/ensemble/num_realizations")
        layout.addRow(number_of_realizations_label.getLabel(), number_of_realizations_label)

        num_iterations_model = NumberOfIterationsModel()
        num_iterations_spinner = IntegerSpinner(num_iterations_model, "Number of iterations", "config/simulation/number_of_iterations")
        layout.addRow(num_iterations_spinner.getLabel(), num_iterations_spinner)

        iterated_target_case_format_model = TargetCaseFormatModel()
        self.iterated_target_case_format_field = StringBox(iterated_target_case_format_model, "Target case format", "config/simulation/iterated_target_case_format")
        self.iterated_target_case_format_field.setValidator(ProperNameFormatArgument())
        layout.addRow(self.iterated_target_case_format_field.getLabel(), self.iterated_target_case_format_field)

        iterated_analysis_module_model = IteratedAnalysisModuleModel()
        self.iterated_analysis_module_choice = ComboChoice(iterated_analysis_module_model, "Analysis Module", "config/analysis/iterated_analysis_module")

        self.variables_popup_button = QToolButton()
        self.variables_popup_button.setIcon(util.resourceIcon("ide/small/cog_edit.png"))
        self.variables_popup_button.clicked.connect(self.showVariablesPopup)
        self.variables_popup_button.setMaximumSize(20, 20)

        self.variables_layout = QHBoxLayout()
        self.variables_layout.addWidget(self.iterated_analysis_module_choice, 0, Qt.AlignLeft)
        self.variables_layout.addWidget(self.variables_popup_button, 0, Qt.AlignLeft)
        self.variables_layout.setContentsMargins(QMargins(0,0,0,0))
        self.variables_layout.addStretch()

        layout.addRow(self.iterated_analysis_module_choice.getLabel(), self.variables_layout)

        active_realizations_model = ActiveRealizationsModel()
        self.active_realizations_field = StringBox(active_realizations_model, "Active realizations", "config/simulation/active_realizations")
        self.active_realizations_field.setValidator(RangeStringArgument())
        layout.addRow(self.active_realizations_field.getLabel(), self.active_realizations_field)

        self.iterated_target_case_format_field.validationChanged.connect(self.simulationConfigurationChanged)
        self.active_realizations_field.validationChanged.connect(self.simulationConfigurationChanged)

        self.setLayout(layout)
        
    def isConfigurationValid(self):
        analysis_module = IteratedAnalysisModuleModel().getCurrentChoice()
        return self.iterated_target_case_format_field.isValid() and self.active_realizations_field.isValid() and analysis_module is not None


    def toggleAdvancedOptions(self, show_advanced):
        self.active_realizations_field.setVisible(show_advanced)
        self.layout().labelForField(self.active_realizations_field).setVisible(show_advanced)

        self.iterated_analysis_module_choice.setVisible(show_advanced)
        self.layout().labelForField(self.variables_layout).setVisible(show_advanced)
        self.variables_popup_button.setVisible(show_advanced)

    def showVariablesPopup(self):
        analysis_module_name = IteratedAnalysisModuleModel().getCurrentChoice()
        if analysis_module_name is not None:
            variable_dialog = AnalysisModuleVariablesPanel(analysis_module_name)
            dialog = ClosableDialog("Edit variables", variable_dialog, self.parent())

            dialog.exec_()
    def __init__(self):
        SimulationConfigPanel.__init__(self, IteratedEnsembleSmoother())

        layout = QFormLayout()

        case_model = CaseSelectorModel()
        case_selector = ComboChoice(case_model, "Current case",
                                    "init/current_case_selection")
        layout.addRow(case_selector.getLabel(), case_selector)

        run_path_model = RunPathModel()
        run_path_label = ActiveLabel(run_path_model, "Runpath",
                                     "config/simulation/runpath")
        layout.addRow(run_path_label.getLabel(), run_path_label)

        number_of_realizations_model = EnsembleSizeModel()
        number_of_realizations_label = ActiveLabel(
            number_of_realizations_model, "Number of realizations",
            "config/ensemble/num_realizations")
        layout.addRow(number_of_realizations_label.getLabel(),
                      number_of_realizations_label)

        num_iterations_model = NumberOfIterationsModel()
        num_iterations_spinner = IntegerSpinner(
            num_iterations_model, "Number of iterations",
            "config/simulation/number_of_iterations")
        layout.addRow(num_iterations_spinner.getLabel(),
                      num_iterations_spinner)

        iterated_target_case_format_model = TargetCaseFormatModel()
        self.iterated_target_case_format_field = StringBox(
            iterated_target_case_format_model, "Target case format",
            "config/simulation/iterated_target_case_format")
        self.iterated_target_case_format_field.setValidator(
            ProperNameFormatArgument())
        layout.addRow(self.iterated_target_case_format_field.getLabel(),
                      self.iterated_target_case_format_field)

        iterated_analysis_module_model = IteratedAnalysisModuleModel()
        self.iterated_analysis_module_choice = ComboChoice(
            iterated_analysis_module_model, "Analysis Module",
            "config/analysis/iterated_analysis_module")

        self.variables_popup_button = QToolButton()
        self.variables_popup_button.setIcon(
            util.resourceIcon("ide/small/cog_edit.png"))
        self.variables_popup_button.clicked.connect(self.showVariablesPopup)
        self.variables_popup_button.setMaximumSize(20, 20)

        self.variables_layout = QHBoxLayout()
        self.variables_layout.addWidget(self.iterated_analysis_module_choice,
                                        0, Qt.AlignLeft)
        self.variables_layout.addWidget(self.variables_popup_button, 0,
                                        Qt.AlignLeft)
        self.variables_layout.setContentsMargins(QMargins(0, 0, 0, 0))
        self.variables_layout.addStretch()

        layout.addRow(self.iterated_analysis_module_choice.getLabel(),
                      self.variables_layout)

        active_realizations_model = ActiveRealizationsModel()
        self.active_realizations_field = StringBox(
            active_realizations_model, "Active realizations",
            "config/simulation/active_realizations")
        self.active_realizations_field.setValidator(RangeStringArgument())
        layout.addRow(self.active_realizations_field.getLabel(),
                      self.active_realizations_field)

        self.iterated_target_case_format_field.validationChanged.connect(
            self.simulationConfigurationChanged)
        self.active_realizations_field.validationChanged.connect(
            self.simulationConfigurationChanged)

        self.setLayout(layout)
class IteratedEnsembleSmootherPanel(SimulationConfigPanel):
    def __init__(self):
        SimulationConfigPanel.__init__(self, IteratedEnsembleSmoother())

        layout = QFormLayout()

        case_model = CaseSelectorModel()
        case_selector = ComboChoice(case_model, "Current case",
                                    "init/current_case_selection")
        layout.addRow(case_selector.getLabel(), case_selector)

        run_path_model = RunPathModel()
        run_path_label = ActiveLabel(run_path_model, "Runpath",
                                     "config/simulation/runpath")
        layout.addRow(run_path_label.getLabel(), run_path_label)

        number_of_realizations_model = EnsembleSizeModel()
        number_of_realizations_label = ActiveLabel(
            number_of_realizations_model, "Number of realizations",
            "config/ensemble/num_realizations")
        layout.addRow(number_of_realizations_label.getLabel(),
                      number_of_realizations_label)

        num_iterations_model = NumberOfIterationsModel()
        num_iterations_spinner = IntegerSpinner(
            num_iterations_model, "Number of iterations",
            "config/simulation/number_of_iterations")
        layout.addRow(num_iterations_spinner.getLabel(),
                      num_iterations_spinner)

        iterated_target_case_format_model = TargetCaseFormatModel()
        self.iterated_target_case_format_field = StringBox(
            iterated_target_case_format_model, "Target case format",
            "config/simulation/iterated_target_case_format")
        self.iterated_target_case_format_field.setValidator(
            ProperNameFormatArgument())
        layout.addRow(self.iterated_target_case_format_field.getLabel(),
                      self.iterated_target_case_format_field)

        iterated_analysis_module_model = IteratedAnalysisModuleModel()
        self.iterated_analysis_module_choice = ComboChoice(
            iterated_analysis_module_model, "Analysis Module",
            "config/analysis/iterated_analysis_module")

        self.variables_popup_button = QToolButton()
        self.variables_popup_button.setIcon(
            util.resourceIcon("ide/small/cog_edit.png"))
        self.variables_popup_button.clicked.connect(self.showVariablesPopup)
        self.variables_popup_button.setMaximumSize(20, 20)

        self.variables_layout = QHBoxLayout()
        self.variables_layout.addWidget(self.iterated_analysis_module_choice,
                                        0, Qt.AlignLeft)
        self.variables_layout.addWidget(self.variables_popup_button, 0,
                                        Qt.AlignLeft)
        self.variables_layout.setContentsMargins(QMargins(0, 0, 0, 0))
        self.variables_layout.addStretch()

        layout.addRow(self.iterated_analysis_module_choice.getLabel(),
                      self.variables_layout)

        active_realizations_model = ActiveRealizationsModel()
        self.active_realizations_field = StringBox(
            active_realizations_model, "Active realizations",
            "config/simulation/active_realizations")
        self.active_realizations_field.setValidator(RangeStringArgument())
        layout.addRow(self.active_realizations_field.getLabel(),
                      self.active_realizations_field)

        self.iterated_target_case_format_field.validationChanged.connect(
            self.simulationConfigurationChanged)
        self.active_realizations_field.validationChanged.connect(
            self.simulationConfigurationChanged)

        self.setLayout(layout)

    def isConfigurationValid(self):
        analysis_module = IteratedAnalysisModuleModel().getCurrentChoice()
        return self.iterated_target_case_format_field.isValid(
        ) and self.active_realizations_field.isValid(
        ) and analysis_module is not None

    def toggleAdvancedOptions(self, show_advanced):
        self.active_realizations_field.setVisible(show_advanced)
        self.layout().labelForField(
            self.active_realizations_field).setVisible(show_advanced)

        self.iterated_analysis_module_choice.setVisible(show_advanced)
        self.layout().labelForField(
            self.variables_layout).setVisible(show_advanced)
        self.variables_popup_button.setVisible(show_advanced)

    def showVariablesPopup(self):
        analysis_module_name = IteratedAnalysisModuleModel().getCurrentChoice()
        if analysis_module_name is not None:
            variable_dialog = AnalysisModuleVariablesPanel(
                analysis_module_name)
            dialog = ClosableDialog("Edit variables", variable_dialog,
                                    self.parent())

            dialog.exec_()
class MultipleDataAssimilationPanel(SimulationConfigPanel):
    def __init__(self):
        SimulationConfigPanel.__init__(self, MultipleDataAssimilation())

        layout = QFormLayout()

        case_model = CaseSelectorModel()
        case_selector = ComboChoice(case_model, "Current case", "init/current_case_selection")
        layout.addRow(case_selector.getLabel(), case_selector)

        run_path_model = RunPathModel()
        run_path_label = ActiveLabel(run_path_model, "Runpath", "config/simulation/runpath")
        layout.addRow(run_path_label.getLabel(), run_path_label)

        number_of_realizations_model = EnsembleSizeModel()
        number_of_realizations_label = ActiveLabel(number_of_realizations_model, "Number of realizations", "config/ensemble/num_realizations")
        layout.addRow(number_of_realizations_label.getLabel(), number_of_realizations_label)

        target_case_format_model = TargetCaseFormatModel()
        self._target_case_format_field = StringBox(target_case_format_model, "Target case format", "config/simulation/target_case_format")
        self._target_case_format_field.setValidator(ProperNameFormatArgument())
        layout.addRow(self._target_case_format_field.getLabel(), self._target_case_format_field)

        iterated_target_case_format_model = DefaultNameFormatModel(())
        iterated_target_case_format_box = StringBox(iterated_target_case_format_model, "Target case format", "config/simulation/iterated_target_case_format")
        iterated_target_case_format_box.setValidator(ProperNameFormatArgument())

        self._createInputForWeights(layout)

        analysis_module_model = AnalysisModuleModel()
        self._analysis_module_choice = ComboChoice(analysis_module_model, "Analysis Module", "config/analysis/analysis_module")

        self._variables_popup_button = QToolButton()
        self._variables_popup_button.setIcon(util.resourceIcon("ide/small/cog_edit.png"))
        self._variables_popup_button.clicked.connect(self.showVariablesPopup)
        self._variables_popup_button.setMaximumSize(20, 20)

        self._variables_layout = QHBoxLayout()
        self._variables_layout.addWidget(self._analysis_module_choice, 0, Qt.AlignLeft)
        self._variables_layout.addWidget(self._variables_popup_button, 0, Qt.AlignLeft)
        self._variables_layout.setContentsMargins(QMargins(0,0,0,0))
        self._variables_layout.addStretch()

        layout.addRow(self._analysis_module_choice.getLabel(), self._variables_layout)

        active_realizations_model = ActiveRealizationsModel()
        self._active_realizations_field = StringBox(active_realizations_model, "Active realizations", "config/simulation/active_realizations")
        self._active_realizations_field.setValidator(RangeStringArgument())
        layout.addRow(self._active_realizations_field.getLabel(), self._active_realizations_field)

        self._target_case_format_field.validationChanged.connect(self.simulationConfigurationChanged)
        self._active_realizations_field.validationChanged.connect(self.simulationConfigurationChanged)
        self._relative_iteration_weights_box.validationChanged.connect(self.simulationConfigurationChanged)

        self.setLayout(layout)

    def _createInputForWeights(self, layout):
        relative_iteration_weights_model = StringModel(self.getSimulationModel().getWeights())
        self._relative_iteration_weights_box = StringBox(relative_iteration_weights_model, "Custom iteration weights", help_link="config/simulation/iteration_weights", continuous_update=True)
        self._relative_iteration_weights_box.setValidator(NumberListStringArgument())
        layout.addRow("Relative Weights:", self._relative_iteration_weights_box)

        def updateModelWithRelativeWeights():
            weights = relative_iteration_weights_model.getValue()
            self.getSimulationModel().setWeights(weights)

        relative_iteration_weights_model.observable().attach(StringModel.VALUE_CHANGED_EVENT, updateModelWithRelativeWeights)

        normalized_weights_model = StringModel()
        normalized_weights_model.setValue("")
        normalized_weights_widget = ActiveLabel(normalized_weights_model, help_link="config/simulation/iteration_weights")
        layout.addRow('Normalized weights:', normalized_weights_widget)

        def updateVisualizationOfNormalizedWeights():
            if self._relative_iteration_weights_box.isValid():
                weights = MultipleDataAssimilation.parseWeights(relative_iteration_weights_model.getValue())
                normalized_weights = MultipleDataAssimilation.normalizeWeights(weights)
                normalized_weights_model.setValue(", ".join("%.2f" % x for x in normalized_weights))
            else:
                normalized_weights_model.setValue("The weights are invalid!")

        self._relative_iteration_weights_box.validationChanged.connect(updateVisualizationOfNormalizedWeights)

        updateVisualizationOfNormalizedWeights() # To normalize the default weights

    def isConfigurationValid(self):
        return self._target_case_format_field.isValid() and self._active_realizations_field.isValid() and self._relative_iteration_weights_box.isValid()

    def toggleAdvancedOptions(self, show_advanced):
        self._active_realizations_field.setVisible(show_advanced)
        self.layout().labelForField(self._active_realizations_field).setVisible(show_advanced)

        self._analysis_module_choice.setVisible(show_advanced)
        self.layout().labelForField(self._variables_layout).setVisible(show_advanced)
        self._variables_popup_button.setVisible(show_advanced)

    def showVariablesPopup(self):
        analysis_module_name = AnalysisModuleModel().getCurrentChoice()
        if analysis_module_name is not None:
            variable_dialog = AnalysisModuleVariablesPanel(analysis_module_name)
            dialog = ClosableDialog("Edit variables", variable_dialog, self.parent())

            dialog.exec_()