Skip to content

Commit

Permalink
Merge pull request #206 from amccaugh/dev
Browse files Browse the repository at this point in the history
1.7.2
  • Loading branch information
amccaugh authored Jul 3, 2024
2 parents 3a9bf95 + 825ffe3 commit 88a6607
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 30 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
pytest:
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10"]
fail-fast: false
runs-on: ubuntu-latest
steps:
Expand All @@ -20,14 +20,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U \
matplotlib \
scipy \
rectpack \
klayout \
freetype-py \
pytest
pip install -e .
pip install -e '.[test]'
- name: Run test
uses: GabrielBB/xvfb-action@v1
with:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog


## 1.7.2 (July 3, 2024)

### Bugfixes
- Updated to be compatible with Numpy 2.0 (thanks Ashley Anderson @aganders3)
- Removed leftover debugging `print()` statement from `kl_` boolean functions (thanks Bakhrom Oripov @bakhromtjk)


## 1.7.1 (April 26, 2024)

### New features
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GDS scripting for Python that's intuitive, fast, and powerful.
- [**Installation / requirements**](#installation--requirements)
- [**Tutorial + examples**](https://phidl.readthedocs.io/en/latest/tutorials.html) (or [try an interactive notebook](https://mybinder.org/v2/gh/amccaugh/phidl/master?filepath=phidl_tutorial_example.ipynb))
- [**Geometry library + function documentation**](https://phidl.readthedocs.io/en/latest/geometry_reference.html)
- [Changelog](https://github.com/amccaugh/phidl/blob/master/CHANGELOG.md) (latest update 1.7.1 on April 26, 2024)
- [Changelog](https://github.com/amccaugh/phidl/blob/master/CHANGELOG.md) (latest update 1.7.2 on July 3, 2024)
- New KLayout-based boolean/offset/outline functions! These are under the name `pg.kl_boolean()`, `pg.kl_offset`, `pg.kl_outline()`, `pg.kl_invert()`. They utilize the excellent KLayout tile processor, which allows breaking down & parallelizing these operations--in a nutshell, these operations should be much, much faster, and they also are more robust than the gdspy/clipper implementation. To use these new functions, you must first `pip install klayout`
- Path.interpolate() now allows easy placement of objects alongside a path (e.g. for placing vias). See [the tutorial](https://phidl.readthedocs.io/en/latest/tutorials/waveguides.html#Interpolating-/-placing-objects-along-a-path) for more information

Expand All @@ -23,8 +23,12 @@ If you found PHIDL useful, please consider citing it in (just one!) of your publ

# Installation / requirements
- Install or upgrade with `pip install -U phidl`
- Install with `pip install -U phidl[all]` to include optional dependencies (e.g. freetype-py, klayout, rectpack)
- Python version >=3.6

## Testing
- Install with test dependencies with `pip install -U phidl[test]` (includes `all` extras as well)
- Run tests with `pytest` (or `python -m pytest`)

# About PHIDL

Expand Down
17 changes: 12 additions & 5 deletions phidl/device_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

gdspy.library.use_current_library = False

__version__ = "1.7.1"
__version__ = "1.7.2"


config = dict(NUM_CPU=multiprocessing.cpu_count())
Expand Down Expand Up @@ -353,9 +353,13 @@ def _line_distances(points, start, end):
if np.all(start == end):
return np.linalg.norm(points - start, axis=1)

vec = end - start
cross = np.cross(vec, start - points)
return np.divide(abs(cross), np.linalg.norm(vec))
line_vec = end - start
relative_points = start - points
cross = (
line_vec[..., 0] * relative_points[..., 1]
- line_vec[..., 1] * relative_points[..., 0]
)
return np.divide(abs(cross), np.linalg.norm(line_vec))


def _simplify(points, tolerance=0):
Expand Down Expand Up @@ -1132,6 +1136,9 @@ def __init__(self, *args, **kwargs):
else:
name = "Unnamed"

if name == "":
raise ValueError("[PHIDL] Device was given a blank name")

# Make a new blank device
self.ports = {}
self.info = {}
Expand Down Expand Up @@ -2728,7 +2735,7 @@ def append(self, path):
and np.issubdtype(np.array(path).dtype, np.number)
and (np.shape(path)[1] == 2)
):
points = np.asfarray(path)
points = np.asarray(path, dtype=np.float64)
nx1, ny1 = points[1] - points[0]
start_angle = np.arctan2(ny1, nx1) / np.pi * 180
nx2, ny2 = points[-1] - points[-2]
Expand Down
6 changes: 3 additions & 3 deletions phidl/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ def _merge_floating_point_errors(polygons, tol=1e-10):
Set of corrected polygons.
"""
if len(polygons) == 0:
return np.asfarray([])
return np.asarray([], dtype=np.float64)
stacked_polygons = np.vstack(polygons)
x = stacked_polygons[:, 0]
y = stacked_polygons[:, 1]
Expand Down Expand Up @@ -1488,7 +1488,7 @@ def _kl_region_to_device(kl_region, layer, name, precision):
for polygon in kl_region.each():
polygon = polygon.to_simple_polygon()
points = _kl_polygon_to_array(polygon)
points = np.asfarray(points) * precision
points = np.asarray(points, dtype=np.float64) * precision
D.add_polygon(points, layer=layer)
return D

Expand Down Expand Up @@ -2224,7 +2224,7 @@ def import_gds(filename, cellname=None, flatten=False):
rotation = 0
l = D.add_label(
text=label.text,
position=np.asfarray(label.position),
position=np.asarray(label.position, dtype=np.float64),
magnification=label.magnification,
rotation=rotation * 180 / np.pi,
layer=(label.layer, label.texttype),
Expand Down
10 changes: 6 additions & 4 deletions phidl/path.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math

import numpy as np

from phidl.device_layout import CrossSection, Path, _rotate_points
Expand Down Expand Up @@ -74,8 +76,8 @@ def _fresnel(R0, s, num_pts, n_iter=8):
y = np.zeros(num_pts)

for n in range(0, n_iter):
x += (-1) ** n * t ** (4 * n + 1) / (np.math.factorial(2 * n) * (4 * n + 1))
y += (-1) ** n * t ** (4 * n + 3) / (np.math.factorial(2 * n + 1) * (4 * n + 3))
x += (-1) ** n * t ** (4 * n + 1) / (math.factorial(2 * n) * (4 * n + 1))
y += (-1) ** n * t ** (4 * n + 3) / (math.factorial(2 * n + 1) * (4 * n + 3))

return np.array([np.sqrt(2) * R0 * x, np.sqrt(2) * R0 * y])

Expand Down Expand Up @@ -142,7 +144,7 @@ def euler(radius=3, angle=90, p=1.0, use_eff=False, num_pts=720):
dx = xp - Rp * np.sin(p * alpha / 2)
dy = yp - Rp * (1 - np.cos(p * alpha / 2))
else:
xbend1 = ybend1 = np.asfarray([])
xbend1 = ybend1 = np.array([], dtype=np.float64)
dx = 0
dy = 0

Expand Down Expand Up @@ -293,7 +295,7 @@ def spiral(num_turns=5, gap=1, inner_gap=2, num_pts=10000):


def _compute_segments(points):
points = np.asfarray(points)
points = np.asarray(points, dtype=np.float64)
normals = np.diff(points, axis=0)
normals = (normals.T / np.linalg.norm(normals, axis=1)).T
dx = np.diff(points[:, 0])
Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
six
gdspy
klayout
numpy
matplotlib
gdspy
rectpack
six
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
line-length = 88

[lint]
select = ["C", "E", "F", "B", "B9", "UP", "I"]
select = ["C", "E", "F", "B", "B9", "UP", "I", "NPY201"]
ignore = [
"E203",
"E266",
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"matplotlib",
]

extras_require = {}
extras_require["all"] = ["freetype-py", "klayout", "rectpack", "scipy"]
extras_require["test"] = extras_require["all"] + ["pytest"]

# read the contents of your README file

this_directory = path.abspath(path.dirname(__file__))
Expand All @@ -19,11 +23,12 @@

setup(
name="phidl",
version="1.7.1",
version="1.7.2",
description="PHIDL",
long_description=long_description,
long_description_content_type="text/markdown",
install_requires=install_requires,
extras_require=extras_require,
author="Adam McCaughan",
author_email="[email protected]",
packages=["phidl"],
Expand Down
12 changes: 8 additions & 4 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ def test_text():


def test_truetype():
_ = pytest.importorskip(
"phidl.font", reason="Testing of ttf/otf fonts requires the freetype package."
pytest.importorskip(
"phidl.font",
reason="Testing of ttf/otf fonts requires the freetype package.",
exc_type=ImportError,
)
from os import path

Expand All @@ -229,8 +231,10 @@ def test_truetype():

@pytest.mark.skipif(sys.version_info < (3, 0), reason="unicode test requires python3")
def test_unicode():
_ = pytest.importorskip(
"phidl.font", reason="Testing of ttf/otf fonts requires the freetype package."
pytest.importorskip(
"phidl.font",
reason="Testing of ttf/otf fonts requires the freetype package.",
exc_type=ImportError,
)
from os import path

Expand Down

0 comments on commit 88a6607

Please sign in to comment.