Creating a new Python Code Object using the Rhino FCP UI
Navigate to the Code (formerly Models) Page
Use the left-hand navigation menu to click the Code menu item
Add a New Code Object
Create a new model by clicking on the Create New Code Object button in the top-right corner
[Option 1] Python "Code Snippet": Use this option for basic Python scripts
Fill in the following fields within the Code Object creation modal:
- Code Object Type: Python Code
-
Details:
- Name: The name you would like to provide for your Code Object
- (Optional) Description: A description that will help you and others understand the nature of this Code Object
-
Data Schemas:
- Input Data Schema: The Data Schema 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.
- Output Data Schema:The Data Schema 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 Schemas.
-
Container details:
Here 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).
- Python and CUDA Versions, or conversely
-
Code: You can provide your code in one of the following formats:
-
Code snippet - Use this option for basic Python scripts.
Important information:-
Code Snippet automatically processes the input Dataset as a Pandas DataFrame, which is Ideal for simple data operations like feature extraction and normalization.
- The code automatically loads the content of your tabular data from
dataset.csv
into a Pandas DataFrame nameddf
. - The output Dataset is created from the same
df
object.
-
Code Snippet automatically processes the input Dataset as a Pandas DataFrame, which is Ideal for simple data operations like feature extraction and normalization.
- Standalone file - 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) - Use this option when your code includes multiple files. After uploading your files, you will need to define the Entry Point to be used to run your code.
-
Code snippet - Use this option for basic Python scripts.
- 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.
-
Container Base Image: This field enables you to specify a base image for your container to be built off of. This capability is enabled for all Python Code types except for Code Snippet which has two locked dependencies—
python:3.9.7-slim-bullseye
Click the Create New Code button to finish.
Not sure which Python Code Object type to Use?
Here is a bit more information on when to use each type:
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.
An Example, consider this Python code snippet:
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. Moreover, you're required to define the Container Base Image for your container, a crucial step if your code necessitates a specific environment – for instance, to support GPU operations.
Once you have provided all the necessary inputs, click "Create New Model" at the bottom of the dialog box. The FCP will now create a container image, in the background, based on your specifications, push it to your workgroup's ECR repository, and create a Model which you can then run.
Note: This can take significant time in some cases, depending on your requirements and selected container base image,
Creating a New Python Code Object Version using the Rhino FCP UI
To create a new version, make sure you are on the page containing the original object you would like to create a new version of. In the box where your original object is in the upper right-hand corner, you should see a + New Version button, like the one shown below:
Click that button and a new dialog should appear that will allow you to create a new version of your object.
Creating a New Version in Every Interface within the Rhino FCP UI
Below is a GIF showing all the interfaces within the Rhino FCP application where you can create a new Version. It displays the Schemas, Cohorts, and Models pages and the + New Version button you will press to create that new version of the schema, cohort, or model you are looking to create.
Creating a New Python Code Object using the Rhino SDK
Prerequisites
Before starting this process, you should have already:
- Created a Project using the Rhino SDK or UI
- Created an Input Data Schema using the Rhino SDK or UI
- [Optional] Created an Output Data Schema using the Rhino SDK or UI. If you choose not to create an output Data Schema, the system will auto-generate the Data Schema of the output for your Code
Import your Python Dependencies
import rhino_health as rh from rhino_health.lib.endpoints.code.code_objects_dataclass import ( CodeObject, CodeObjectCreateInput, CodeTypes, CodeRunType ) import getpass
Remember to change all lines with CHANGE_ME comments above them in all the blocks below!
Log into the Rhino SDK using your FCP Credentials
Your username will be the email address you log into the Rhino FCP platform with.
print("Logging In") # CHANGE_ME: MY_USERNAME my_username = "MY_USERNAME" session = rh.login(username=my_username, password=getpass.getpass()) print("Logged In")
Get Supporting FCP Information Needed to Create Your Code Object
At this point, you will need the name of your project, your input Data Schema name, optionally your output Data Schema name, and your Python code. You can also retrieve each object's UUID by following the instructions here: How do I retrieve a UUID for a Project, Collaborator, Schema, Dataset, Code Object's, or Code Run?
# CHANGE_ME: YOUR_FCP_PROJECT_NAME project = session.project.get_project_by_name('YOUR_FCP_PROJECT_NAME') # CHANGE_ME: INPUT_SCHEMA_NAME & Possibly Version Number too input_schema = session.project.get_data_schema_by_name('INPUT_SCHEMA_NAME', project_uid=project.uid, version=1) # CHANGE_ME: OUTPUT_SCHEMA_NAME & Possibly Version Number too output_schema = session.project.get_data_schema_by_name('OUTPUT_SCHEMA_NAME', project_uid=project.uid, version=1) # CHANGE_ME: PYTHON_CODE python_code = """PYTHON_CODE"""
Create Your Python Code Object
During the creation of your CodeObject
, you will provide it with various pieces of data similar to how a Code Object is created within the UI. You will give the CodeObject
a name, description, input_data_schema_uids
, output_data_schema_uids
, project_uid
, code_object_type
, and the config
where you will provide your Python code and other information dependent on your code run type.
[Option 1] CodeObject
with a default Code Run Type
code_object_params = CodeObjectCreateInput( # CHANGE_ME: CODE_OBJECT_NAME name = "CODE_OBJECT_NAME", # CHANGE_ME: CODE_OBJECT_DESCRIPTION description = "CODE_OBJECT_DESCRIPTION", input_data_schema_uids = [input_schema.uid],
# output_schema.uid or None to Infer Output Data Schema output_data_schema_uids = [output_schema.uid], project_uid = project.uid, code_object_type = CodeTypes.PYTHON_CODE, config = { "code_run_type": CodeRunType.DEFAULT, "python_code": python_code }
) code_object = session.code.create_code_object(code_object_params) print(f"Got Code Object '{code_object.name}' with UID {code_object.uid}")
[Option 2] CodeObject
with an Auto-Container Snippet Code Run Type
code_object_params = CodeObjectCreateInput( # CHANGE_ME: CODE_OBJECT_NAME name = "CODE_OBJECT_NAME", # CHANGE_ME: CODE_OBJECT_DESCRIPTION description = "CODE_OBJECT_DESCRIPTION", input_data_schema_uids = [input_schema.uid],
# output_schema.uid or None to Infer Output Data Schema output_data_schema_uids = [output_schema.uid], project_uid = project.uid, code_object_type = CodeTypes.PYTHON_CODE, config = { "code_run_type": CodeRunType.AUTO_CONTAINER_SNIPPET, "python_code": python_code }
) code_object = session.code.create_code_object(code_object_params) print(f"Got Code Object '{code_object.name}' with UID {code_object.uid}")
[Option 3] CodeObject
with an Auto-Container File Code Run Type
code_object_params = CodeObjectCreateInput( # CHANGE_ME: CODE_OBJECT_NAME name = "CODE_OBJECT_NAME", # CHANGE_ME: CODE_OBJECT_DESCRIPTION description = "CODE_OBJECT_DESCRIPTION", input_data_schema_uids = [input_schema.uid],
# output_schema.uid or None to Infer Output Data Schema output_data_schema_uids = [output_schema.uid], project_uid = project.uid, code_object_type = CodeTypes.PYTHON_CODE, config = { "code_run_type": CodeRunType.AUTO_CONTAINER_FILE, "python_code": python_code }
) code_object = session.code.create_code_object(code_object_params) print(f"Got Code Object '{code_object.name}' with UID {code_object.uid}")
If you have received an error or run into any issues throughout the process, please check out our community forums, or reach out to support@rhinohealth.com for more assistance.