Admins will be upgrading ORNL GitLab Servers on Saturday, 16 May 2026, from 7 AM until 11 AM EST. Repositories will experience intermittent outages during this time.
- Explain the purpose of the `Nova`, `Tool`, and `Parameters` classes in `nova-galaxy`.
- Explain the purpose of the `Connection`, `Outputs`, `Datastore`, `Tool`, and `Parameters` classes in `nova-galaxy`.
- Describe the basic workflow for running an NDIP tool using `nova-galaxy`.
- Connect to NDIP using the `Nova` class.
- Connect to NDIP using the `Connection` class.
- Define an NDIP tool and set its parameters using the `Tool` and `Parameters` classes.
- Run the tool and create a datastore.
@@ -34,27 +34,33 @@ The `nova-galaxy` library is your gateway to interacting with NDIP programmatica
We will be using the following key classes from `nova-galaxy` in this episode:
***`Nova`**: The main entry point for interacting with NDIP. You instantiate the `Nova` class with your NDIP URL and API key to establish a connection.
***`Connection`**: The main entry point for interacting with NDIP. You instantiate the `Connection` class with your NDIP URL and API key to establish a connection.
***`Tool`**: Represents a tool available on the NDIP platform. You can define a `Tool` object by its ID (which corresponds to a tool XML definition in NDIP).
***`Parameters`**: Used to define the input parameters for a tool. You add parameters to a `Parameters` object, specifying the parameter names and values.
***`Datastore`**: Configures Galaxy to group outputs of a tool to group outputs of a tool together.
***`Output`**: Contains the output datasets and collections for a tool.
***`Dataset`**: A singular file which can be uploaded to Galaxy to be used in tools or downloaded from Galaxy to local storage.
***`DatasetCollection`**: A group of files which can be uploaded to Galaxy to be used in tools or downloaded from Galaxy to local storage.
The basic workflow for running a tool with `nova-galaxy` involves these steps:
1.**Connect to NDIP**: Create a `Nova` instance with your credentials.
1.**Connect to NDIP**: Create a `Connection` instance with your credentials.
2.**Define the Tool**: Create a `Tool` instance, specifying the ID of the NDIP tool you want to run.
3.**Set Parameters**: Create a `Parameters` instance and add the necessary input parameters and their values for the tool.
4.**Run the Tool**: Use the `tool.run()` method to submit the job to NDIP. This typically involves creating a datastore to hold the job\'s input and output data.
## Setting up the Fractal tool
Let\'s create a `Fractal` class that uses `nova-galaxy` to run the `neutrons_fractal` tool on NDIP. You can find the complete code for this episode in the `code/episode_3` directory. Here, we will focus on the key code snippets and explain the important parts.
Let\'s create a `Fractal` class that uses `nova-galaxy` to run the `neutrons_fractal` tool on NDIP. You can find the complete code for this episode in the `code/episode_3` directory.
**1. `Fractal` Class (`src/nova_tutorial/models/fractal.py`):**
***Imports**: The `Fractal Model` starts by importing necessary classes from `nova-galaxy`:
To get started, let\'s create the Fractal class. Create a new file at `src/nova_tutorial/models/fractal.py`. Add the following pieces of code to the newly created file.
***Imports**: The `Fractal Class` will start by importing the necessary classes from `nova-galaxy`:
```python
from nova.galaxy import Nova, Parameters, Tool
from nova.galaxy import Connection, Parameters, Tool
```
***`__init__` method**: In the `__init__` method, we instantiate the `Fractal` class. Note how we retrieve `GALAXY_URL` and `GALAXY_API_KEY` from environment variables. This establishes how we will connect to NDIP:
@@ -69,7 +75,7 @@ Let\'s create a `Fractal` class that uses `nova-galaxy` to run the `neutrons_fra
***`run_fractal_tool` method**: This method encapsulates the logic for running the `fractal` tool. Let\'s examine the key steps within this method:
* **Instantiate `Nova`, `Tool`, and `Parameters`**: We create instances of the `Nova`, `Tool`, and `Parameters` classes:
* **Instantiate `Connection`, `Tool`, and `Parameters`**: We create instances of the `Connection`, `Tool`, and `Parameters` classes:
@@ -79,7 +85,7 @@ Let\'s create a `Fractal` class that uses `nova-galaxy` to run the `neutrons_fra
```
Note that we create a `Tool` object with the `id="neutrons_fractal"`. This tells `nova-galaxy` which NDIP tool we want to run. The obvious question at this point is how do we know the id of the tool and what parameters it expects? We can look at the tool\'s launch page in calvera for some hints but ultimately we have to look at the tool\'s [xml file](https://code.ornl.gov/ndip/galaxy-tools/-/blob/dev/tools/neutrons/test_tools/fractal.xml?ref_type=heads).
* **Connect and Run the Tool**: The `with nova.connect() as galaxy_connection:` block establishes a connection to NDIP and ensures proper handling of the connection:
* **Connect and Run the Tool**: The `with conn.connect() as galaxy_connection:` block establishes a connection to NDIP and ensures proper handling of the connection:
@@ -92,6 +98,8 @@ Let\'s create a `Fractal` class that uses `nova-galaxy` to run the `neutrons_fra
**2. `main.py` - Calling the Model (`src/nova_tutorial/main.py`):**
We are now going to modify the existing `main.py` file. Change the main method to match the code below.
***Instantiate and Run**: In the `main()` function, we create an instance of `Fractal` and call the `run_fractal_tool()` method, wrapped in a `try...except` block for basic error handling:
```python
defmain():
@@ -128,7 +136,22 @@ At times, it may be desirable to execute a tool or workflow without waiting on t
## Tool output
After the tool finishes running on NDIP, the result of the tool is returned as an output. In this example, the output is a single image file of the generated fractal. Tools can return single files or a collection of files as a zip. The output can be used by the rest of your application, saved, or simply discarded. A copy of the output also resides on the NDIP platform, so it is not necessary to maintain a local copy.
Tool execution often results in some type of output. In the Fractal example, the tool output is a singular image file. A tool can have multiple outputs and sometimes these outputs are grouped together in a collection. In `nova-galaxy`, a singular file is called a Dataset and a group of files is called a DatasetCollection. The `Dataset` and `DatasetCollection` classes support the following methods:
***upload(Datastore):** Uploads the Dataset(DatasetCollection) to the specified Datastore on Galaxy.
***download(file_path):** Downloads the Dataset(DatasetCollection) from Galaxy to the local path.
***get_content():** Retreives the content of the Dataset(DatasetCollection) without saving it to a local file path.
If a tool run results in a `Dataset` or `DatasetCollection`, an `Output` is returned from the run method. `Output` is an encapsulation of the output datasets and collections from a Tool. A tool execution can result in multiple `Dataset` and `DatasetCollection`, therefore, these are all grouped in the `Outputs` class for easier consumption.
In the Fractal example, the Tool.run comman returns an instance of the `Output` class which we save to the variable `output`. The Fractal tool [xml file](https://code.ornl.gov/ndip/galaxy-tools/-/blob/dev/tools/neutrons/test_tools/fractal.xml?ref_type=heads) defines that successful execution of the tool will result in a `Dataset` named `output`. This `Dataset` is then downloaded to the local file path `image.png`.
The Outputs can be used by the rest of your application, saved, or simply discarded. A copy of the Datasets and DatasetCollections also resides on the NDIP platform, so it is not necessary to maintain a local copy.
***Decode the image data:** Finally, we need to decode the image that we receive as the output from the tool execution. Modify the section where we execute the tool to the following:
@@ -215,7 +216,7 @@ Let\'s see how to implement the MVVM pattern using `nova-mvvm` and incorporate P
vuetify.VTab("Sample Tab 2", value=3)
```
**4. Modify the tab panel (`src/nova_tutorial/views/tab_content_panel.py`):**
**5. Modify the tab panel content (`src/nova_tutorial/views/tab_content_panel.py`):**