Skip to content

PyaedtFileParameters

Launch and manage an AEDT (HFSS) session based on file and license settings.

This model is used during every stage of the workflow where HFSS access is required. It provides a context-managed interface to automatically open and clean up HFSS projects.

Bases: BaseModel

Configuration for launching and managing an AEDT (HFSS) session.

This object controls how the .aedt file is opened, including settings related to license availability, GUI behavior, and session cleanup.

It is used during the prepare, build, and simulate phases of the simulation workflow.

Attributes:

Name Type Description
file_path PATH_TYPE

Path to the source .aedt project file.

design_name str

Name of the design to open (defaults to "temp").

version Literal['2024.2']

AEDT version to use (e.g., "2024.2").

non_graphical bool

Whether to run AEDT in non-graphical mode.

new_desktop bool

If True, starts a new AEDT desktop instance.

close_on_exit bool

Whether to automatically close AEDT after exiting the context.

open_pyaedt_file

open_pyaedt_file() -> Generator[Hfss, None, None]

Open an HFSS session using the specified file and settings.

Returns a context-managed Hfss instance that is ready to use.

Yields:

Type Description
Hfss

An active and validated Hfss object.

Raises:

Type Description
LicenseUnavailableError

If no valid design is loaded (e.g., license issue).

Source code in src/quansys/workflow/session_handler/config.py
@contextmanager
def open_pyaedt_file(self) -> Generator[Hfss, None, None]:
    """
    Open an HFSS session using the specified file and settings.

    Returns a context-managed `Hfss` instance that is ready to use.

    Yields:
        An active and validated `Hfss` object.

    Raises:
        LicenseUnavailableError: If no valid design is loaded (e.g., license issue).
    """
    with Hfss(
            non_graphical=self.non_graphical,
            version=self.version,
            new_desktop=self.new_desktop,
            close_on_exit=self.close_on_exit,
            design=self.design_name,
            project=str(self.file_path.resolve()),
            remove_lock=True
    ) as hfss:
        # Immediately check if HFSS initialized to a valid state
        if not hfss.valid_design:
            # Close the session and signal unavailability
            raise LicenseUnavailableError(
                "HFSS session created but no valid design — likely license or startup issue."
            )

        try:
            yield hfss
            hfss.save_project()
        finally:
            # Optional cleanup
            if 'temp' in hfss.design_list:
                print("Cleaning up: Deleting temporary HFSS design.")
                hfss.delete_design("temp")