Download this example
Download this example as a Jupyter Notebook or as a Python script. All assets used in the examples can be downloaded as a ZIP archive.
How to open result#
This tutorial demonstrates how to open and review results using workflow method.
Prerequisites#
Perform imports#
[1]:
import os
from pathlib import Path
from ansys.speos.core import Project, Speos, launcher
from ansys.speos.core.generic.version_checker import server_version_checker
from ansys.speos.core.kernel.client import (
default_docker_channel,
)
from ansys.speos.core.simulation import SimulationDirect
Define constants#
Constants help ensure consistency and avoid repetition throughout the example.
[2]:
HOSTNAME = "localhost"
GRPC_PORT = 50098 # Be sure the Speos GRPC Server has been started on this port.
FILE_NAME = "LG_50M_Colorimetric_short.sv5"
RESULT_NAME = "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp"
USE_DOCKER = True # Set to False if you're running this example locally as a Notebook.
USE_GPU = False
Model Setup#
Load assets#
The assets used to run this example are available in the PySpeos repository on GitHub.
Note: Make sure you have downloaded simulation assets and set
assets_data_pathto point to the assets folder.
[3]:
if USE_DOCKER: # Running on the remote server.
assets_data_path = Path("/app") / "assets"
else:
assets_data_path = Path("/path/to/your/download/assets/directory")
Connect to the RPC Server#
This Python client connects to a server where the Speos engine is running as a service. In this example, the server and client are the same machine.
[4]:
if USE_DOCKER:
speos = Speos(channel=default_docker_channel())
else:
speos = launcher.launch_local_speos_rpc_server(port=GRPC_PORT)
/home/runner/work/pyspeos/pyspeos/.venv/lib/python3.14/site-packages/ansys/tools/common/cyberchannel.py:201: UserWarning: Starting gRPC client without TLS on localhost:50098. This is INSECURE. Consider using a secure connection.
warn(f"Starting gRPC client without TLS on {target}. This is INSECURE. Consider using a secure connection.")
Create project from a Speos file#
The Project class is instantiated by passing a Speos instance and the name of the Speos project file.
[5]:
p = Project(
speos=speos,
path=str(assets_data_path / FILE_NAME / FILE_NAME),
)
print(p)
{
"name": "LG_50M_Colorimetric_short",
"description": "From Speos file: /app/assets/LG_50M_Colorimetric_short.sv5/LG_50M_Colorimetric_short.sv5",
"part_guid": "50b4697d-a353-4ffa-899a-f9c3100da5f9",
"sources": [
{
"name": "Dom Source 2 (0) in SOURCE2",
"metadata": {
"UniqueId": "7f02e828-d0bb-4db5-ab1d-fb496a584217"
},
"source_guid": "fc16fd63-b0de-4779-aae1-e70323aa818f",
"display_name": "",
"description": "",
"source": {
"name": "Dom Source 2 (0) in SOURCE2",
"surface": {
"radiant_flux": {
"radiant_value": 6.590041607465698
},
"intensity_guid": "dcfbff3c-cafb-4581-a586-db9f697b063e",
"exitance_constant": {
"geo_paths": [
{
"geo_path": "Solid Body in SOURCE2:2920204960/Face in SOURCE2:222",
"reverse_normal": false
}
]
},
"spectrum_guid": "ee95911b-df38-429a-b3c9-8b9413271a49",
"intensity": {
"cos": {
"N": 1.0,
"total_angle": 180.0
},
"name": "",
"description": "",
"metadata": {}
},
"spectrum": {
"library": {
"file_uri": "/app/assets/LG_50M_Colorimetric_short.sv5/Red Spectrum.spectrum"
},
"name": "",
"description": "",
"metadata": {}
}
},
"description": "",
"metadata": {}
}
},
{
"name": "Surface Source (0) in SOURCE1",
"metadata": {
"UniqueId": "c3572fdc-5dd6-4037-b434-15ad184e06c4"
},
"source_guid": "945c0f20-d1e8-45f7-87df-9a67d8e0ece4",
"display_name": "",
"description": "",
"source": {
"name": "Surface Source (0) in SOURCE1",
"surface": {
"radiant_flux": {
"radiant_value": 9.290411220389682
},
"intensity_guid": "55d900b5-92ea-447f-a7be-ffbbd61ee252",
"exitance_constant": {
"geo_paths": [
{
"geo_path": "Solid Body in SOURCE1:2494956811/Face in SOURCE1:187",
"reverse_normal": false
}
]
},
"spectrum_guid": "487be631-aa8e-4629-9375-2f284efafcf0",
"intensity": {
"cos": {
"N": 1.0,
"total_angle": 180.0
},
"name": "",
"description": "",
"metadata": {}
},
"spectrum": {
"library": {
"file_uri": "/app/assets/LG_50M_Colorimetric_short.sv5/Blue Spectrum.spectrum"
},
"name": "",
"description": "",
"metadata": {}
}
},
"description": "",
"metadata": {}
}
}
],
"sensors": [
{
"name": "Dom Irradiance Sensor (0)",
"metadata": {
"UniqueId": "43397e73-6ac6-476c-8e40-3b74c83eb818"
},
"sensor_guid": "c3ea436f-6ceb-4a3e-87a1-65455babedd8",
"result_file_name": "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0)",
"display_name": "",
"description": "",
"sensor": {
"irradiance_sensor_template": {
"sensor_type_colorimetric": {
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 25
}
},
"illuminance_type_planar": {},
"dimensions": {
"x_start": -20.0,
"x_end": 20.0,
"x_sampling": 500,
"y_start": -20.0,
"y_end": 20.0,
"y_sampling": 500
},
"axis_system": [
-42.0,
2.0,
5.0,
0.0,
1.0,
0.0,
0.0,
0.0,
-1.0,
-1.0,
0.0,
0.0
],
"layer_type_source": {},
"integration_direction": [
1.0,
-0.0,
-0.0
],
"ray_file_type": "RayFileNone"
},
"name": "Dom Irradiance Sensor (0)",
"description": "",
"metadata": {}
}
}
],
"simulations": [
{
"name": "ASSEMBLY1.DS (0)",
"metadata": {
"UniqueId": "c0dfc384-f15d-4f4b-873c-b349bf6755e9"
},
"simulation_guid": "0bf60835-ba54-46c1-aaaa-6e5e4d4ccf13",
"sensor_paths": [
"Dom Irradiance Sensor (0)"
],
"source_paths": [
"Dom Source 2 (0) in SOURCE2",
"Surface Source (0) in SOURCE1"
],
"geometries": {
"geo_paths": []
},
"display_name": "",
"description": "",
"source_groups": [],
"simulation": {
"direct_mc_simulation_template": {
"geom_distance_tolerance": 0.05,
"max_impact": 100,
"weight": {
"minimum_energy_percentage": 0.005
},
"dispersion": true,
"colorimetric_standard": "CIE_1931",
"fast_transmission_gathering": false,
"ambient_material_uri": ""
},
"name": "ASSEMBLY1.DS (0)",
"metadata": {},
"description": "",
"scene_guid": "0ca94902-9956-4230-84cb-b147d2953f9c",
"simulation_path": "ASSEMBLY1.DS (0)",
"job_type": "CPU"
}
}
],
"materials": [
{
"name": "Material.1",
"metadata": {
"UniqueId": "1331e39c-93b4-4e6c-ae4b-c2980bcd6b0a"
},
"geometries": {
"geo_paths": [
"Solid Body in GUIDE:1379760262/Face in GUIDE:169"
]
},
"sop_guid": "c9f4016e-6be3-411a-b750-e0eb00d338bc",
"display_name": "",
"description": "",
"sop_guids": [],
"sop": {
"mirror": {
"reflectance": 100.0
},
"name": "",
"description": "",
"metadata": {}
}
},
{
"name": "Material.2",
"metadata": {
"UniqueId": "21614e56-e037-4268-8088-eba323648b08"
},
"vop_guid": "40a72e99-f037-4c0e-acf2-62bfc1227baa",
"geometries": {
"geo_paths": [
"Solid Body in GUIDE:1379760262"
]
},
"sop_guid": "b642da5a-393c-4e97-a6e4-54952108c6f5",
"display_name": "",
"description": "",
"sop_guids": [],
"vop": {
"optic": {
"index": 1.4,
"constringence": 60.0,
"absorption": 0.0
},
"name": "",
"description": "",
"metadata": {}
},
"sop": {
"optical_polished": {},
"name": "",
"description": "",
"metadata": {}
}
},
{
"name": "Material.3",
"metadata": {
"UniqueId": "0c28211d-302c-4f58-a048-11108cbcf7d0"
},
"vop_guid": "2d82f625-5283-48c2-9af4-c93dd69638ab",
"geometries": {
"geo_paths": [
"Solid Body in SOURCE2:2920204960",
"Solid Body in SOURCE1:2494956811"
]
},
"sop_guid": "c9f4016e-6be3-411a-b750-e0eb00d338bc",
"display_name": "",
"description": "",
"sop_guids": [],
"vop": {
"opaque": {},
"name": "",
"description": "",
"metadata": {}
},
"sop": {
"mirror": {
"reflectance": 100.0
},
"name": "",
"description": "",
"metadata": {}
}
},
{
"name": "Material.4",
"metadata": {
"UniqueId": "67f34e3a-7fa3-466b-8317-aea3607cff19"
},
"vop_guid": "5e138087-efed-4bb2-bd3e-03230ebd641e",
"display_name": "",
"description": "",
"sop_guids": [],
"vop": {
"optic": {
"index": 1.0,
"absorption": 0.0
},
"name": "",
"description": "",
"metadata": {}
}
}
],
"metadata": {},
"sub_scene_anchor_axis_system": [],
"scenes": []
}
Retrieve the simulation feature#
Use the method Project.find() to retrieve an instance of the SimulationDirect feature.
[6]:
sim = p.find(name=".*", name_regex=True, feature_type=SimulationDirect)[0]
Run simulation#
The simulation can be run using either the CPU or with GPU acceleration. The following cell shows how Python is used to assign the appropriate method to run_sim.
[7]:
run_sim = sim.compute_GPU if USE_GPU else sim.compute_CPU
results = run_sim() # run the simulation
print(results)
[upload_response {
info {
uri: "7e61ba63-6deb-470e-9aae-f13291987fc7"
file_name: "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp"
file_size: 1795332
}
}
, upload_response {
info {
uri: "9df0eed7-af34-428f-83e5-17eff60cf142"
file_name: "ASSEMBLY1.DS (0).html"
file_size: 252050
}
}
]
Postprocessing#
Open the results:#
Display one result as image.
A full path can be given, or the name of the result.
[8]:
# Method available only on Windows OS or with Speos 2026 R1.2 or higher,
# which supports opening XMP results as images regardless of the OS.
if os.name == "nt" or server_version_checker.is_version_supported(2026, 1, 2):
from ansys.speos.core.workflow.open_result import open_result_image
open_result_image(simulation_feature=sim, result_name=RESULT_NAME)
Display the image#
Display one result in a result viewer.
A full path can be given, or the name of the result.
[9]:
if os.name == "nt":
from ansys.speos.core.workflow.open_result import open_result_in_viewer
open_result_in_viewer(
simulation_feature=sim,
result_name=RESULT_NAME,
)
Export the XMP result to PNG image#
Export one result to a PNG image file.
A full path can be given, or the name of the result.
[10]:
from ansys.speos.core.workflow.open_result import export_xmp_to_image
[11]:
exported_image = export_xmp_to_image(simulation_feature=sim, result_name=RESULT_NAME)
if exported_image.HasField("path"):
print(exported_image.path) # Local path of the exported image on the server.
elif exported_image.HasField("upload_response"):
print(
exported_image.upload_response.info.uri
) # URI of the exported image on the server, which can be used to download the file.
d1a36a5e-cbd0-41d4-899f-e97399388ed1
[12]:
speos.close()
[12]:
True
Download this example
Download this example as a Jupyter Notebook or as a Python script. All assets used in the examples can be downloaded as a ZIP archive.