Skip to content
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

Add Ansys product version to Additive init #170

Merged
merged 7 commits into from
Nov 21, 2023
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 @@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
[project]
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
name = "ansys-additive-core"
version = "0.17.dev2"
version = "0.17.dev3"
description = "A Python client for the Ansys Additive service"
readme = "README.rst"
requires-python = ">=3.9,<4"
Expand Down
31 changes: 15 additions & 16 deletions src/ansys/additive/core/additive.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import ansys.additive.core.misc as misc
from ansys.additive.core.porosity import PorosityInput, PorositySummary
from ansys.additive.core.progress_logger import ProgressLogger
from ansys.additive.core.server_connection import ServerConnection
from ansys.additive.core.server_connection import DEFAULT_PRODUCT_VERSION, ServerConnection
from ansys.additive.core.simulation import SimulationError
from ansys.additive.core.single_bead import SingleBeadInput, SingleBeadSummary
from ansys.additive.core.thermal_history import ThermalHistoryInput, ThermalHistorySummary
Expand All @@ -61,11 +61,6 @@ class Additive:
List of connection definitions for servers. The list may be a combination of strings and
connected :class:`grpc.Channel <grpc.Channel>` objects. Strings use the format
``host:port`` to specify the server IPv4 address.
channel: grpc.Channel, default: None
gRPC channel connection to use for communicating with the server. If the
default ``None`` is used, a connection is established using the host and port
parameters. This parameter is ignored if the ``server_connections`` parameter
is other than ``None``.
host: str, default: None
Host name or IPv4 address of the server. This parameter is ignored if the
``server_channels`` or ``channel`` parameters is other than ``None``.
Expand All @@ -77,6 +72,11 @@ class Additive:
the Additive portion of the Ansys Structures package must be installed.
This parameter is ignored if the ``server_connections``, ``channel``, or ``host``
parameter is other than ``None``.
product_version: str
Version of the Ansys product installation in the form ``"YYR"``, where ``YY``
is the two-digit year and ``R`` is the release number. For example, the release
2024 R1 would be specified as ``241``. This parameter is only applicable in
PyPIM environments and on localhost.
log_level: str, default: "INFO"
Minimum severity level of messages to log.
log_file: str, default: ""
Expand All @@ -88,10 +88,10 @@ class Additive:
def __init__(
self,
server_connections: list[str | grpc.Channel] = None,
channel: grpc.Channel | None = None,
host: str | None = None,
port: int = DEFAULT_ADDITIVE_SERVICE_PORT,
nservers: int = 1,
product_version: str = DEFAULT_PRODUCT_VERSION,
log_level: str = "INFO",
log_file: str = "",
) -> None:
Expand All @@ -100,7 +100,7 @@ def __init__(
self._log.debug("Logging set to %s", log_level)

self._servers = Additive._connect_to_servers(
server_connections, channel, host, port, nservers, self._log
server_connections, host, port, nservers, product_version, self._log
)

# Setup data directory
Expand Down Expand Up @@ -134,10 +134,10 @@ def _create_logger(log_file, log_level) -> logging.Logger:
@staticmethod
def _connect_to_servers(
server_connections: list[str | grpc.Channel] = None,
channel: grpc.Channel | None = None,
host: str | None = None,
port: int = DEFAULT_ADDITIVE_SERVICE_PORT,
nservers: int = 1,
product_version: str = DEFAULT_PRODUCT_VERSION,
log: logging.Logger = None,
) -> list[ServerConnection]:
"""Connect to Additive servers, starting them if necessary."""
Expand All @@ -148,15 +148,13 @@ def _connect_to_servers(
connections.append(ServerConnection(channel=target, log=log))
else:
connections.append(ServerConnection(addr=target, log=log))
elif channel:
connections.append(ServerConnection(channel=channel, log=log))
elif host:
connections.append(ServerConnection(addr=f"{host}:{port}", log=log))
elif os.getenv("ANSYS_ADDITIVE_ADDRESS"):
connections.append(ServerConnection(addr=os.getenv("ANSYS_ADDITIVE_ADDRESS"), log=log))
else:
for _ in range(nservers):
connections.append(ServerConnection(log=log))
connections.append(ServerConnection(product_version=product_version, log=log))

return connections

Expand Down Expand Up @@ -198,6 +196,7 @@ def simulate(
list is returned.
"""
if type(inputs) is not list:
print("Single input")
return self._simulate(inputs, self._servers[0], show_progress=True)
else:
self._validate_inputs(inputs)
Expand Down Expand Up @@ -258,7 +257,7 @@ def _simulate(
"""
logger = None
if show_progress:
logger = ProgressLogger("Simulation")
logger = ProgressLogger("Simulation") # pragma: no cover

if input.material == AdditiveMaterial():
raise ValueError("A material is not assigned to the simulation input")
Expand All @@ -273,7 +272,7 @@ def _simulate(
for response in server.simulation_stub.Simulate(request):
if response.HasField("progress"):
if logger:
logger.log_progress(response.progress)
logger.log_progress(response.progress) # pragma: no cover
if response.progress.state == ProgressState.PROGRESS_STATE_ERROR:
raise Exception(response.progress.message)
if response.HasField("melt_pool"):
Expand Down Expand Up @@ -449,15 +448,15 @@ def _simulate_thermal_history(
):
remote_geometry_path = response.remote_file_name
if logger:
logger.log_progress(response.progress)
logger.log_progress(response.progress) # pragma: no cover
if response.progress.state == ProgressState.PROGRESS_STATE_ERROR:
raise Exception(response.progress.message)

request = input._to_simulation_request(remote_geometry_path=remote_geometry_path)
for response in server.simulation_stub.Simulate(request):
if response.HasField("progress"):
if logger:
logger.log_progress(response.progress)
logger.log_progress(response.progress) # pragma: no cover
if (
response.progress.state == ProgressState.PROGRESS_STATE_ERROR
and "WARN" not in response.progress.message
Expand Down
21 changes: 10 additions & 11 deletions src/ansys/additive/core/parametric_study/parametric_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from typing import List, Optional, Union
from __future__ import annotations

import numpy as np
import pandas as pd
Expand All @@ -47,31 +47,30 @@ class ParametricRunner:
def simulate(
df: pd.DataFrame,
additive: Additive,
type: Optional[List[SimulationType]] = None,
priority: Optional[int] = None,
) -> List[Union[MicrostructureSummary, PorositySummary, SingleBeadSummary]]:
"""Run the simulations in the parametric study with
``SimulationStatus.PENDING`` in the ``ColumnNames.STATUS`` column.
type: list[SimulationType] = None,
priority: int = None,
) -> list[SingleBeadSummary, PorositySummary, MicrostructureSummary]:
"""Run the simulations in the parametric study with ``Status`` equal to ``Pending``.

Execution order is determined by the values in the ``ColumnNames.PRIORITY`` column.
Execution order is determined by the ``Priority`` value assigned to the simulations.
Lower values are interpreted as having higher priority and are run first.

Parameters
----------
df : pd.DataFrame
Parametric study data frame.
additive: :class:`Additive <ansys.additive.core.additive.Additive>`
additive : Additive
Additive service connection to use for running simulations.
type : list, None
type : list, default: None
List of the simulation types to run. The default is ``None``, in which case all
simulation types are run.
priority : int, None
priority : int, default: None
Priority of simulations to run. The default is ``None``, in which case
all priorities are run.

Returns
-------
List[Union[MicrostructureSummary, PorositySummary, SingleBeadSummary]]
list[SingleBeadSummary, PorositySummary, MicrostructureSummary]
List of simulation summaries.
"""
if type is None:
Expand Down
Loading