Skip to content

Commit

Permalink
Merge pull request #21 from invrs-io/bayer
Browse files Browse the repository at this point in the history
Add the bayer sorter leaderboard
  • Loading branch information
mfschubert authored Jul 11, 2024
2 parents 01effc1 + a06da28 commit 1e5a172
Show file tree
Hide file tree
Showing 8 changed files with 337 additions and 2 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ jobs:
- name: Run Python tests
run: pytest

leaderboard_bayer_sorter:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
cache-dependency-path: pyproject.toml

- name: Setup environment
run: |
python -m pip install --upgrade pip
pip install ".[tests,dev]"
- name: Run Python tests
run: |
pytest tests/test_new_solutions.py::VerifyLeaderboardTest::test_bayer_sorter --runslow
leaderboard_diffractive_splitter:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions challenges/bayer_sorter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `220607_zou_*` solutions are extracted from Supplementary figure 2 of "[Pixel-level Bayer-type colour router based on metasurfaces](https://www.nature.com/articles/s41467-022-31019-7)" by X. Zou et al.
1 change: 1 addition & 0 deletions challenges/bayer_sorter/leaderboard.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
path=challenges/bayer_sorter/solutions/220607_zou_00.csv, eval_metric=0.42892409584479074, minimum_width=9.0, minimum_spacing=3.0, binarization_degree=1.0
200 changes: 200 additions & 0 deletions challenges/bayer_sorter/solutions/220607_zou_00.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ root: readme
parts:
- caption: Challenges
chapters:
- file: notebooks/bayer_sorter
- file: notebooks/ceviche_challenges
- file: notebooks/diffractive_splitter
- file: notebooks/meta_atom_library
Expand Down
100 changes: 100 additions & 0 deletions docs/notebooks/bayer_sorter.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "6dd24c9b",
"metadata": {},
"source": [
"# Bayer sorter\n",
"\n",
"Visit the invrs-gym docs for the [bayer sorter challenge](https://invrs-io.github.io/gym/notebooks/bayer_challenge.html).\n",
"\n",
"The bayer sorter challenge is based on the “[Pixel-level Bayer-type colour router based on metasurfaces](https://www.nature.com/articles/s41467-022-31019-7)” by Zou et al., and entails the design of a metasurface that sorts incident light in a wavelength-dependent way and takes the place of a traditional color filter.\n",
"\n",
"The bayer sorter eval metric is defined as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a805742a",
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"from invrs_gym import challenges\n",
"\n",
"docstring = challenges.bayer_sorter().eval_metric.__doc__\n",
"print(\"\\n\".join([s[8:] for s in docstring.split(\"Args\")[0].split(\"\\n\")[2:-2]]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f8c178cb",
"metadata": {
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"import os\n",
"import plotly.express as px\n",
"from IPython import display\n",
"from invrs_leaderboard import data\n",
"\n",
"df = data.leaderboard_dataframe(base_path=\"../../\")\n",
"\n",
"def plot_challenge_metrics(challenge_name: str) -> display.DisplayHandle:\n",
" challenge_df = df[df[\"challenge\"] == challenge_name]\n",
" fig = px.scatter(\n",
" challenge_df,\n",
" x=\"minimum_length_scale\",\n",
" y=\"eval_metric\",\n",
" color=\"file_prefix\",\n",
" hover_data=[\"file\", \"minimum_width\", \"minimum_spacing\", \"binarization_degree\"],\n",
" )\n",
" if not os.path.exists(\"_plots/\"):\n",
" os.mkdir(\"_plots/\")\n",
" filename = f\"_plots/eval_metric_{challenge_name}.html\"\n",
" fig.write_html(filename)\n",
" return display.display(display.HTML(filename))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0712f9cd",
"metadata": {},
"outputs": [],
"source": [
"plot_challenge_metrics(\"bayer_sorter\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
6 changes: 6 additions & 0 deletions src/invrs_leaderboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import jax.numpy as jnp
import numpy as onp
from invrs_gym import challenges
from invrs_gym.challenges.bayer import challenge as bayer_challenge
from invrs_gym.challenges.diffract import metagrating_challenge, splitter_challenge
from invrs_gym.challenges.library import challenge as library_challenge
from invrs_gym.challenges.metalens import challenge as metalens_challenge
Expand All @@ -29,6 +30,11 @@
# purposes, we use settings that ensure greater accuracy. Note: if these values
# change, leaderboards will be affected and must be regenerated!
OVERRIDE_SIM_PARAMS_BY_CHALLENGE = {
"bayer_sorter": dataclasses.replace(
bayer_challenge.BAYER_SIM_PARAMS,
approximate_num_terms=1000,
wavelength=jnp.asarray([0.433, 0.467, 0.533, 0.567, 0.633, 0.667]),
),
"diffractive_splitter": dataclasses.replace(
splitter_challenge.DIFFRACTIVE_SPLITTER_SIM_PARAMS,
approximate_num_terms=1000,
Expand Down
8 changes: 6 additions & 2 deletions tests/test_new_solutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def _test_new_submissions_have_correct_metrics(self, challenge_to_check):
self.assertEqual(a, b)

@pytest.mark.slow
def test_diffractive_splitter(self):
self._test_new_submissions_have_correct_metrics("diffractive_splitter")
def test_bayer_sorter(self):
self._test_new_submissions_have_correct_metrics("bayer_sorter")

@pytest.mark.slow
def test_ceviche_beam_splitter(self):
Expand All @@ -113,6 +113,10 @@ def test_ceviche_waveguide_bend(self):
def test_ceviche_wdm(self):
self._test_new_submissions_have_correct_metrics("ceviche_wdm")

@pytest.mark.slow
def test_diffractive_splitter(self):
self._test_new_submissions_have_correct_metrics("diffractive_splitter")

@pytest.mark.slow
def test_meta_atom_library(self):
self._test_new_submissions_have_correct_metrics("meta_atom_library")
Expand Down

0 comments on commit 1e5a172

Please sign in to comment.