> For the complete documentation index, see [llms.txt](https://docs.rhinofcp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rhinofcp.com/creating-and-running-code-objects/creating-and-running-a-python-code-object.md).

# Creating and Running a Python Code Object

This article explains how to create and run Python Code Objects. Python code objects allow you to provide your code to FCP without having to containerize it.

{% hint style="info" %}
NOTE: To learn how to create a Python Code Object using the Rhino SDK, see [Creating a Python Code Object Using the Rhino SDK.](/rhino-sdk/creating-a-python-code-object-using-the-rhino-sdk.md)
{% endhint %}

## What is a Python Code Object?

In Rhino Federated Computing Platform (FCP), Python Code Objects offer a powerful way to execute Python code scripts effortlessly, eliminating the need to locally containerize your code. Building and deploying code becomes a seamless process, with FCP handling container image creation and storage on your workgroup's ECR (Elastic Container Registry).

With Python Code Objects, FCP streamlines code deployment process, allowing you to concentrate on code development and analysis. Whether you're performing sophisticated data manipulations or running custom algorithms, Python Code Objects empower you to leverage the full capabilities of Python while benefiting from FCP's containerization and deployment efficiency.

Python Code Objects on FCP bring simplicity and power to your code development endeavors. By offering options for both code snippets and standalone files, FCP adapts to your needs, allowing you to focus on creating impactful software. Embrace the convenience of executing Python code directly within the platform, while FCP takes care of the intricate details of containerization, image creation, and deployment. Elevate your workflow and unlock new dimensions of development possibilities with Rhino FCP.

## Creating a Python Code Object

To create a new code object, follow these steps.

{% stepper %}
{% step %}

#### Go to your project

Go to the main project's page and select your project.
{% endstep %}

{% step %}

#### Open the Code Objects page

Select **Code** from the menu on the left to open the **Code Objects** page. To search for code objects, use the text boxes located at the top right corner of the page. To search by name enter the full name or part of the name in the Search Name text box. To search by description, enter part of the description in the Search Description text box.

![](/files/52b1d045269970af50b0bedd1ffd13ebe143ff62)
{% endstep %}

{% step %}

#### Create a new code object

Select the **Create New Code Object** button to open the **Create New Code Object** page. You might need to scroll down to see the entire page.

![](/files/98a37ce2f1ef3916d9b9f0a99319657489213569)
{% endstep %}

{% step %}

#### Enter the code object details

*Before you enter information in the fields (see table below), read the following about input and outputs*

*Multiple input and output datasets are supported in Python, Generalized, and Interactive Container Code Objects. While NVFlare Code Objects do not support multiple datasets, they can still be used as before for learning and inference across multiple sites.*

*Code objects usually require that you know the number of inputs and outputs your code needs. Those inputs and outputs are provided as data schemas. For example, if your code splits one dataset into two (like a train/test split), you will have to create a code object with one input schema and two output schemas. For more detail into how to structure your code to run on FCP, see* [*Accessing your datasets in Code Objects*](/creating-and-running-code-objects/accessing-your-datasets-in-code-objects.md)*.*

{% hint style="info" %}
**Pro-tip:** If you don't need this level of control, you can:

* **\[NEW]** set any input or output as optional, which will allow to provide or generate no datasets respectively
* **\[NEW]** set any input or output as a list, which will allow to select 1 or more datasets
* **\[NEW]** select "ANY" as input schema, which will allow code object re-use across any input dataset schema.
* let the system automatically determine the output schemas with [Auto-Generated Data Schemas](/data-schemas/auto-generated-data-schemas.md).
  {% endhint %}

Enter the following:

* Ensure that Python Code is selected as the **Code Object Type**.
* Enter **Details** about this code object, including the name you would like to provide for your code object and optionally, a description. The description that will help you and others understand the nature of this Code Object.
* Add the **inputs**, which are what the Data Schema(s) for the Datasets this Code Object will accept as input. Your selection here will affect which Datasets can be selected as input when triggering a Code Run with this Code Object.
* Enter the **outputs** for the Data Schema(s) for the Datasets that will be created as output when triggering a Code Run with this Code Object. You can also select the option to *\[Auto-generate Data Schema from Data]*. For more information about Auto-generating Data Schemas, please refer to [Auto-Generated Data *Schema*s](/data-schemas/auto-generated-data-schemas.md).
* Enter the **container details**. This is where you can specify parameters that will define your Code Object container:
  * Python and CUDA Versions, or conversely
  * Pre-existing Container Base Image (from Dockerhub). By default, the FCP will use the `python:3.9.7-slim-bullseye` docker image. This means your code will run within a Python 3.9 environment. You are free to select whichever docker base image makes the most sense for your use case (i.e. an image that supports GPU operations).
    {% endstep %}

{% step %}

#### Provide your code

Your code can be provided as a code snippet, standalone file, or an upload file. The information about each appears below.

* **Code Snippet** - Ideal for relatively straightforward scripts that primarily utilize basic Python packages, along with Pandas and Numpy. FCP automatically provides access to your cohort data as a Pandas Dataframe named **df.** Additionally, it generates the output cohort of your model from this same Dataframe. This setup facilitates elementary Pandas-based operations on your raw input data, such as feature extraction and value normalization.

  As an example, consider this Python code snippet:

  ```python
  normalized_df = (df-df.mean())/df.std()
  df = normalized_df
  ```

  Executing this code snippet yields an output cohort with z-normalized numerical features, all without requiring any additional code.
* **Standalone File** - This option grants you the freedom to execute varied Python code with custom dependencies, extending beyond Pandas and Numpy. The Standalone File option lets you specify your code's prerequisites, which will be automatically installed within the image generated by FCP. If your code necessitates a specific environment – for instance, to support GPU operations - you can define the Container Base Image that supports it. Use this option for more complex code, which can still be run as a single file. Unlike the ***Code Snippet***, no additional "hidden" functionality is included here.
* **Upload File(s)** - This option is similar to "Standalone File", but allows you to provide your code in more than one file, e.g., multiple Python files and/or shell scripts. Files can include non-Python files of any format, such as configuration files, model parameter files, and so forth. You just have to upload the files you need, or a folder(s), and select the entry point in the text box that appears when this option is selected. The entry point is the file that you'd like your container to run. Be sure to specify code requirements and the container environment as needed.

{% hint style="info" %}
NOTE: To see how you adapt your code to access your data, see [Accessing your datasets in Code Objects](/creating-and-running-code-objects/accessing-your-datasets-in-code-objects.md)
{% endhint %}
{% endstep %}

{% step %}

#### Enter requirements

Enter the requirements. This field enables you to specify Python libraries that are required to run your *code*. This capability is enabled for all Python Code types except for *Code Snippet* which has two locked dependencies—Pandas and NumPy. Paste all Python dependencies that are necessary for running your previously specified Python code. These dependencies will automatically be installed by the Rhino FCP when it builds your container in the background. Alternatively, click **Upload File** to load a requirements file from your local computer. The Rhino FCP supports both Pip and Conda as package management frameworks.
{% endstep %}

{% step %}

#### Set compute resources if needed

If you will be running your code object on the Google Cloud Platform (GCP) and you want to set minimum CPU, RAM, VRAM, and GPU resources, complete the steps in the Setting Required Compute Resources (Autoscaling) section of this document. If not, go to the next step.
{% endstep %}

{% step %}

#### Finish

When complete, click Create New Code Object or start a Code Run.
{% endstep %}
{% endstepper %}

### Setting Required Compute Resources (Autoscaling)

{% hint style="info" %}
NOTE: This feature is only available if you are running on the Google Cloud Platform (GCP). *For NVFlare code objects and code runs, you can adjust autoscaling methods for both the NVFlare Server and the NVFlare Client. For the NVFlare Server, you can only specify the CPU and RAM.*
{% endhint %}

Autoscaling allows Rhino to run Code Runs on additional compute resources when the default Rhino Client capacity is not sufficient. This capability is designed to support resource‑intensive, "bursty"(processing tasks occur in short, intense or irregular spurts), or GPU‑based workloads while improving isolation, reliability, and cost efficiency. With autoscaling enabled, Rhino provisions temporary cloud VMs on demand, executes workloads on those VMs, and automatically terminates them when execution completes. This can help you make more efficient use of your computing resources and save on costs.

In this section of the screen there are three options: Use Client Resources, Set Minimum, and Use VM Pool.

<figure><img src="/files/GFBA6RaRsa2CcbnjNlEN" alt=""><figcaption></figcaption></figure>

* **Use Client Resources** - Uses the available client settings and resources.
* **Set Minimum** - Allows you to set the minimum number of resources that must be available. If you choose the Set Minimum option, you can indicate the minimum number of CPUs, amount of RAM, the disk size (VRAM), as well as the type and number of GPUs. You can adjust these settings when you create a code object and also when you run your code. Note that adjustments do not persist and will need to be reset with each run.
* **Use VM Pool** - Allows you to select a Pre-allocated Virtual Machine Pool. Select a VM pool to indicate which dedicated compute resource you want to use for your code run, ensuring guaranteed availability for high-demand workloads such as GPU-intensive AI training and inference. This feature provides faster job startup times by using pre-warmed VMs and offers predictable costs through fixed capacity reservations.

Each option is detailed below.

#### *Use Client Resources*

To use client resources, complete the following steps.

1. Select the Use Client Resources button. It should be selected by default.
2. When complete, select Create New Code Object or start a Code Run.

#### *Set Minimum*

To set the minimum required compute resources, complete the following steps.

1. In the Required Compute Resources section, select Set Minimum.
2. Next, make changes to the settings as needed. Note that these setting changes do not persist the next time you run the code object or code run. The settings are explained below.

|           |                                                                                                     |                                                                                                                                                                                                                           |
| --------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Setting   | Description                                                                                         | Usage Notes                                                                                                                                                                                                               |
| CPU MIN   | The minimum number of CPU cores on which your code will be run.                                     | If the CPU MIN is too low, you might see slow code execution or throttling.                                                                                                                                               |
| RAM MIN   | The minimum amount of RAM (main memory) that you want to allocate to running your code.             | If this is too low, you might see an out-of-memory crash or slowness in execution due to disk swapping.                                                                                                                   |
| DISK SIZE | Amount of storage allocated to the instance.                                                        | Increasing this setting increases capacity (not necessarily speed)                                                                                                                                                        |
| GPU TYPE  | The model of GPU hardware. The number of GPUs indicate the number of GPUs attached to the instance. | If your code isn’t written to use multiple GPUs, extra GPUs might not be used. Note that GPU availability depends on the selected cloud region, Project‑level GPU quotas, and the current capacity at the cloud provider. |

#### *Use VM Pool*

To select a VM Pool, complete the following steps.

1. If you choose Use VM Pool, available pools are shown. For each pool you will see a name, as well as the current resources available. For each pool you will see the following information.

* Number of VMs (if any)
* Number of vCPUs per VM
* Amount of RAM per VM
* Disk size per VM
* Whether there are GPUs available, and how many

2. Select the pool of your choice.
3. When complete, select Create New Code Object or start a Code Run.

## Viewing a Code Object's Configuration

To get an object's configuration, make sure you are on the page containing the original object you would like to view the configuration of. In the box where your original object is, there should be a row for each version. Navigate to the version you would like to view the configuration for and select the three-dot menu button, shown below:

![](/files/903f8d8b02de3537a785b7355db65dd33f4bf44c)

The menu button is on the right-hand side of the row, click it to view a new menu. The new menu should have an option to show that object's configuration, click on that to see the object's configuration.

For Code Objects and Code Runs, if you chose the Use VM Pool option, you will use the pool that was indicated during the Code Object or Code Run configurations.  Selecting this option shows the resources, including the number of VMs and vCPUs that will be allocated, as well as the amount of RAM, the size of the disk, the number of GPUs, the GPU type/mode&#x6C;*,* and the amount of VRAM.

## Creating a New Version of a Python Code Object

To create a new version, complete the following steps.

1. Go to the page that has the original object you want to create a new version of.
2. In the upper right corner of the box where your original object is, select the **+ New Version** button.
3. A new window appears that allows you to create a new version of your object.

## Removing a Code Object

To remove a code object, complete the following steps.

{% stepper %}
{% step %}

### Open the Code Objects page

Go to the page that lists your code objects.
{% endstep %}

{% step %}

### Find the code object version

If needed, use the search fields at the top right.

* Use **Search Name** to search by code object name.
* Use **Search Description** to search by code object description.

Each code object appears with a row for each version. Find the version you want to delete.
{% endstep %}

{% step %}

### Open the menu for the version

Select the three-dot menu on the right side of the version row, shown below.

![](/files/e30ab6c50f33a01039109108a719df8152c5cb07)
{% endstep %}

{% step %}

### Remove the code object version

Select **Remove code object**.

Repeat these steps for each version you want to remove. When you delete the last version, the code object is fully deleted.
{% endstep %}
{% endstepper %}

## Running a Python Code Object

Create a Python Code Object before you complete these steps.

{% hint style="info" %}
NOTE: For information on how to run a Python Code Object using the Rhino SDK, see [Running a Python Code Object using the Rhino SDK.](/rhino-sdk/running-a-python-code-object-using-the-rhino-sdk.md)
{% endhint %}

To run a Python Code object, complete the following steps.

{% stepper %}
{% step %}

#### Go to the main project's page

Select your project.
{% endstep %}

{% step %}

#### Open the Code Objects page

Select **Code** from the menu on the left to open the **Code Objects** page.

![](/files/9454ef85e3a554b9fe081c71540d77bafc1f735c)
{% endstep %}

{% step %}

#### Select the Run button

Select the **Run** button for the code object you'd like to run. The Run Model Training page opens.
{% endstep %}

{% step %}

#### Fill in the Code Run configuration fields

Fill in the following fields within the new Code Run configuration window. These steps are the same for the Python Snippet, Standalone File, and Upload File(s) options:

* Enter the Input Dataset(s). This is one or more Datasets to be used as input to your Code Run. If multiple Datasets are selected, each will be run separately. If a Dataset happens to be a collaborator's Dataset, the code will be run on that collaborator's Rhino Client. In other words, the data never moves outside your collaborator's Rhino Client
* Enter the Output Dataset Name Suffix. A suffix that is appended onto the name of each input Dataset to define the name of the output Dataset that will be created during your Code Run
* Adjust the Timeout in Seconds if needed. This is the number of seconds that must elapse before a Code Run is automatically halted. This is to avoid zombie tasks that run perpetually within a Rhino client.
* Add Run Parameters (Optional). Here you can paste a JSON object that defines additional parameters to be provided to your Code Run. This can be used for specifying hyper-parameters for model validation or any parameter provided to the code. Run parameters are made available to the container code in a file located at `/input/run_params.json`

{% hint style="info" %}
Files that you want to run at run-time should be uploaded to the Rhino Orchestrator. See [Frequently Asked Questions (FAQs)](/frequently-asked-questions/frequently-asked-questions-faqs.md) for more details.
{% endhint %}

To add run time files to your code run, select the run time files from the list of the workgroup run files that appears. You will want to only include the ones you need for the code run, like in the example that follows.

![](/files/5f7f440d0a36a536e516429412e33184f7187328)

Note that your workgroup run time files include both published and unpublished files. Files from other workgroups only include the files that they have published and have made visible to you and others in your workgroup that share the same persona. *(Note that for collaborators to have access to files, they must be published. See* [*Managing Run Time Files*](/creating-and-running-code-objects/managing-run-time-files.md) *to learn how to publish run time files.)*
{% endstep %}

{% step %}

#### Run the code

When you have completed adding all your Code Run details, either set the required compute resources by following the instruction in [Setting Required Compute Resources (Autoscaling)](#h_01KCVE0ZYQA8T055FFAN752HR5), or click the **Run** button to run your code.
{% endstep %}
{% endstepper %}

## Reviewing Code Run Logs

Logs that are produced during a Code Run can be viewed by clicking on the Status link in the Code Runs view. If you need to search for a specific code run, use the text boxes located at the top right corner of the page. To search by name enter the full name or part of the name in the Search Name text box. To search by description, enter part of the code run's description in the Search Description text box.

![](/files/b9eac61eb5020042cd8f173ca83e2714a1f39575)

Clicking the Status link will open the Logs view for a particular run:

![](/files/913042c4d818bc668909f24d9376bea0c453f1c8)

Logs can be accessed while the Code Run is active and after the Code Run has completed. While the code is running, an auto-refresh option is available.

This Logs view provides the following information:

* General Info - information about the Code Run, including
  * Code Object name and type
  * Code Object version
  * Code Object description
  * Input and Output Datasets
  * Code Object configuration
  * Code Run configuration
* System Logs
  * Errors or warnings that occurred from the FCP side, e.g. Dataset import errors.
* FL server logs (for NVIDIA FLARE runs)
* FL client logs (for NVIDIA FLARE runs)
  * Each federated client's logs will appear separately
* Client-specific logs (for all other run types)

### Troubleshooting Code Runs

**Error Message that Usage Limit Has Been Exceeded**

If you get an error message indicating that the usage limit has been exceeded, your administrator has set usage limits on the number of input rows a workgroup can process per model within a certain timeframe. Getting this message means that the entire run has been cancelled. Please contact your administrator for more details and help with resolving the issue.

## Viewing a Code Run's Configuration

To get an object's configuration, make sure you are on the page containing the original object you would like to view the configuration of. In the box where your original object is, there should be a row for each version. Navigate to the version you would like to view the configuration for and select the three-dot menu button, shown below:

![](/files/903f8d8b02de3537a785b7355db65dd33f4bf44c)

The menu button is on the right-hand side of the row, click it to view a new menu. The new menu should have an option to show that object's configuration, click on that to see the object's configuration.

For Code Objects and Code Runs, if you chose the Use VM Pool option, you will use the pool that was indicated during the Code Object or Code Run configurations.  Selecting this option shows the resources, including the number of VMs and vCPUs that will be allocated, as well as the amount of RAM, the size of the disk, the number of GPUs, the GPU type/mode&#x6C;*,* and the amount of VRAM.

## Deleting a Code Run

Follow these steps to delete a code run.

{% stepper %}
{% step %}

### Open the Code Runs page

Go to the page that lists your code runs.
{% endstep %}

{% step %}

### Find the code run

If needed, use the search fields at the top right.

* Use **Search Name** to search by code run name.
* Use **Search Description** to search by code run description.

Find the code run you want to delete.
{% endstep %}

{% step %}

### Open the menu for the code run

Select the three-dot menu on the right side of the row, shown below.

![](/files/d6d3efbded53ff3765ccd54d866cfef8630e6c3c)
{% endstep %}

{% step %}

### Remove the code run

Select **Remove code run**.
{% endstep %}
{% endstepper %}
