From 1ed9088dc4a10d46750e121c6be970ee78101844 Mon Sep 17 00:00:00 2001 From: Dor Harpaz Date: Thu, 6 Mar 2025 15:55:00 +0200 Subject: [PATCH] Add test: linear_combination_of_unitaries --- .../test_linear_combination_of_unitaries.py | 28 +++++++++++++ .../linear_combination_of_unitaries.ipynb | 41 ++++++++----------- 2 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 tests/notebooks/test_linear_combination_of_unitaries.py diff --git a/tests/notebooks/test_linear_combination_of_unitaries.py b/tests/notebooks/test_linear_combination_of_unitaries.py new file mode 100644 index 00000000..34311d32 --- /dev/null +++ b/tests/notebooks/test_linear_combination_of_unitaries.py @@ -0,0 +1,28 @@ +from tests.utils_for_testbook import ( + validate_quantum_program_size, + validate_quantum_model, + wrap_testbook, +) +from testbook.client import TestbookNotebookClient + + +@wrap_testbook("linear_combination_of_unitaries", timeout_seconds=20) +def test_notebook(tb: TestbookNotebookClient) -> None: + # test models + validate_quantum_model(tb.ref("qmod_1")) + validate_quantum_model(tb.ref("qmod_2")) + + # test quantum programs + validate_quantum_program_size( + tb.ref("qprog_1"), + expected_width=5, # actual width: 4 + expected_depth=500, # actual depth: 372 + ) + validate_quantum_program_size( + tb.ref("qprog_2"), + expected_width=5, # actual width: 4 + expected_depth=500, # actual depth: 372 + ) + + # test notebook content + pass # Todo diff --git a/tutorials/advanced_tutorials/linear_combination_of_unitaries/linear_combination_of_unitaries.ipynb b/tutorials/advanced_tutorials/linear_combination_of_unitaries/linear_combination_of_unitaries.ipynb index 3c5cb17f..3fcd43ae 100644 --- a/tutorials/advanced_tutorials/linear_combination_of_unitaries/linear_combination_of_unitaries.ipynb +++ b/tutorials/advanced_tutorials/linear_combination_of_unitaries/linear_combination_of_unitaries.ipynb @@ -126,7 +126,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 1, "id": "58e277dd", "metadata": {}, "outputs": [], @@ -169,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 2, "id": "1fe3de0d-c13c-42cc-babd-77c577372874", "metadata": {}, "outputs": [], @@ -195,7 +195,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 3, "id": "82854a21", "metadata": {}, "outputs": [], @@ -211,8 +211,9 @@ " apply=lambda: select(controller, psi),\n", " )\n", "\n", - "quantum_model = create_model(main)\n", - "quantum_program = synthesize(quantum_model)" + "\n", + "qmod_1 = create_model(main)\n", + "qprog_1 = synthesize(qmod_1)" ] }, { @@ -225,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 4, "id": "262dd6f5", "metadata": {}, "outputs": [ @@ -233,12 +234,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "Opening: https://platform.classiq.io/circuit/2sDTrI2KmNNYeCfOTeSOrt4W0sC?version=0.66.0\n" + "Opening: https://platform.classiq.io/circuit/2twhaKXfhxHpjDTuYqwIlUebB8c?version=0.70.0\n" ] } ], "source": [ - "show(quantum_program)" + "show(qprog_1)" ] }, { @@ -290,7 +291,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "id": "03804a1a", "metadata": {}, "outputs": [ @@ -298,7 +299,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Opening: https://platform.classiq.io/circuit/2sqWYKfPmYSb9oL9myDA0jJsCye?version=0.66.1\n" + "Opening: https://platform.classiq.io/circuit/2twhb9xii5m4B8N1K4wz3d8EkTk?version=0.70.0\n" ] } ], @@ -321,7 +322,8 @@ " error_bound = 0.01\n", " controller_probabilities = [0.5, 0.25, 0.25, 0]\n", " inplace_prepare_state(controller_probabilities, error_bound, controller)\n", - " \n", + "\n", + "\n", "@qfunc\n", "def main(controller: Output[QNum], psi: Output[QNum]):\n", " # Allocating the target and control qubits, respectively\n", @@ -333,10 +335,11 @@ " apply=lambda: select(controller, psi),\n", " )\n", "\n", - "quantum_model = create_model(main)\n", - "quantum_program = synthesize(quantum_model)\n", "\n", - "show(quantum_program)" + "qmod_2 = create_model(main, out_file=\"linear_combination_of_unitaries\")\n", + "qprog_2 = synthesize(qmod_2)\n", + "\n", + "show(qprog_2)" ] }, { @@ -351,16 +354,6 @@ "[2]: [Lecture Notes on\n", "Quantum Algorithms (Andrew M. Childs)](https://www.cs.umd.edu/~amchilds/qa/qa.pdf)" ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "5937706e", - "metadata": {}, - "outputs": [], - "source": [ - "write_qmod(quantum_model, \"linear_combination_of_unitaries\")" - ] } ], "metadata": {