Commit 7e07b0e4 authored by Duggan, John's avatar Duggan, John
Browse files

Functional config and resources tabs

parent 54faaab1
Loading
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -22,12 +22,17 @@ class IPSFastranTool(BasicTool):

    def prepare_tool(self) -> Tuple[Tool, Parameters]:
        # Prepare file ingestion into Galaxy
        self.config = Dataset(name="config.txt")
        self.config.set_content(self.model.config)
        self.config_dataset = Dataset(name="config.txt")
        self.config_dataset.set_content(self.model.config.file_contents)

        # Create the tool instance
        tool_params = Parameters()
        tool_params.add_input(name="config", value=self.config)
        tool_params.add_input(name="config", value=self.config_dataset)
        tool_params.add_input(name="shot_number", value=self.model.config.shot_number)
        tool_params.add_input(name="time_id", value=self.model.config.time_id)
        tool_params.add_input(name="__job_resource|nodes", value=self.model.resource_params.number_of_nodes)
        tool_params.add_input(name="__job_resource|time", value=self.model.resource_params.time_limit)
        # tool_params.add_input(name="__job_resource|qos", value=self.model.resource_params.partition)
        self.tool = Tool(id="fusion_ips_fastran")

        return self.tool, tool_params
+12 −20
Original line number Diff line number Diff line
"""Module for the main model."""

from typing import List

from pydantic import BaseModel, Field


class Config(BaseModel):
    """
    Contains the configuration file.
    Contains configuration parameters.

    This class uses Pydantic (https://docs.pydantic.dev/latest/),
    which allows for defining data validation rules,
@@ -15,26 +13,17 @@ class Config(BaseModel):
    other interfaces for improved clarity and usability.
    """

    field_1: str = Field(default="")
    shot_number: str = Field(default="000001", title="Shot Number")
    time_id: str = Field(default="00001", title="Time ID")
    file_contents: str = Field(default="")


class SlurmParameters(BaseModel):
    """
    Contains parameters for running SBATCH.

    Note that it's important to validate these parameters to let users know if their selected values will cause issues
    running on NERSC.
    """
class ResourceParameters(BaseModel):
    """Contains resource parameters for running the job."""

    partition: str = Field(default="debug", title="Partition")
    number_of_nodes: int = Field(default=1, ge=1, le=4, title="Number of Nodes")
    number_of_nodes: int = Field(default=1, ge=1, le=2, title="Number of Nodes")
    time_limit: int = Field(default=10, ge=1, le=10080, title="Time Limit (minutes)")
    job_name: str = Field(default="ips_fastran", title="Job Name")
    output_filename: str = Field(default="ips.out", title="Error Filename")
    error_filename: str = Field(default="ips.err", title="Error Filename")
    constraints: List[str] = Field(default=["cpu"], title="Constraints")
    shot_number: str = Field(default="000001", title="Shot Number")
    time_id: str = Field(default="00001", title="Time ID")


class MainModel:
@@ -42,7 +31,10 @@ class MainModel:

    def __init__(self) -> None:
        self.config = Config()
        self.slurm_params = SlurmParameters()
        self.resource_params = ResourceParameters()

    def get_config_file(self) -> str:
        return self.config.file_contents

    def set_from_json(self, json_data: str) -> None:
        self.config = Config.model_validate_json(json_data)
        self.config.file_contents = json_data
+1 −3
Original line number Diff line number Diff line
@@ -30,9 +30,7 @@ class ExecutionViewModel:
        self.model = model
        galaxy_url, galaxy_api_key = parse_args()
        self.tool = IPSFastranTool(model)
        self.tool_runner = ToolRunner(
            self.model.slurm_params.job_name, self.tool, self.store_factory, galaxy_url, galaxy_api_key
        )
        self.tool_runner = ToolRunner("ips_fastran", self.tool, self.store_factory, galaxy_url, galaxy_api_key)
        self.tool_runner.progress_signal.connect(self.on_progress)
        self.completion_signal = signal("ips_fastran_complete")

+14 −6
Original line number Diff line number Diff line
@@ -36,10 +36,10 @@ class MainViewModel:
        # self.model will be updated automatically on changes of connected fields in View,
        # but one also can provide a callback function if they want to react to those events
        # and/or process errors.
        self.config_bind = binding.new_bind()
        self.config_bind = binding.new_bind(self.model.config, callback_after_update=self.on_change_config)
        self.figure_bind = binding.new_bind()
        self.slurm_params_bind = binding.new_bind(
            self.model.slurm_params, callback_after_update=self.on_change_slurm_params
        self.resource_params_bind = binding.new_bind(
            self.model.resource_params, callback_after_update=self.on_change_resource_params
        )
        self.view_state_bind = binding.new_bind(self.view_state)

@@ -49,13 +49,16 @@ class MainViewModel:
        self.completion_signal = signal("ips_fastran_complete")
        self.completion_signal.connect(self.on_completion, weak=False)

    def get_config_file(self) -> str:
        return self.model.get_config_file()

    def get_figure(self) -> Figure:
        return self.figure

    def init_view(self) -> None:
        self.config_bind.update_in_view(self.model.config.model_dump_json(indent=2))
        self.config_bind.update_in_view(self.model.config)

    def on_change_config(self, json_data: str) -> None:
    def on_change_config_file(self, json_data: str) -> None:
        # Monaco fires input events with internal data that need to be ignored.
        if "_vts" in json_data:
            return
@@ -74,7 +77,12 @@ class MainViewModel:

        self.view_state_bind.update_in_view(self.view_state)

    def on_change_slurm_params(self, results: Dict[str, Any]) -> None:
    def on_change_config(self, results: Dict[str, Any]) -> None:
        if results["updated"]:
            # You can take actions in Python when specific fields are changed here.
            pass

    def on_change_resource_params(self, results: Dict[str, Any]) -> None:
        if results["updated"]:
            # You can take actions in Python when specific fields are changed here.
            pass
+2 −2
Original line number Diff line number Diff line
"""Module for the Execution panel."""

from nova.trame.view.components.execution_buttons import ExecutionButtons
from nova.trame.view.components import ExecutionButtons


class ExecutionPanel:
@@ -10,4 +10,4 @@ class ExecutionPanel:
        self.create_ui()

    def create_ui(self) -> None:
        ExecutionButtons("ips_fastran")
        ExecutionButtons("ips_fastran", download_btn=True)
Loading