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

wheeeel #273

Merged
merged 22 commits into from
Oct 24, 2024
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
12 changes: 8 additions & 4 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:

testing:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]

Expand All @@ -63,9 +64,9 @@ jobs:
dir
winget settings --enable LocalManifestFiles
winget install -m .\manifests\n\NGSpice\NGSpice\42
# winget install -m .\manifests\o\OpenEMS\OpenEMS\0.0.36
winget install -m .\manifests\o\OpenEMS\OpenEMS\0.0.36
Add-Content $env:GITHUB_PATH "$env:LOCALAPPDATA\Microsoft\WinGet\Packages\NGSpice.NGSpice__DefaultSource\Spice64\bin"
# Add-Content $env:GITHUB_PATH "$env:LOCALAPPDATA\Microsoft\WinGet\Packages\OpenEMS.OpenEMS__DefaultSource\OpenEMS"
Add-Content $env:GITHUB_PATH "$env:LOCALAPPDATA\Microsoft\WinGet\Packages\OpenEMS.OpenEMS__DefaultSource\OpenEMS"
- name: Install Nix for Ubuntu
if: ${{runner.os != 'Windows' }}
uses: cachix/install-nix-action@v30
Expand All @@ -78,6 +79,7 @@ jobs:
sudo apt-get install -y ngspice
nix-channel --update
nix-channel --list
# nix-env -i openems -f '<nixpkgs>'
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.10
Expand All @@ -88,7 +90,7 @@ jobs:
- name: Install Dependencies
run: |
poetry show --tree
poetry install
poetry install --with=dev
poetry run pwd
- name: Install PDK
run: |
Expand All @@ -99,6 +101,8 @@ jobs:
run: |
poetry run volare enable --pdk sky130 --pdk-root ./pdk 6d4d11780c40b20ee63cc98e645307a9bf2b2ab8
poetry run volare enable --pdk gf180mcu --pdk-root ./pdk 6d4d11780c40b20ee63cc98e645307a9bf2b2ab8
poetry run pip install .\manifests\openEMS-0.0.36-cp310-cp310-win_amd64.whl
poetry run pip install .\manifests\CSXCAD-0.6.3-cp310-cp310-win_amd64.whl
poetry run volare ls
- if: ${{ steps.pdk-restore.outputs.cache-hit != 'true' }}
name: Save PDK Directory
Expand All @@ -115,7 +119,7 @@ jobs:
if: failure()
uses: actions/upload-artifact@v4
with:
name: reports
name: reports-${{ matrix.os }}
path: |
tmp/
pytest.log
29 changes: 21 additions & 8 deletions hades/wrappers/oems.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path
from typing import Optional

from pydantic import PositiveFloat, BaseModel
from pydantic import confloat, BaseModel
from typer import Typer

from gdstk import read_gds
Expand All @@ -23,10 +23,16 @@
if shutil.which("openEMS"):
if "OPENEMS_INSTALL_PATH" not in os.environ:
os.environ["OPENEMS_INSTALL_PATH"] = dirname(shutil.which("openEMS"))
from CSXCAD import CSXCAD
from openEMS.openEMS import openEMS
else:
logging.error("openEMS not found")
paths = os.environ["PATH"].split(";" if os.name == "nt" else ":")
[logging.info(f"{p}") for p in paths]
try:
from CSXCAD import CSXCAD
from openEMS.openEMS import openEMS
except ImportError:
logging.error("CSXCAD or openEMS not found")


from hades.layouts.tools import Port

Expand All @@ -38,8 +44,8 @@


class Frequency(BaseModel):
start: PositiveFloat = 0
stop: PositiveFloat
start: confloat(ge=0) = 0
stop: confloat(gt=0)


@oems_app.command("run")
Expand Down Expand Up @@ -99,6 +105,9 @@ def compute(
"""
unit = 1e-6 # all length in um

if type(freq) is tuple:
freq = Frequency(start=freq[0], stop=freq[1])

### Setup FDTD parameter & excitation function
FDTD = openEMS(CoordSystem=0, EndCriteria=1e-4) # init a rectangular FDTD
if freq.start == freq.stop:
Expand Down Expand Up @@ -170,10 +179,13 @@ def compute(

### Export as a touchstone file
f = np.linspace(freq.start, freq.stop, 401)
port.CalcPort(sim_path, f)
result = Network()
result.frequency = f
result.s = port.uf_ref / port.uf_inc
try:
port.CalcPort(sim_path, f)
result.s = port.uf_ref / port.uf_inc
except FileNotFoundError:
logging.error("Ports files not found, run the simulation first")
return result


Expand All @@ -182,14 +194,15 @@ def make_geometry(
tech: str = "mock",
*,
margin: float = 0.2,
) -> CSXCAD.ContinuousStructure:
):
"""
Create a geometry in OpenEMS from a gds and a technology.
:param gds_file: The input gds file (the top cell is used by default).
:param tech: Name of the technology (*hades pdk list* for a list of available techno).
:param margin: margin around the model. The simulation box is the bounding box of the model time (1 + margin).
:return:
"""
logging.info(f"Creating geometry from {gds_file}")
gdsii = read_gds(gds_file).cells[0]

CSX = CSXCAD.ContinuousStructure()
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ klayout = "^0.29.5"
ngsolve = "^6.2.2404.post51"
pydantic = "^2.8.2"
openems = [
{path = "manifests/openEMS-0.0.36-cp310-cp310-win_amd64.whl", python = "~3.10", platform = "win64"},
{path = "manifests/openEMS-0.0.36-cp311-cp311-win_amd64.whl", python = "~3.11", platform = "win64"},
{path = "manifests/openEMS-0.0.36-cp310-cp310-win_amd64.whl", python = "~3.10", platform = "win32"},
{path = "manifests/openEMS-0.0.36-cp311-cp311-win_amd64.whl", python = "~3.11", platform = "win32"},
]
csxcad = [
{path = "manifests/CSXCAD-0.6.3-cp310-cp310-win_amd64.whl", python = "~3.10", platform = "win64"},
{path = "manifests/CSXCAD-0.6.3-cp311-cp311-win_amd64.whl", python = "~3.11", platform = "win64"},
{path = "manifests/CSXCAD-0.6.3-cp310-cp310-win_amd64.whl", python = "~3.10", platform = "win32"},
{path = "manifests/CSXCAD-0.6.3-cp311-cp311-win_amd64.whl", python = "~3.11", platform = "win32"},
]
h5py = "^3.11.0"

Expand Down
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ in
pkgs.mkShellNoCC {
packages = with pkgs; [
magic-vlsi
openems
];

shellHook =
Expand Down
17 changes: 17 additions & 0 deletions tests/test_wrappers/test_oems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import shutil
from os.path import dirname
from pathlib import Path
import pytest

from hades.wrappers.oems import compute, Frequency


@pytest.mark.skipif(shutil.which("openEMS") is None, reason="OpenEMS not found in PATH")
def test_compute(tmp_path):
compute(
Path(dirname(__file__)) / "../test_layouts/ref_ind2.gds",
"ind",
Frequency(start=0, stop=1e9),
sim_path=tmp_path,
skip_run=True,
)