.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/02_generative_design_ex/04-project_geometries.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_02_generative_design_ex_04-project_geometries.py: .. _ref_project_geometries: Projecting Geometries onto a Model ================================== This example demonstrates how to project a geometry onto a trained GeomAI model and retrieve its latent parameters. Before you begin ---------------- - Complete ":ref:`ref_build_model`" to train a GeomAI model. - Ensure that the model training has completed successfully and that its workspace is available. - Prepare a geometry file in ``VTP`` or ``STL`` format. .. GENERATED FROM PYTHON SOURCE LINES 42-44 Import necessary libraries --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. code-block:: Python import ansys.simai.core as asc from ansys.simai.core.data.geomai.predictions import GeomAIPredictionConfiguration .. GENERATED FROM PYTHON SOURCE LINES 49-52 Configure your settings ----------------------- Update these variables with your specific settings: .. GENERATED FROM PYTHON SOURCE LINES 52-57 .. code-block:: Python ORGANIZATION = "my_organization" # Replace with your organization name WORKSPACE_NAME = "new-bracket-project #1" # Replace with your trained model workspace GEOMETRY_FILE = "./td/bracket_264.vtp" # VTP or STL file to project .. GENERATED FROM PYTHON SOURCE LINES 58-60 Initialize the client and get the workspace ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 60-66 .. code-block:: Python simai_client = asc.SimAIClient(organization=ORGANIZATION) geomai_client = simai_client.geomai workspace = geomai_client.workspaces.get(name=WORKSPACE_NAME) print(f"Using workspace: {workspace.name}") .. GENERATED FROM PYTHON SOURCE LINES 67-69 Upload a geometry ----------------- .. GENERATED FROM PYTHON SOURCE LINES 69-75 .. code-block:: Python print("Uploading geometry...") geometry = geomai_client.geometries.upload(GEOMETRY_FILE) geometry.wait() print(f"Uploaded {geometry.name} with id {geometry.id}") .. GENERATED FROM PYTHON SOURCE LINES 76-80 Project the geometry onto the workspace model ---------------------------------------------- The projection operation is idempotent: if this geometry has already been projected onto the model, the existing projection is returned. .. GENERATED FROM PYTHON SOURCE LINES 80-89 .. code-block:: Python print("Running projection...") projection = geometry.run_projection(workspace) projection.wait() latent_parameters = projection.get_latent_parameters() print(f"Projection {projection.id} on model {projection.workspace_id}") print(f"Retrieved {len(latent_parameters)} latent parameters") .. GENERATED FROM PYTHON SOURCE LINES 90-94 Reconstruct the geometry from its latent parameters --------------------------------------------------- The latent parameters can be passed to a prediction configuration to regenerate the geometry from the model. .. GENERATED FROM PYTHON SOURCE LINES 94-107 .. code-block:: Python config = GeomAIPredictionConfiguration( latent_params=latent_parameters, ) prediction = geomai_client.predictions.run(config, workspace) print(f"Prediction {prediction.id} started...") prediction.wait() output_path = f"reconstructed_{prediction.id}.vtp" geomai_client.predictions.download(prediction.id, output_path) print(f"Saved reconstructed geometry to {output_path}") .. GENERATED FROM PYTHON SOURCE LINES 108-112 Look up an existing projection ------------------------------------- Retrieve a projection without starting a new computation. The result is ``None`` if the geometry has not been projected onto this workspace's model. .. GENERATED FROM PYTHON SOURCE LINES 112-121 .. code-block:: Python print("\nLooking up an existing projection...") existing_projection = geometry.get_projection(workspace) if existing_projection is None: print("Geometry has not yet been projected onto this workspace's model.") else: print(f"Existing projection: {existing_projection.id}") print(f"First three parameters: {existing_projection.get_latent_parameters(n=3)}") .. GENERATED FROM PYTHON SOURCE LINES 122-124 List projections in the workspace ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 124-130 .. code-block:: Python projections = workspace.list_projections() print(f"\n{len(projections)} projections in {workspace.name}") for proj in projections: print(f"- {proj.id}") .. GENERATED FROM PYTHON SOURCE LINES 131-137 Next steps ---------- To explore the model further, you can: - Generate geometries from latent parameters. - Interpolate between geometries: :ref:`ref_interpolate_geometries`. .. _sphx_glr_download__examples_02_generative_design_ex_04-project_geometries.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 04-project_geometries.ipynb <04-project_geometries.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 04-project_geometries.py <04-project_geometries.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 04-project_geometries.zip <04-project_geometries.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_