.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/generative_design_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_generative_design_ex_01-build_model.py: .. _ref_build_model: Building a Generative Design Model ================================================ This example demonstrates how to configure a Generative Design model, start the model training process, and monitor the build progress. Before you begin ------------------------------------------- - Complete ":ref:`ref_create_project_upload_data`" to create a project with training data. - Ensure all training data in your project are ready (processed successfully). .. GENERATED FROM PYTHON SOURCE LINES 39-41 Import necessary libraries ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 41-45 .. code-block:: Python import ansys.simai.core as asc from ansys.simai.core.data.geomai.models import GeomAIModelConfiguration .. GENERATED FROM PYTHON SOURCE LINES 46-49 Configure your settings ------------------------------------------- Update these variables with your specific settings: .. GENERATED FROM PYTHON SOURCE LINES 49-55 .. code-block:: Python ORGANIZATION = "my_organization" # Replace with your organization name PROJECT_NAME = "new-bracket-project" # Replace with your project name NB_LATENT_PARAMS = 15 # Number of latent parameters (2-256) BUILD_PRESET = "default" # Options: "debug", "short", "default", "long" .. GENERATED FROM PYTHON SOURCE LINES 56-62 The ``BUILD_PRESET`` options correspond to: - ``"debug"``: Fast training for testing (very few epochs). - ``"short"``: Quick training with reduced accuracy. - ``"default"``: Balanced training time and quality. - ``"long"``: Longer training for best quality. .. GENERATED FROM PYTHON SOURCE LINES 65-68 Initialize the client and get the project ------------------------------------------- Connect to the instance: .. GENERATED FROM PYTHON SOURCE LINES 68-72 .. code-block:: Python simai_client = asc.SimAIClient(organization=ORGANIZATION) geomai_client = simai_client.geomai .. GENERATED FROM PYTHON SOURCE LINES 73-74 Retrieve the project by name: .. GENERATED FROM PYTHON SOURCE LINES 74-78 .. code-block:: Python project = geomai_client.projects.get(name=PROJECT_NAME) print(f"Using project: {project.name}") .. GENERATED FROM PYTHON SOURCE LINES 79-82 Verify project data are ready ------------------------------------------- Before building a model, ensure all training data are processed: .. GENERATED FROM PYTHON SOURCE LINES 82-90 .. code-block:: Python project_data = project.data() ready_data = [data for data in project_data if data.is_ready] print(f"Project has {len(ready_data)}/{len(project_data)} ready training data") if len(ready_data) < len(project_data): print("Warning: Some training data are not ready. Model may fail to build.") .. GENERATED FROM PYTHON SOURCE LINES 91-98 Configure the model ------------------------------------------- To define the configuration for your model, you can either specify the build preset or the number of epochs. To do so, instead of ``build_preset``, you can specify the number of epochs directly. Example: ``nb_epochs=100``. The number of latent parameters defines the complexity of the model's latent space; start with a small number (e.g., 10) and adjust based on your needs. .. GENERATED FROM PYTHON SOURCE LINES 98-105 .. code-block:: Python configuration = GeomAIModelConfiguration( build_preset=BUILD_PRESET, nb_latent_param=NB_LATENT_PARAMS, # Must be between 2 and 256 ) .. GENERATED FROM PYTHON SOURCE LINES 106-109 Build the model ------------------------------------------- Start the model training process: .. GENERATED FROM PYTHON SOURCE LINES 109-113 .. code-block:: Python model = geomai_client.models.build(project, configuration) print(f"Started build for model {model.id}") .. GENERATED FROM PYTHON SOURCE LINES 114-117 Wait for model training to complete ------------------------------------------- Monitor the training process and handle completion: .. GENERATED FROM PYTHON SOURCE LINES 117-127 .. code-block:: Python print("Waiting for model training to complete (this may take a while)...") while not model.wait(timeout=60): # Check every 60 seconds print(f"Model {model.id} is still training...") if model.has_failed: print(f"Model training failed: {model.failure_reason}") else: print(f"Model {model.id} trained successfully and is ready to use.") .. GENERATED FROM PYTHON SOURCE LINES 128-134 Next steps ------------------------------------------- Once your model is trained, you can: - Generate random geometries: :ref:`ref_generate_random_geometries` - Interpolate between geometries: :ref:`ref_interpolate_geometries` .. _sphx_glr_download__examples_generative_design_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 `_