Skip to content

Commit

Permalink
Merge branch 'main' into maint/activate_2d_meshing_tests_for_251
Browse files Browse the repository at this point in the history
  • Loading branch information
prmukherj authored Nov 19, 2024
2 parents f02f208 + b170c1c commit f2ceade
Show file tree
Hide file tree
Showing 202 changed files with 11,496 additions and 2,313 deletions.
6 changes: 3 additions & 3 deletions .ci/compare_flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ def compare_flobject():
RuntimeError
If flobject.py is inconsistent in Fluent and PyFluent.
"""
image_name = f"ghcr.io/ansys/pyfluent:v24.1.0"
image_name = "ghcr.io/ansys/pyfluent:v24.1.0"
container_name = uuid.uuid4().hex
is_linux = platform.system() == "Linux"
subprocess.run(
f"docker container create --name {container_name} {image_name}",
shell=is_linux,
)
xml_source = f"/ansys_inc/v241/fluent/fluent24.1.0/cortex/pylib/flapi/flobject.py"
xml_source = "/ansys_inc/v241/fluent/fluent24.1.0/cortex/pylib/flapi/flobject.py"
subprocess.run(
f"docker cp {container_name}:{xml_source} fluent_flobject.py", shell=is_linux
)
subprocess.run(f"docker container rm {container_name}", shell=is_linux)
p = subprocess.run(
f"diff -u fluent_flobject.py src/ansys/fluent/core/solver/flobject.py",
"diff -u fluent_flobject.py src/ansys/fluent/core/solver/flobject.py",
shell=is_linux,
capture_output=True,
text=True,
Expand Down
119 changes: 119 additions & 0 deletions .ci/fluent_test_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
"""Script to run Fluent test in Docker container."""

import argparse
import logging
import os
from pathlib import Path
from shutil import copytree
from tempfile import TemporaryDirectory
from time import sleep

import yaml

import ansys.fluent.core as pyfluent
from ansys.fluent.core import FluentVersion
import docker


class FluentRuntimeError(RuntimeError):
"""Exception raised when stderr is detected in Fluent output."""

pass


def run_fluent_test(journal_file: Path, launcher_args: str = "") -> None:
"""Run Fluent test.
Parameters
----------
journal_file : Path
Absolute path to the journal file.
launcher_args : str, optional
Additional arguments for the Fluent launcher.
Raises
------
FluentRuntimeError
Raised when stderr is detected in Fluent output.
"""
logging.debug(f"journal_file: {journal_file}")
src_pyfluent_dir = str(Path(pyfluent.__file__).parent)
verion_for_file_name = FluentVersion.current_dev().number
dst_pyfluent_dir = f"/ansys_inc/v{verion_for_file_name}/commonfiles/CPython/3_10/linx64/Release/python/lib/python3.10/site-packages/ansys/fluent/core"
src_test_dir = str(journal_file.parent)
dst_test_dir = "/testing"
logging.debug(f"src_pyfluent_dir: {src_pyfluent_dir}")
logging.debug(f"dst_pyfluent_dir: {dst_pyfluent_dir}")
logging.debug(f"src_test_dir: {src_test_dir}")
logging.debug(f"dst_test_dir: {dst_test_dir}")

docker_client = docker.from_env()
version_for_image_tag = FluentVersion.current_dev().docker_image_tag
image_name = f"ghcr.io/ansys/pyfluent:{version_for_image_tag}"
container = docker_client.containers.run(
image=image_name,
volumes=[
f"{src_pyfluent_dir}:{dst_pyfluent_dir}",
f"{src_test_dir}:{dst_test_dir}",
],
working_dir=dst_test_dir,
environment={"ANSYSLMD_LICENSE_FILE": os.environ["ANSYSLMD_LICENSE_FILE"]},
command=f"3ddp {launcher_args} -gu -py -i {journal_file.name}",
detach=True,
stdout=True,
stderr=True,
)
while True:
container.reload()
if container.status == "exited":
break
stderr = container.logs(stdout=False, stderr=True)
if stderr:
stderr = stderr.decode()
for line in stderr.split("\n"):
if line.strip().startswith("Error:"):
if "Expected exception" in line: # for check_assert.py
container.stop()
else:
raise FluentRuntimeError(line)
sleep(1)
logging.debug(container.logs(stderr=True).decode())
container.remove()


MAX_TEST_PATH_LENGTH = 40


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run Fluent test.")
parser.add_argument(
"test_dir",
help="Path to the Fluent test directory relative to the PyFluent repository root.",
)
args = parser.parse_args()
test_dir = Path.cwd() / args.test_dir
with TemporaryDirectory(ignore_cleanup_errors=True) as tmpdir:
copytree(test_dir, tmpdir, dirs_exist_ok=True)
exception_occurred = False
for test_file in Path(tmpdir).rglob("*.py"):
config_file = test_file.with_suffix(".yaml")
launcher_args = ""
if config_file.exists():
configs = yaml.safe_load(config_file.read_text())
launcher_args = configs.get("launcher_args", "")
test_file_relpath = str(test_file.relative_to(tmpdir))
print(f"Running {test_file_relpath}", end="", flush=True)
try:
run_fluent_test(test_file, launcher_args)
print(
f"{(MAX_TEST_PATH_LENGTH + 10 - len(test_file_relpath)) * '·'}PASSED"
)
except FluentRuntimeError as e:
print(
f"{(MAX_TEST_PATH_LENGTH + 10 - len(test_file_relpath)) * '·'}FAILED"
)
print(e)
exception_occurred = True
if exception_occurred:
exit(1)
9 changes: 4 additions & 5 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[flake8]
exclude = venv, doc/_build, src/ansys/api/fluent/v0/*, src/ansys/fluent/core/meshing/tui.py, src/ansys/fluent/core/solver/tui.py, src/ansys/fluent/core/solver/settings/*, src/ansys/fluent/core/datamodel/*
max-line-length = 88
exclude = src/ansys/fluent/core/generated
count = True
max-complexity = 10
statistics = True
select = W191 W291 W293 W391 E115 E117 E122 E124 E125 E225 E231 E301 E303 F401 F403 N801 N802 N803 N804 N805 N806
extend-ignore = E203, E501
max-complexity = 10
max-line-length = 88
extend-ignore = E203, E501, C901
107 changes: 76 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,23 @@ jobs:
name: Documentation Style Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install pre-commit
run: python -m pip install pre-commit

- name: Run pre-commit for docformatter
run: pre-commit run --hook-stage manual --all-files --show-diff-on-failure docformatter

- name: Running Vale
uses: errata-ai/vale-action@reviewdog
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
uses: ansys/actions/doc-style@v8
with:
files: doc
reporter: github-pr-check
level: error
filter_mode: nofilter
fail_on_error: true
token: ${{ secrets.GITHUB_TOKEN }}

code-style:
name: Code style
runs-on: ubuntu-latest
steps:
- name: "Run PyAnsys code style checks"
uses: ansys/actions/code-style@v8

commit-style:
name: "Run commit style checks"
runs-on: ubuntu-latest
steps:
- uses: ansys/actions/commit-style@v7
- uses: ansys/actions/check-pr-title@v8
with:
token: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -84,15 +72,15 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.10', '3.11', '3.12']
python-version: ['3.10', '3.11', '3.12', '3.13']
should-release:
- ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags') }}
exclude:
- should-release: false
os: macos-latest
steps:
- name: Build wheelhouse and perform smoke test
uses: ansys/actions/build-wheelhouse@v7
uses: ansys/actions/build-wheelhouse@v8
with:
library-name: ${{ env.PACKAGE_NAME }}
operating-system: ${{ matrix.os }}
Expand All @@ -103,8 +91,8 @@ jobs:
needs: [docs-style]
runs-on: [self-hosted, pyfluent]
env:
DOC_DEPLOYMENT_IMAGE_TAG: v24.2.0
PYFLUENT_CONTAINER_MOUNT_SOURCE: "/home/ansys/Documents/ansys_fluent_core_examples"
DOC_DEPLOYMENT_IMAGE_TAG: v25.1.0
PYFLUENT_CONTAINER_MOUNT_SOURCE: "/home/ansys/Downloads/ansys_fluent_core_examples"

steps:
- uses: actions/checkout@v4
Expand All @@ -127,6 +115,22 @@ jobs:
restore-keys: |
Python-${{ runner.os }}-${{ matrix.python-version }}
- name: Install Quarto
uses: quarto-dev/quarto-actions/setup@v2
with:
tinytex: true

- name: Check Quarto Version
shell: bash
run: |
quarto --version
- name: "Install Poppler for PDF to PNG conversion"
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y poppler-utils
- name: Install pyfluent
run: make install

Expand Down Expand Up @@ -273,6 +277,7 @@ jobs:
run: make api-codegen
env:
FLUENT_IMAGE_TAG: v22.2.0
PYFLUENT_CODEGEN_SKIP_BUILTIN_SETTINGS: 1

- name: Print 22.2 Fluent version info
run: |
Expand Down Expand Up @@ -303,6 +308,7 @@ jobs:
run: make api-codegen
env:
FLUENT_IMAGE_TAG: v23.1.0
PYFLUENT_CODEGEN_SKIP_BUILTIN_SETTINGS: 1

- name: Print 23.1 Fluent version info
run: |
Expand Down Expand Up @@ -333,6 +339,7 @@ jobs:
run: make api-codegen
env:
FLUENT_IMAGE_TAG: v23.2.0
PYFLUENT_CODEGEN_SKIP_BUILTIN_SETTINGS: 1

- name: Print 23.2 Fluent version info
run: |
Expand Down Expand Up @@ -363,6 +370,7 @@ jobs:
run: make api-codegen
env:
FLUENT_IMAGE_TAG: v24.1.0
PYFLUENT_CODEGEN_SKIP_BUILTIN_SETTINGS: 1

- name: Print 24.1 Fluent version info
run: |
Expand Down Expand Up @@ -393,6 +401,7 @@ jobs:
run: make api-codegen
env:
FLUENT_IMAGE_TAG: v24.2.0
PYFLUENT_CODEGEN_SKIP_BUILTIN_SETTINGS: 1

- name: Print 24.2 Fluent version info
run: |
Expand All @@ -409,26 +418,58 @@ jobs:
doc/source/api/core/meshing/datamodel
doc/source/api/core/solver/tui
doc/source/api/core/solver/datamodel
key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-${{ vars.FLUENT_STABLE_IMAGE_DEV }}-${{ hashFiles('src/ansys/fluent/core/codegen/**') }}
restore-keys: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-${{ vars.FLUENT_STABLE_IMAGE_DEV }}
key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v25.1.0-${{ hashFiles('src/ansys/fluent/core/codegen/**') }}
restore-keys: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v25.1.0

- name: Pull 25.1 Fluent docker image
if: steps.cache-251-api-code.outputs.cache-hit != 'true'
run: make docker-pull
env:
FLUENT_IMAGE_TAG: ${{ vars.FLUENT_STABLE_IMAGE_DEV }}
FLUENT_IMAGE_TAG: v25.1.0

- name: Run 25.1 API codegen
if: steps.cache-251-api-code.outputs.cache-hit != 'true'
run: make api-codegen
env:
FLUENT_IMAGE_TAG: ${{ vars.FLUENT_STABLE_IMAGE_DEV }}
FLUENT_IMAGE_TAG: v25.1.0
PYFLUENT_CODEGEN_SKIP_BUILTIN_SETTINGS: 1

- name: Print 25.1 Fluent version info
run: |
cat src/ansys/fluent/core/generated/fluent_version_251.py
python -c "from ansys.fluent.core.generated.solver.settings_251 import SHASH; print(f'SETTINGS_HASH = {SHASH}')"
# Replace v25.2.0 with ${{ vars.FLUENT_STABLE_IMAGE_DEV }} after the first successful nightly test run
- name: Cache 25.2 API Code
uses: actions/cache@v4
id: cache-252-api-code
with:
path:
src/ansys/fluent/core/generated
doc/source/api/core/meshing/tui
doc/source/api/core/meshing/datamodel
doc/source/api/core/solver/tui
doc/source/api/core/solver/datamodel
key: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v25.2.0-${{ hashFiles('src/ansys/fluent/core/codegen/**') }}
restore-keys: API-Code-v${{ env.API_CODE_CACHE }}-${{ steps.version.outputs.PYFLUENT_VERSION }}-v25.2.0

- name: Pull 25.2 Fluent docker image
if: steps.cache-251-api-code.outputs.cache-hit != 'true'
run: make docker-pull
env:
FLUENT_IMAGE_TAG: v25.2.0

- name: Run 25.2 API codegen
if: steps.cache-252-api-code.outputs.cache-hit != 'true'
run: make api-codegen
env:
FLUENT_IMAGE_TAG: v25.2.0

- name: Print 25.2 Fluent version info
run: |
cat src/ansys/fluent/core/generated/fluent_version_252.py
python -c "from ansys.fluent.core.generated.solver.settings_251 import SHASH; print(f'SETTINGS_HASH = {SHASH}')"
- name: Install again after codegen
run: |
rm -rf dist
Expand Down Expand Up @@ -469,9 +510,13 @@ jobs:
version: 242
- image-tag: v25.1.0
version: 251
- image-tag: v25.2.0
version: 252
timeout-minutes: 120
env:
FLUENT_IMAGE_TAG: ${{ matrix.version == 251 && vars.FLUENT_STABLE_IMAGE_DEV || matrix.image-tag }}
# Enable this after the first successful nightly test run
# FLUENT_IMAGE_TAG: ${{ matrix.version == 252 && vars.FLUENT_STABLE_IMAGE_DEV || matrix.image-tag }}
FLUENT_IMAGE_TAG: ${{ matrix.image-tag }}

steps:

Expand Down
Loading

0 comments on commit f2ceade

Please sign in to comment.