Skip to content

Commit

Permalink
Add test: linear_combination_of_unitaries
Browse files Browse the repository at this point in the history
  • Loading branch information
classiqdor committed Mar 6, 2025
1 parent bb4355c commit 1ed9088
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
28 changes: 28 additions & 0 deletions tests/notebooks/test_linear_combination_of_unitaries.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 1,
"id": "58e277dd",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -169,7 +169,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 2,
"id": "1fe3de0d-c13c-42cc-babd-77c577372874",
"metadata": {},
"outputs": [],
Expand All @@ -195,7 +195,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 3,
"id": "82854a21",
"metadata": {},
"outputs": [],
Expand All @@ -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)"
]
},
{
Expand All @@ -225,20 +226,20 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 4,
"id": "262dd6f5",
"metadata": {},
"outputs": [
{
"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)"
]
},
{
Expand Down Expand Up @@ -290,15 +291,15 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 5,
"id": "03804a1a",
"metadata": {},
"outputs": [
{
"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"
]
}
],
Expand All @@ -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",
Expand All @@ -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)"
]
},
{
Expand All @@ -351,16 +354,6 @@
"<a id='childs_notes'>[2]</a>: [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": {
Expand Down

0 comments on commit 1ed9088

Please sign in to comment.