Skip to content

add speos simulation service #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ classifiers=[
"Operating System :: OS Independent",
]
dependencies=[
"ansys-optics-speos-grpcapi==4",
"ansys-optics-speos-grpcapi>=4,<5",
"grpcio-tools",
]

Expand Down
14 changes: 14 additions & 0 deletions tests/assets/LG_50M_Colorimetric_short.sv5/Blue Spectrum.spectrum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
OPTIS - Spectrum file v1.0
Blackbody at 5200.0 K
11
380 0
455 0
460 100
490 100
495 0
550 0
600 0
650 0
700 0
750 0
780 0
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/assets/LG_50M_Colorimetric_short.sv5/Red Spectrum.spectrum
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
OPTIS - Spectrum file v1.0
SpectreRouge
9
380 0
450 0
500 0
595 0
600 100
630 100
635 0
750 0
780 0
2 changes: 1 addition & 1 deletion tests/local_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"SpeosServerOnDocker": true,
"SpeosContainerName" : "pyoptics_speos-rpc",
"SpeosServerPort": 50051
}
}
74 changes: 74 additions & 0 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""This module allows pytest to perform unit testing.

Usage:
.. code::
$ pytest
$ pytest -vx

With coverage.
.. code::
$ pytest --cov ansys.pyoptics.speos

"""
import os

import ansys.api.speos.simulation.v1.simulation_pb2 as simulation__v1__pb2
import ansys.api.speos.simulation.v1.simulation_pb2_grpc as simulation__v1__pb2_grpc

from ansys.pyoptics import speos
from conftest import config, test_path
from helper import does_file_exist, remove_file


def test_simulation():
# Stub on simulation manager
simulation_manager_stub = speos.get_stub_insecure_channel(
port=config.get("SpeosServerPort"), stub_type=simulation__v1__pb2_grpc.SpeosSimulationsManagerStub
)

# Stub on simulation
simulation_stub = speos.get_stub_insecure_channel(
port=config.get("SpeosServerPort"), stub_type=simulation__v1__pb2_grpc.SpeosSimulationStub
)

# Create a new simulation on the server
guid_simu = simulation_manager_stub.Create(simulation__v1__pb2.Create_Request())

# Get input file path and load it
speos_simulation_name = "LG_50M_Colorimetric_short.sv5"
folder_path = os.path.join(test_path, speos_simulation_name)
speos_simulation_full_path = os.path.join(folder_path, speos_simulation_name)

load_request = simulation__v1__pb2.Load_Request()
load_request.guid = guid_simu.guid
load_request.input_file_path = speos_simulation_full_path

simulation_stub.Load(load_request)

# GetName
get_name_request = simulation__v1__pb2.GetName_Request()
get_name_request.guid = guid_simu.guid
get_name_response = simulation_stub.GetName(get_name_request)

assert get_name_response.name == "ASSEMBLY1.DS (0)"

# Get Results list
get_results_request = simulation__v1__pb2.GetResults_Request()
get_results_request.guid = guid_simu.guid

get_results_response = simulation_stub.GetResults(get_results_request)

# Run the simulation
run_request = simulation__v1__pb2.Run_Request()
run_request.guid = guid_simu.guid
simulation_stub.Run(run_request)

# Check results has been pushed
for result in get_results_response.results_paths:
assert does_file_exist(result)
remove_file(result)
assert not does_file_exist(result)

delete_request = simulation__v1__pb2.Delete_Request()
delete_request.guid = guid_simu.guid
simulation_manager_stub.Delete(delete_request)