.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/00_basic_simai_ex/01-build_model.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_00_basic_simai_ex_01-build_model.py: .. _ref_basic_build_model: Building a SimAI Model ============================================ This example demonstrates how to configure a SimAI model with inputs, outputs, global coefficients, and domain of analysis, then start the model training process. Before you begin ------------------------------------------- - Complete ":ref:`ref_basic_create_project_upload_data`" to create a project with training data. - Ensure all training data in your project are ready (processed successfully). - Know the names of surfaces and boundary conditions in your training data. - Determine which global coefficients you want to calculate. .. GENERATED FROM PYTHON SOURCE LINES 42-44 Import necessary libraries ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 44-54 .. code-block:: Python import ansys.simai.core as asc from ansys.simai.core.data.model_configuration import ( DomainOfAnalysis, GlobalCoefficientDefinition, ModelConfiguration, ModelInput, ModelOutput, ) .. GENERATED FROM PYTHON SOURCE LINES 55-58 Configure your settings ------------------------------------------- Update these variables with your specific settings: .. GENERATED FROM PYTHON SOURCE LINES 58-62 .. code-block:: Python ORGANIZATION_NAME = "" # Replace with your organization name PROJECT_NAME = "" # Replace with your project name .. GENERATED FROM PYTHON SOURCE LINES 63-66 Initialize the client and get the project ------------------------------------------- Connect to SimAI: .. GENERATED FROM PYTHON SOURCE LINES 66-69 .. code-block:: Python simai_client = asc.SimAIClient(organization=ORGANIZATION_NAME) .. GENERATED FROM PYTHON SOURCE LINES 70-71 Retrieve the project by name: .. GENERATED FROM PYTHON SOURCE LINES 71-75 .. code-block:: Python project = simai_client.projects.get(name=PROJECT_NAME) print(f"Using existing project: {PROJECT_NAME}") .. GENERATED FROM PYTHON SOURCE LINES 76-80 Configure model inputs ------------------------------------------- Define which surfaces and boundary conditions the model will use as inputs. Replace the placeholder names with the actual names from your training data: .. GENERATED FROM PYTHON SOURCE LINES 80-86 .. code-block:: Python model_input = ModelInput( surface=[""], # List of surface names to use as input boundary_conditions=[""], # List of boundary condition names ) .. GENERATED FROM PYTHON SOURCE LINES 87-91 Configure model outputs ------------------------------------------- Define which surfaces the model will predict. These are typically the same surfaces as the inputs, but you can specify different ones: .. GENERATED FROM PYTHON SOURCE LINES 91-96 .. code-block:: Python model_output = ModelOutput( surface=[""], # List of surface names to predict ) .. GENERATED FROM PYTHON SOURCE LINES 97-107 Define global coefficients ------------------------------------------- Global coefficients are scalar values calculated from the prediction results. They can be used to extract key performance indicators from your simulations. In this example, we calculate the integral of a field called "Photometric". You can define multiple global coefficients with different formulas. Available locations: ``"points"`` or ``"cells"``. .. GENERATED FROM PYTHON SOURCE LINES 107-116 .. code-block:: Python global_coefficients = [ GlobalCoefficientDefinition( name="", # Name for this global coefficient formula="integral(Photometric)", # Formula to calculate the global coefficient value gc_location="points", # Calculate at points (or at "cells") ) ] .. GENERATED FROM PYTHON SOURCE LINES 117-129 Define domain of analysis ------------------------------------------- The domain of analysis specifies the spatial extent that the model will analyze. Values can be specified as absolute dimensions or relative to minimum values. Format: reference_type, min_value, max_value - ``reference_type``: ``"relative_to_min"``, ``"relative_to_max"``, ``"relative_to_center``" or ``"absolute"``. - ``min_value``: minimum dimension value. - ``max_value``: maximum dimension value. You can find appropriate values by analyzing your training data in the SimAI platform. .. GENERATED FROM PYTHON SOURCE LINES 129-136 .. code-block:: Python doa = DomainOfAnalysis( length=("relative_to_min", 0.102, 1.219), # Length bounds width=("relative_to_min", 0.102, 1.219), # Width bounds height=("relative_to_min", 0.134, 1.61), # Height bounds ) .. GENERATED FROM PYTHON SOURCE LINES 137-147 Create model configuration ------------------------------------------- Combine all the configuration elements into a ModelConfiguration object. Build presets determine the training duration: - ``debug``: Quick training for testing. - ``1_day``: Short training. - ``2_days``: Standard training (recommended). - ``7_days``: Maximum training for best accuracy. .. GENERATED FROM PYTHON SOURCE LINES 147-159 .. code-block:: Python mdl_conf = ModelConfiguration( project=project, # Project containing the training data build_preset="1_day", # Duration of the build build_on_top=False, # Start training from scratch input=model_input, # Model input configuration output=model_output, # Model output configuration global_coefficients=global_coefficients, # Global coefficient definitions domain_of_analysis=doa, # Domain of analysis bounds ) .. GENERATED FROM PYTHON SOURCE LINES 160-163 Verify and build the model ------------------------------------------- Before building, check if the project meets all requirements for training: .. GENERATED FROM PYTHON SOURCE LINES 163-177 .. code-block:: Python if project.is_trainable(): print("Project is trainable. Starting model build...") new_model = simai_client.models.build(mdl_conf) print(f"Model build started with ID: {new_model.id}") print( "The model will take some time to train. You can monitor its progress in the SimAI platform." ) else: print("Project is not trainable. Please check the following:") print("- All training data must be processed successfully.") print("- The project must have enough training data.") print("- All required surfaces and boundary conditions must exist in the training data.") .. GENERATED FROM PYTHON SOURCE LINES 178-185 Next steps ------------------------------------------- Once your model is trained, you can: - Monitor the training progress in the SimAI platform. - Run predictions on new geometries: :ref:`ref_basic_run_predictions`. - Evaluate model performance using validation data. .. _sphx_glr_download__examples_00_basic_simai_ex_01-build_model.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01-build_model.ipynb <01-build_model.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01-build_model.py <01-build_model.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01-build_model.zip <01-build_model.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_