From 61c1691d846ffa95e78a1c7c17cb373013f99c21 Mon Sep 17 00:00:00 2001 From: daquintero Date: Mon, 12 Feb 2024 18:04:04 +0100 Subject: [PATCH 1/3] FEAT: Little tests but working fine --- StartHere.ipynb | 73 ++++++++++++++++++++++------------------ tests/test_quickstart.py | 8 +++++ 2 files changed, 48 insertions(+), 33 deletions(-) create mode 100644 tests/test_quickstart.py diff --git a/StartHere.ipynb b/StartHere.ipynb index cb748e10..fec7ab35 100644 --- a/StartHere.ipynb +++ b/StartHere.ipynb @@ -12,10 +12,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "id": "19787f48-98be-4f65-8fd1-7f46c398ca86", "metadata": { - "tags": [] + "tags": [], + "ExecuteTime": { + "end_time": "2024-02-12T17:01:39.651565038Z", + "start_time": "2024-02-12T17:01:39.610184423Z" + } }, "outputs": [], "source": [ @@ -30,10 +34,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 5, "id": "8a6c56eb-149c-4691-bd4a-7b48e8127933", "metadata": { - "tags": [] + "tags": [], + "ExecuteTime": { + "end_time": "2024-02-12T17:01:39.753666887Z", + "start_time": "2024-02-12T17:01:39.747692034Z" + } }, "outputs": [], "source": [ @@ -462,8 +470,8 @@ "\n" ], "text/plain": [ - "\u001b[2;36m[09:31:15]\u001b[0m\u001b[2;36m \u001b[0mCreated task \u001b[32m'quickstart'\u001b[0m with task_id \n", - "\u001b[2;36m \u001b[0m\u001b[32m'fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1'\u001b[0m. \n" + "\u001B[2;36m[09:31:15]\u001B[0m\u001B[2;36m \u001B[0mCreated task \u001B[32m'quickstart'\u001B[0m with task_id \n", + "\u001B[2;36m \u001B[0m\u001B[32m'fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1'\u001B[0m. \n" ] }, "metadata": {}, @@ -478,9 +486,9 @@ "\n" ], "text/plain": [ - "\u001b[2;36m \u001b[0m\u001b[2;36m \u001b[0mView task using web UI at \n", - "\u001b[2;36m \u001b[0m\u001b]8;id=624032;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34m'https://tidy3d.simulation.cloud/workbench?\u001b[0m\u001b]8;;\u001b\\\u001b]8;id=129933;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34mtaskId\u001b[0m\u001b]8;;\u001b\\\u001b]8;id=624032;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34m=\u001b[0m\u001b]8;;\u001b\\\u001b]8;id=786678;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34mfdve\u001b[0m\u001b]8;;\u001b\\\u001b]8;id=624032;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34m-a65fc275-cb18-\u001b[0m\u001b]8;;\u001b\\\n", - "\u001b[2;36m \u001b[0m\u001b]8;id=624032;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34m4630-adf2-0a4e976bf5fbv1'\u001b[0m\u001b]8;;\u001b\\\u001b[4;34m.\u001b[0m \n" + "\u001B[2;36m \u001B[0m\u001B[2;36m \u001B[0mView task using web UI at \n", + "\u001B[2;36m \u001B[0m\u001B]8;id=624032;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34m'https://tidy3d.simulation.cloud/workbench?\u001B[0m\u001B]8;;\u001B\\\u001B]8;id=129933;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34mtaskId\u001B[0m\u001B]8;;\u001B\\\u001B]8;id=624032;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34m=\u001B[0m\u001B]8;;\u001B\\\u001B]8;id=786678;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34mfdve\u001B[0m\u001B]8;;\u001B\\\u001B]8;id=624032;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34m-a65fc275-cb18-\u001B[0m\u001B]8;;\u001B\\\n", + "\u001B[2;36m \u001B[0m\u001B]8;id=624032;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34m4630-adf2-0a4e976bf5fbv1'\u001B[0m\u001B]8;;\u001B\\\u001B[4;34m.\u001B[0m \n" ] }, "metadata": {}, @@ -530,7 +538,7 @@ "\n" ], "text/plain": [ - "\u001b[2;36m[09:31:17]\u001b[0m\u001b[2;36m \u001b[0mstatus = queued \n" + "\u001B[2;36m[09:31:17]\u001B[0m\u001B[2;36m \u001B[0mstatus = queued \n" ] }, "metadata": {}, @@ -557,7 +565,7 @@ "\n" ], "text/plain": [ - "\u001b[2;36m[09:31:27]\u001b[0m\u001b[2;36m \u001b[0mstatus = preprocess \n" + "\u001B[2;36m[09:31:27]\u001B[0m\u001B[2;36m \u001B[0mstatus = preprocess \n" ] }, "metadata": {}, @@ -581,8 +589,8 @@ "\n" ], "text/plain": [ - "\u001b[2;36m[09:31:32]\u001b[0m\u001b[2;36m \u001b[0mMaximum FlexCredit cost: \u001b[1;36m0.025\u001b[0m. Use \u001b[32m'web.real_cost\u001b[0m\u001b[32m(\u001b[0m\u001b[32mtask_id\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m to get \n", - "\u001b[2;36m \u001b[0mthe billed FlexCredit cost after a simulation run. \n" + "\u001B[2;36m[09:31:32]\u001B[0m\u001B[2;36m \u001B[0mMaximum FlexCredit cost: \u001B[1;36m0.025\u001B[0m. Use \u001B[32m'web.real_cost\u001B[0m\u001B[32m(\u001B[0m\u001B[32mtask_id\u001B[0m\u001B[32m)\u001B[0m\u001B[32m'\u001B[0m to get \n", + "\u001B[2;36m \u001B[0mthe billed FlexCredit cost after a simulation run. \n" ] }, "metadata": {}, @@ -595,7 +603,7 @@ "\n" ], "text/plain": [ - "\u001b[2;36m \u001b[0m\u001b[2;36m \u001b[0mstarting up solver \n" + "\u001B[2;36m \u001B[0m\u001B[2;36m \u001B[0mstarting up solver \n" ] }, "metadata": {}, @@ -608,7 +616,7 @@ "\n" ], "text/plain": [ - "\u001b[2;36m \u001b[0m\u001b[2;36m \u001b[0mrunning solver \n" + "\u001B[2;36m \u001B[0m\u001B[2;36m \u001B[0mrunning solver \n" ] }, "metadata": {}, @@ -624,10 +632,10 @@ "\n" ], "text/plain": [ - "\u001b[2;36m \u001b[0m\u001b[2;36m \u001b[0mTo cancel the simulation, use \u001b[32m'web.abort\u001b[0m\u001b[32m(\u001b[0m\u001b[32mtask_id\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m or \n", - "\u001b[2;36m \u001b[0m\u001b[32m'web.delete\u001b[0m\u001b[32m(\u001b[0m\u001b[32mtask_id\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m or abort/delete the task in the web UI. \n", - "\u001b[2;36m \u001b[0mTerminating the Python script will not stop the job running on the \n", - "\u001b[2;36m \u001b[0mcloud. \n" + "\u001B[2;36m \u001B[0m\u001B[2;36m \u001B[0mTo cancel the simulation, use \u001B[32m'web.abort\u001B[0m\u001B[32m(\u001B[0m\u001B[32mtask_id\u001B[0m\u001B[32m)\u001B[0m\u001B[32m'\u001B[0m or \n", + "\u001B[2;36m \u001B[0m\u001B[32m'web.delete\u001B[0m\u001B[32m(\u001B[0m\u001B[32mtask_id\u001B[0m\u001B[32m)\u001B[0m\u001B[32m'\u001B[0m or abort/delete the task in the web UI. \n", + "\u001B[2;36m \u001B[0mTerminating the Python script will not stop the job running on the \n", + "\u001B[2;36m \u001B[0mcloud. \n" ] }, "metadata": {}, @@ -654,7 +662,7 @@ "\n" ], "text/plain": [ - "\u001b[2;36m[09:31:39]\u001b[0m\u001b[2;36m \u001b[0mearly shutoff detected, exiting. \n" + "\u001B[2;36m[09:31:39]\u001B[0m\u001B[2;36m \u001B[0mearly shutoff detected, exiting. \n" ] }, "metadata": {}, @@ -690,7 +698,7 @@ "\n" ], "text/plain": [ - "\u001b[2;36m \u001b[0m\u001b[2;36m \u001b[0mstatus = postprocess \n" + "\u001B[2;36m \u001B[0m\u001B[2;36m \u001B[0mstatus = postprocess \n" ] }, "metadata": {}, @@ -717,7 +725,7 @@ "\n" ], "text/plain": [ - "\u001b[2;36m[09:31:44]\u001b[0m\u001b[2;36m \u001b[0mstatus = success \n" + "\u001B[2;36m[09:31:44]\u001B[0m\u001B[2;36m \u001B[0mstatus = success \n" ] }, "metadata": {}, @@ -742,9 +750,9 @@ "\n" ], "text/plain": [ - "\u001b[2;36m[09:31:45]\u001b[0m\u001b[2;36m \u001b[0mView simulation result at \n", - "\u001b[2;36m \u001b[0m\u001b]8;id=887611;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34m'https://tidy3d.simulation.cloud/workbench?\u001b[0m\u001b]8;;\u001b\\\u001b]8;id=889999;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34mtaskId\u001b[0m\u001b]8;;\u001b\\\u001b]8;id=887611;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34m=\u001b[0m\u001b]8;;\u001b\\\u001b]8;id=811867;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34mfdve\u001b[0m\u001b]8;;\u001b\\\u001b]8;id=887611;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34m-a65fc275-cb18-\u001b[0m\u001b]8;;\u001b\\\n", - "\u001b[2;36m \u001b[0m\u001b]8;id=887611;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001b\\\u001b[4;34m4630-adf2-0a4e976bf5fbv1'\u001b[0m\u001b]8;;\u001b\\\u001b[4;34m.\u001b[0m \n" + "\u001B[2;36m[09:31:45]\u001B[0m\u001B[2;36m \u001B[0mView simulation result at \n", + "\u001B[2;36m \u001B[0m\u001B]8;id=887611;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34m'https://tidy3d.simulation.cloud/workbench?\u001B[0m\u001B]8;;\u001B\\\u001B]8;id=889999;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34mtaskId\u001B[0m\u001B]8;;\u001B\\\u001B]8;id=887611;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34m=\u001B[0m\u001B]8;;\u001B\\\u001B]8;id=811867;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34mfdve\u001B[0m\u001B]8;;\u001B\\\u001B]8;id=887611;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34m-a65fc275-cb18-\u001B[0m\u001B]8;;\u001B\\\n", + "\u001B[2;36m \u001B[0m\u001B]8;id=887611;https://tidy3d.simulation.cloud/workbench?taskId=fdve-a65fc275-cb18-4630-adf2-0a4e976bf5fbv1\u001B\\\u001B[4;34m4630-adf2-0a4e976bf5fbv1'\u001B[0m\u001B]8;;\u001B\\\u001B[4;34m.\u001B[0m \n" ] }, "metadata": {}, @@ -794,7 +802,7 @@ "\n" ], "text/plain": [ - "\u001b[2;36m[09:31:46]\u001b[0m\u001b[2;36m \u001b[0mloading SimulationData from data/data.hdf5 \n" + "\u001B[2;36m[09:31:46]\u001B[0m\u001B[2;36m \u001B[0mloading SimulationData from data/data.hdf5 \n" ] }, "metadata": {}, @@ -839,8 +847,7 @@ "Field decay smaller than shutoff factor, exiting solver.\n", "\n", "Solver time (s): 1.2144\n", - "Data write time (s): 0.0036\n", - "\n" + "Data write time (s): 0.0036\n" ] } ], @@ -1136,7 +1143,7 @@ { "data": { "text/html": "
 monitor_data.hdf5 ━━━━━━━━━━━━━━━ 100.0%945.8/945.8 kB2.1 MB/s0:00:00\n
\n", - "text/plain": "\u001b[1;32m↓\u001b[0m \u001b[1;34mmonitor_data.hdf5\u001b[0m \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━\u001b[0m \u001b[35m100.0%\u001b[0m • \u001b[32m945.8/945.8 kB\u001b[0m • \u001b[31m2.1 MB/s\u001b[0m • \u001b[36m0:00:00\u001b[0m\n" + "text/plain": "\u001B[1;32m↓\u001B[0m \u001B[1;34mmonitor_data.hdf5\u001B[0m \u001B[38;2;114;156;31m━━━━━━━━━━━━━━━\u001B[0m \u001B[35m100.0%\u001B[0m • \u001B[32m945.8/945.8 kB\u001B[0m • \u001B[31m2.1 MB/s\u001B[0m • \u001B[36m0:00:00\u001B[0m\n" }, "metadata": {}, "output_type": "display_data" @@ -1218,7 +1225,7 @@ { "data": { "text/html": "
 simulation.hdf5.gz ━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0%1.2/1.2 kB?0:00:00\n
\n", - "text/plain": "\u001b[1;31m↑\u001b[0m \u001b[1;34msimulation.hdf5.gz\u001b[0m \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[35m100.0%\u001b[0m • \u001b[32m1.2/1.2 kB\u001b[0m • \u001b[31m?\u001b[0m • \u001b[36m0:00:00\u001b[0m\n" + "text/plain": "\u001B[1;31m↑\u001B[0m \u001B[1;34msimulation.hdf5.gz\u001B[0m \u001B[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[35m100.0%\u001B[0m • \u001B[32m1.2/1.2 kB\u001B[0m • \u001B[31m?\u001B[0m • \u001B[36m0:00:00\u001B[0m\n" }, "metadata": {}, "output_type": "display_data" @@ -1247,7 +1254,7 @@ { "data": { "text/html": "
🚶  Starting 'quickstart'...\n
\n", - "text/plain": "\u001b[32m🚶 \u001b[0m \u001b[1;32mStarting 'quickstart'...\u001b[0m\n" + "text/plain": "\u001B[32m🚶 \u001B[0m \u001B[1;32mStarting 'quickstart'...\u001B[0m\n" }, "metadata": {}, "output_type": "display_data" @@ -1276,7 +1283,7 @@ { "data": { "text/html": "
solver progress (field decay = 1.64e-03) ━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00\n
\n", - "text/plain": "solver progress (field decay = 1.64e-03) \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[35m100%\u001b[0m \u001b[36m0:00:00\u001b[0m\n" + "text/plain": "solver progress (field decay = 1.64e-03) \u001B[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[35m100%\u001B[0m \u001B[36m0:00:00\u001B[0m\n" }, "metadata": {}, "output_type": "display_data" @@ -1305,7 +1312,7 @@ { "data": { "text/html": "
🏃  Finishing 'quickstart'...\n
\n", - "text/plain": "\u001b[32m🏃 \u001b[0m \u001b[1;32mFinishing 'quickstart'...\u001b[0m\n" + "text/plain": "\u001B[32m🏃 \u001B[0m \u001B[1;32mFinishing 'quickstart'...\u001B[0m\n" }, "metadata": {}, "output_type": "display_data" diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py new file mode 100644 index 00000000..a68b9ecd --- /dev/null +++ b/tests/test_quickstart.py @@ -0,0 +1,8 @@ +from testbook import testbook + + +@testbook('../StartHere.ipynb', execute=True) +def test_func(tb): + freq0 = tb.get("freq0") + + assert freq0 == 399723277333333.3 From 4735789a60ff3895673b1d7f92d33e7c37315c38 Mon Sep 17 00:00:00 2001 From: daquintero Date: Tue, 13 Feb 2024 18:12:33 +0100 Subject: [PATCH 2/3] FEAT: Notebook tests working --- tests/README.md | 3 ++ tests/execute_all_notebooks.py | 39 +++++++++++++++++++ .../{test_quickstart.py => test_notebooks.py} | 2 +- tests/utils.py | 0 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/README.md create mode 100644 tests/execute_all_notebooks.py rename tests/{test_quickstart.py => test_notebooks.py} (76%) create mode 100644 tests/utils.py diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..30319aed --- /dev/null +++ b/tests/README.md @@ -0,0 +1,3 @@ +# Testing Instructions + +Make sure to read up on the [testing documentation](https://docs.flexcompute.com/projects/tidy3d/en/latest/development/index.html) before running the tests. \ No newline at end of file diff --git a/tests/execute_all_notebooks.py b/tests/execute_all_notebooks.py new file mode 100644 index 00000000..f351ccce --- /dev/null +++ b/tests/execute_all_notebooks.py @@ -0,0 +1,39 @@ +import os +import pathlib +import pytest +from testbook import testbook + +# # note: these libraries throw Deprecation warnings in python 3.9, so they are ignored in pytest.ini +# import nbformat +# from nbconvert.preprocessors import CellExecutionError +# from nbconvert.preprocessors import ExecutePreprocessor + +# sys.path.append("tidy3d") + +# ep = ExecutePreprocessor(timeout=3000, kernel_name="python3") + +# Get the directory where the current script (or notebook) is located +NOTEBOOKS_DIR = pathlib.Path(__file__).parent.parent.resolve() + +# List all .ipynb files in the directory, excluding the .ipynb_checkpoints directory +notebook_filenames_all = [ + NOTEBOOKS_DIR / f # Use '/' for path concatenation, which is supported by pathlib + for f in os.listdir(NOTEBOOKS_DIR) # Directly use NOTEBOOK_DIR, which is already a Path object + if (f.endswith(".ipynb")) and (not f.startswith(".ipynb_checkpoints")) +] + +# sort alphabetically +notebook_filenames_all.sort() + + +# Loop through notebooks in notebook_filenames and verify they all run. +@pytest.mark.parametrize("notebook_path", argvalues=notebook_filenames_all) +def test_notebooks(notebook_path): + @testbook(notebook_path, execute=True) + def test_notebook(tb): + # Verifies that it executes without error + return 0 + + print("Running: " + str(notebook_path)) + test_notebook(notebook_path) + return 0 diff --git a/tests/test_quickstart.py b/tests/test_notebooks.py similarity index 76% rename from tests/test_quickstart.py rename to tests/test_notebooks.py index a68b9ecd..0b58554e 100644 --- a/tests/test_quickstart.py +++ b/tests/test_notebooks.py @@ -5,4 +5,4 @@ def test_func(tb): freq0 = tb.get("freq0") - assert freq0 == 399723277333333.3 + assert freq0 == 399723277333333.3 \ No newline at end of file diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 00000000..e69de29b From 2906ccbe80dcf48b15ab57502b241f7af2bf8799 Mon Sep 17 00:00:00 2001 From: daquintero Date: Fri, 16 Feb 2024 16:50:56 +0100 Subject: [PATCH 3/3] TEST: Updates --- tests/execute_all_notebooks.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/execute_all_notebooks.py b/tests/execute_all_notebooks.py index f351ccce..68954db6 100644 --- a/tests/execute_all_notebooks.py +++ b/tests/execute_all_notebooks.py @@ -3,14 +3,6 @@ import pytest from testbook import testbook -# # note: these libraries throw Deprecation warnings in python 3.9, so they are ignored in pytest.ini -# import nbformat -# from nbconvert.preprocessors import CellExecutionError -# from nbconvert.preprocessors import ExecutePreprocessor - -# sys.path.append("tidy3d") - -# ep = ExecutePreprocessor(timeout=3000, kernel_name="python3") # Get the directory where the current script (or notebook) is located NOTEBOOKS_DIR = pathlib.Path(__file__).parent.parent.resolve()