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:188: 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": "100b9f61-6d55-44c1-9e88-16f1f405f8cf",
"sources": [
{
"name": "Dom Source 2 (0) in SOURCE2",
"metadata": {
"UniqueId": "da360363-b5a2-4484-895a-1095ed8de6bb"
},
"source_guid": "a9d0ec1f-3114-4f4e-9a6b-3c556dd59bdc",
"display_name": "",
"description": "",
"source": {
"name": "Dom Source 2 (0) in SOURCE2",
"surface": {
"radiant_flux": {
"radiant_value": 6.590041607465698
},
"intensity_guid": "758d76a6-abd6-46b0-ba7a-6258adce369e",
"exitance_constant": {
"geo_paths": [
{
"geo_path": "Solid Body in SOURCE2:2920204960/Face in SOURCE2:222",
"reverse_normal": false
}
]
},
"spectrum_guid": "581d7e05-8cc4-4b60-96b9-8eeb5999226b",
"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": "772e3316-0499-4bdb-95df-fb6c694b8887"
},
"source_guid": "13852685-67f9-4966-a543-df9f1160d624",
"display_name": "",
"description": "",
"source": {
"name": "Surface Source (0) in SOURCE1",
"surface": {
"radiant_flux": {
"radiant_value": 9.290411220389682
},
"intensity_guid": "0b0225a3-5020-4c09-8eae-df2e53d60907",
"exitance_constant": {
"geo_paths": [
{
"geo_path": "Solid Body in SOURCE1:2494956811/Face in SOURCE1:187",
"reverse_normal": false
}
]
},
"spectrum_guid": "db467ac0-8b93-47a0-b59a-55d0392a749e",
"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": "34fd4cc1-0377-455b-ae81-3c601f447cf5"
},
"sensor_guid": "42166c9c-4af4-43f7-b1a4-9cc9a14aec43",
"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": "bbb342a6-82b6-4fa3-afbd-5c702c2dbe3c"
},
"simulation_guid": "957e19c5-eac2-4268-95b0-e7f6033c5637",
"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": "5fec2fd8-684f-4488-a8a4-ddffe893e6f3",
"simulation_path": "ASSEMBLY1.DS (0)",
"job_type": "CPU"
}
}
],
"materials": [
{
"name": "Material.1",
"metadata": {
"UniqueId": "9aaa9548-786e-4d39-bc59-c0cfad0d6337"
},
"geometries": {
"geo_paths": [
"Solid Body in GUIDE:1379760262/Face in GUIDE:169"
]
},
"sop_guid": "95272db3-2cc0-4e81-837f-367561a0d9c7",
"display_name": "",
"description": "",
"sop_guids": [],
"sop": {
"mirror": {
"reflectance": 100.0
},
"name": "",
"description": "",
"metadata": {}
}
},
{
"name": "Material.2",
"metadata": {
"UniqueId": "225c2103-4126-474d-bf62-7a8133899536"
},
"vop_guid": "ac2fde7a-5d91-4821-ac89-d7cdd9eebaed",
"geometries": {
"geo_paths": [
"Solid Body in SOURCE2:2920204960",
"Solid Body in SOURCE1:2494956811"
]
},
"sop_guid": "95272db3-2cc0-4e81-837f-367561a0d9c7",
"display_name": "",
"description": "",
"sop_guids": [],
"vop": {
"opaque": {},
"name": "",
"description": "",
"metadata": {}
},
"sop": {
"mirror": {
"reflectance": 100.0
},
"name": "",
"description": "",
"metadata": {}
}
},
{
"name": "Material.3",
"metadata": {
"UniqueId": "4c08aaf7-7e19-4259-a31b-7cca4859b99f"
},
"vop_guid": "40b768bd-53c9-44c2-9ef3-245479212b80",
"geometries": {
"geo_paths": [
"Solid Body in GUIDE:1379760262"
]
},
"sop_guid": "7b512d90-e734-42bb-bc25-58739a9b0e41",
"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.4",
"metadata": {
"UniqueId": "27f11c36-cd1f-40b9-8464-dd718e4e305b"
},
"vop_guid": "04214777-74e6-4530-a70d-26b0c77de4e1",
"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: "c2c8055e-3b2b-45e3-952f-990d9e952f6a"
file_name: "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp"
file_size: 1795891
}
}
, upload_response {
info {
uri: "1689fd9f-4efa-4a59-8f2c-025e856da1c4"
file_name: "ASSEMBLY1.DS (0).html"
file_size: 248282
}
}
]
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.
9b4af5e2-82f2-4938-b10c-e2ec9ee94a7b
[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.