From 50511a4a0918520007605e527761a81a270d1713 Mon Sep 17 00:00:00 2001 From: Dor Harpaz Date: Thu, 20 Feb 2025 17:07:24 +0200 Subject: [PATCH 1/3] Add test: facility_location --- tests/notebooks/test_facility_location.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/notebooks/test_facility_location.py diff --git a/tests/notebooks/test_facility_location.py b/tests/notebooks/test_facility_location.py new file mode 100644 index 00000000..f5f43480 --- /dev/null +++ b/tests/notebooks/test_facility_location.py @@ -0,0 +1,21 @@ +from tests.utils_for_testbook import ( + validate_quantum_program_size, + validate_quantum_model, + wrap_testbook, +) +from testbook.client import TestbookNotebookClient + + +@wrap_testbook("facility_location", timeout_seconds=1656) +def test_notebook(tb: TestbookNotebookClient) -> None: + # test models + validate_quantum_model(tb.ref("qmod")) + # test quantum programs + validate_quantum_program_size( + tb.ref("qprog"), + expected_width=15, # actual width: 12 + expected_depth=1000, # actual depth: 9237 + ) + + # test notebook content + pass # todo From d06dbfb805874634d8f9155b4833e49180009681 Mon Sep 17 00:00:00 2001 From: Dor Harpaz Date: Thu, 20 Feb 2025 17:08:54 +0200 Subject: [PATCH 2/3] Add test: task_scheduling_problem --- .../task_scheduling_problem.ipynb | 16 +++++------ .../notebooks/test_task_scheduling_problem.py | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 tests/notebooks/test_task_scheduling_problem.py diff --git a/applications/logistics/task_scheduling_problem/task_scheduling_problem.ipynb b/applications/logistics/task_scheduling_problem/task_scheduling_problem.ipynb index 13694080..e143e426 100644 --- a/applications/logistics/task_scheduling_problem/task_scheduling_problem.ipynb +++ b/applications/logistics/task_scheduling_problem/task_scheduling_problem.ipynb @@ -1501,16 +1501,16 @@ "\n", "optimizer_config = OptimizerConfig(max_iteration=1, alpha_cvar=0.6)\n", "\n", - "qmod = construct_combinatorial_optimization_model(\n", + "qmod_large = construct_combinatorial_optimization_model(\n", " pyo_model=tasks_model_large,\n", " qaoa_config=qaoa_config,\n", " optimizer_config=optimizer_config,\n", ")\n", "\n", - "qmod = set_execution_preferences(\n", - " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n", + "qmod_large = set_execution_preferences(\n", + " qmod_large, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n", ")\n", - "write_qmod(qmod, \"task_scheduling_problem_large\")" + "write_qmod(qmod_large, \"task_scheduling_problem_large\")" ] }, { @@ -1539,8 +1539,8 @@ } ], "source": [ - "qprog = synthesize(qmod)\n", - "show(qprog)" + "qprog_large = synthesize(qmod_large)\n", + "show(qprog_large)" ] }, { @@ -1558,7 +1558,7 @@ }, "outputs": [], "source": [ - "result = execute(qprog).result_value()" + "result_large = execute(qprog_large).result_value()" ] }, { @@ -1688,7 +1688,7 @@ "\n", "solution = get_optimization_solution_from_pyo(\n", " tasks_model_large,\n", - " vqe_result=result,\n", + " vqe_result=result_large,\n", " penalty_energy=qaoa_config.penalty_energy,\n", ")\n", "optimization_result = pd.DataFrame.from_records(solution)\n", diff --git a/tests/notebooks/test_task_scheduling_problem.py b/tests/notebooks/test_task_scheduling_problem.py new file mode 100644 index 00000000..7f0519bb --- /dev/null +++ b/tests/notebooks/test_task_scheduling_problem.py @@ -0,0 +1,27 @@ +from tests.utils_for_testbook import ( + validate_quantum_program_size, + validate_quantum_model, + wrap_testbook, +) +from testbook.client import TestbookNotebookClient + + +@wrap_testbook("task_scheduling_problem", timeout_seconds=840) +def test_notebook(tb: TestbookNotebookClient) -> None: + # test models + validate_quantum_model(tb.ref("qmod")) + validate_quantum_model(tb.ref("qmod_large")) + # test quantum programs + validate_quantum_program_size( + tb.ref("qprog"), + expected_width=8, # actual width: 6 + expected_depth=120, # actual depth: 92 + ) + validate_quantum_program_size( + tb.ref("qprog_large"), + expected_width=30, # actual width: 24 + expected_depth=500, # actual depth: 428 + ) + + # test notebook content + pass # todo From d5fd6b5561772bc797162d63c5bf45542a20dcdd Mon Sep 17 00:00:00 2001 From: Dor Harpaz Date: Thu, 20 Feb 2025 17:26:52 +0200 Subject: [PATCH 3/3] Add test: traveling_salesman_problem --- .../test_traveling_salesman_problem.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/notebooks/test_traveling_salesman_problem.py diff --git a/tests/notebooks/test_traveling_salesman_problem.py b/tests/notebooks/test_traveling_salesman_problem.py new file mode 100644 index 00000000..6602d9e8 --- /dev/null +++ b/tests/notebooks/test_traveling_salesman_problem.py @@ -0,0 +1,21 @@ +from tests.utils_for_testbook import ( + validate_quantum_program_size, + validate_quantum_model, + wrap_testbook, +) +from testbook.client import TestbookNotebookClient + + +@wrap_testbook("traveling_salesman_problem", timeout_seconds=1068) +def test_notebook(tb: TestbookNotebookClient) -> None: + # test models + validate_quantum_model(tb.ref("qmod")) + # test quantum programs + validate_quantum_program_size( + tb.ref("qprog"), + expected_width=16, # actual width: 16 + expected_depth=567, # actual depth: 567 + ) + + # test notebook content + pass # todo