Skip to content

Remove usages of from qprog method #931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions algorithms/aqc/solving_qlsp/solving_qlsp_with_aqc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@
}
],
"source": [
"print(\"Program depth:\", QuantumProgram.from_qprog(qprog_1).transpiled_circuit.depth)"
"print(\"Program depth:\", qprog_1.transpiled_circuit.depth)"
]
},
{
Expand Down Expand Up @@ -1000,7 +1000,7 @@
}
],
"source": [
"print(\"Program depth:\", QuantumProgram.from_qprog(qprog_2).transpiled_circuit.depth)"
"print(\"Program depth:\", qprog_2.transpiled_circuit.depth)"
]
},
{
Expand Down Expand Up @@ -1126,7 +1126,7 @@
}
],
"source": [
"print(\"Program depth:\", QuantumProgram.from_qprog(qprog_3).transpiled_circuit.depth)"
"print(\"Program depth:\", qprog_3.transpiled_circuit.depth)"
]
},
{
Expand Down
16 changes: 7 additions & 9 deletions algorithms/hhl/hhl/hhl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,8 @@
"qprog_hhl_exact = synthesize(qmod_hhl_exact)\n",
"show(qprog_hhl_exact)\n",
"\n",
"circuit_hhl_exact = QuantumProgram.from_qprog(qprog_hhl_exact)\n",
"print(\"Circuit depth = \", circuit_hhl_exact.transpiled_circuit.depth)\n",
"print(\"Circuit CX count = \", circuit_hhl_exact.transpiled_circuit.count_ops[\"cx\"])"
"print(\"Circuit depth = \", qprog_hhl_exact.transpiled_circuit.depth)\n",
"print(\"Circuit CX count = \", qprog_hhl_exact.transpiled_circuit.count_ops[\"cx\"])"
]
},
{
Expand Down Expand Up @@ -792,7 +791,7 @@
}
],
"source": [
"qsol = quantum_solution(circuit_hhl_exact, res_hhl_exact, precision)\n",
"qsol = quantum_solution(qprog_hhl_exact, res_hhl_exact, precision)\n",
"qsol"
]
},
Expand Down Expand Up @@ -843,7 +842,7 @@
],
"source": [
"precision = QPE_SIZE\n",
"show_solutions(A, b, circuit_hhl_exact, res_hhl_exact, precision, check=False)"
"show_solutions(A, b, qprog_hhl_exact, res_hhl_exact, precision, check=False)"
]
},
{
Expand Down Expand Up @@ -1019,14 +1018,13 @@
"show(qprog_hhl_trotter)\n",
"\n",
"# Show circuit\n",
"circuit_hhl_trotter = QuantumProgram.from_qprog(qprog_hhl_trotter)\n",
"print(\"Circuit depth = \", circuit_hhl_trotter.transpiled_circuit.depth)\n",
"print(\"Circuit CX count = \", circuit_hhl_trotter.transpiled_circuit.count_ops[\"cx\"])\n",
"print(\"Circuit depth = \", qprog_hhl_trotter.transpiled_circuit.depth)\n",
"print(\"Circuit CX count = \", qprog_hhl_trotter.transpiled_circuit.count_ops[\"cx\"])\n",
"print()\n",
"\n",
"# Show results\n",
"res_hhl_trotter = execute(qprog_hhl_trotter).result_value()\n",
"show_solutions(A, b, circuit_hhl_trotter, res_hhl_trotter, precision)"
"show_solutions(A, b, qprog_hhl_trotter, res_hhl_trotter, precision)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,7 @@
},
"outputs": [],
"source": [
"from classiq import QuantumProgram\n",
"circuit = QuantumProgram.from_qprog(qprog)\n",
"print(\"Circuit width: \", circuit.data.width)"
"print(\"Circuit width: \", qprog.data.width)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"# Solving the Advection Equation\n"
]
},
Expand Down Expand Up @@ -501,10 +502,9 @@
],
"source": [
"r, qprog_t_1 = solve(n_qbits, t, tau)\n",
"circuit = QuantumProgram.from_qprog(qprog_t_1)\n",
"width = circuit.data.width\n",
"depth = circuit.transpiled_circuit.depth\n",
"cx_count = circuit.transpiled_circuit.count_ops[\"cx\"]\n",
"width = qprog_t_1.data.width\n",
"depth = qprog_t_1.transpiled_circuit.depth\n",
"cx_count = qprog_t_1.transpiled_circuit.count_ops[\"cx\"]\n",
"print(f\"width={width}\\ndepth={depth}\\ncx count={cx_count}\")\n",
"\n",
"position = np.linspace(0.0, 4.0, 2**n_qbits)\n",
Expand Down Expand Up @@ -603,8 +603,7 @@
"outputs": [],
"source": [
"def count_cx_ops_in_qprog(qprog) -> int:\n",
" circuit = QuantumProgram.from_qprog(qprog)\n",
" return circuit.transpiled_circuit.count_ops[\"cx\"]\n",
" return qprog.transpiled_circuit.count_ops[\"cx\"]\n",
"\n",
"\n",
"def count_cx_ops(n_qbits: int, t: float, tau: float) -> int:\n",
Expand Down Expand Up @@ -803,8 +802,7 @@
"\n",
" my_model = create_model(main)\n",
" my_qprog = synthesize(my_model)\n",
" circuit = QuantumProgram.from_qprog(my_qprog)\n",
" return circuit.transpiled_circuit.count_ops[\"cx\"]\n",
" return my_qprog.transpiled_circuit.count_ops[\"cx\"]\n",
"\n",
"\n",
"cx_counts_for_cry = {\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"id": "3652aca5-46be-454d-9b5e-5b795379c534"
},
"source": [
"# Solving the Advection Equation (Hamiltonian Simulation)"
"\\# Solving the Advection Equation (Hamiltonian Simulation)"
]
},
{
Expand Down Expand Up @@ -2091,8 +2091,7 @@
" qprog = synthesize(qmod)\n",
"\n",
" # Extract CX count and depth from synthesized circuit\n",
" circuit = QuantumProgram.from_qprog(qprog)\n",
" cx_count = circuit.transpiled_circuit.count_ops['cx']\n",
" cx_count = qprog.transpiled_circuit.count_ops['cx']\n",
" return cx_count"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,12 @@
" - \"width\": Circuit width (number of qubits used).\n",
" - \"cx_count\": Number of CX gates (returns 0 if none are present).\n",
" \"\"\"\n",
" # Generate the optimized quantum circuit\n",
" circuit = QuantumProgram.from_qprog(qprog)\n",
"\n",
" # Extract metrics\n",
" metrics = {\n",
" \"depth\": circuit.transpiled_circuit.depth,\n",
" \"width\": circuit.data.width,\n",
" \"cx_count\": circuit.transpiled_circuit.count_ops.get(\n",
" \"depth\": qprog.transpiled_circuit.depth,\n",
" \"width\": qprog.data.width,\n",
" \"cx_count\": qprog.transpiled_circuit.count_ops.get(\n",
" \"cx\", 0\n",
" ), # Default to 0 if 'cx' not found\n",
" }\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,14 +817,11 @@
" - \"width\": Circuit width (number of qubits used).\n",
" - \"cx_count\": Number of CX gates (returns 0 if none are present).\n",
" \"\"\"\n",
" # Generate the optimized quantum circuit\n",
" circuit = QuantumProgram.from_qprog(qprog)\n",
"\n",
" # Extract metrics\n",
" metrics = {\n",
" \"depth\": circuit.transpiled_circuit.depth,\n",
" \"width\": circuit.data.width,\n",
" \"cx_count\": circuit.transpiled_circuit.count_ops.get(\n",
" \"depth\": qprog.transpiled_circuit.depth,\n",
" \"width\": qprog.data.width,\n",
" \"cx_count\": qprog.transpiled_circuit.count_ops.get(\n",
" \"cx\", 0\n",
" ), # Default to 0 if 'cx' not found\n",
" }\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,14 +709,11 @@
" - \"width\": Circuit width (number of qubits used).\n",
" - \"cx_count\": Number of CX gates (returns 0 if none are present).\n",
" \"\"\"\n",
" # Generate the optimized quantum circuit\n",
" circuit = QuantumProgram.from_qprog(qprog)\n",
"\n",
" # Extract metrics\n",
" metrics = {\n",
" \"depth\": circuit.transpiled_circuit.depth,\n",
" \"width\": circuit.data.width,\n",
" \"cx_count\": circuit.transpiled_circuit.count_ops.get(\n",
" \"depth\": qprog.transpiled_circuit.depth,\n",
" \"width\": qprog.data.width,\n",
" \"cx_count\": qprog.transpiled_circuit.count_ops.get(\n",
" \"cx\", 0\n",
" ), # Default to 0 if 'cx' not found\n",
" }\n",
Expand Down Expand Up @@ -846,7 +843,7 @@
" f\"{team_name.replace(' ','_')}__stage_{stage}__resolution_{resolution}.qprog\"\n",
" )\n",
" with open(os.path.join(folder, file_name), \"w\") as f:\n",
" f.write(qprog)"
" f.write(qprog.model_dump_json(indent=2))"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@
" SavedResult,\n",
")\n",
"from classiq.execution import execute_qnn\n",
"from classiq.synthesis import SerializedQuantumProgram\n",
"from classiq import QuantumProgram\n",
"\n",
"\n",
"def execute(\n",
" quantum_program: SerializedQuantumProgram, arguments: MultipleArguments\n",
" quantum_program: QuantumProgram, arguments: MultipleArguments\n",
") -> ResultsCollection:\n",
" return execute_qnn(quantum_program, arguments)\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@
}
],
"source": [
"circuit = QuantumProgram.from_qprog(qprog)\n",
"print(f\"Synthesized MCX depth is {circuit.transpiled_circuit.depth}\")"
"print(f\"Synthesized MCX depth is {qprog.transpiled_circuit.depth}\")"
]
},
{
Expand Down Expand Up @@ -536,12 +535,10 @@
}
],
"source": [
"circuit_grid = QuantumProgram.from_qprog(qprog_grid)\n",
"\n",
"print(\n",
" f\"Synthesized MCX cx-count for grid connectivity is {circuit_grid.transpiled_circuit.count_ops['cx']}\"\n",
" f\"Synthesized MCX cx-count for grid connectivity is {qprog.transpiled_circuit.count_ops['cx']}\"\n",
")\n",
"circuit_grid.show()"
"qprog.show()"
]
},
{
Expand Down Expand Up @@ -589,12 +586,10 @@
}
],
"source": [
"circuit_star = QuantumProgram.from_qprog(qprog_star)\n",
"\n",
"print(\n",
" f\"Synthesized MCX cx-count for star connectivity is {circuit_star.transpiled_circuit.count_ops['cx']}\"\n",
" f\"Synthesized MCX cx-count for star connectivity is {qprog.transpiled_circuit.count_ops['cx']}\"\n",
")\n",
"circuit_star.show()"
"qprog.show()"
]
},
{
Expand All @@ -618,7 +613,7 @@
],
"source": [
"print(\n",
" f\"Synthesized Depth for grid connectivity is {circuit_grid.transpiled_circuit.depth}\"\n",
" f\"Synthesized Depth for grid connectivity is {qprog.transpiled_circuit.depth}\"\n",
")"
]
},
Expand All @@ -643,7 +638,7 @@
],
"source": [
"print(\n",
" f\"Synthesized Depth for star connectivity is {circuit_star.transpiled_circuit.depth}\"\n",
" f\"Synthesized Depth for star connectivity is {qprog.transpiled_circuit.depth}\"\n",
")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@
")\n",
"qprog = synthesize(qmod)\n",
"\n",
"circuit = QuantumProgram.from_qprog(qprog)\n",
"\n",
"print(\"Circuit depth: %i\\n\" % circuit.program_circuit.depth)\n",
"print(\"Circuit depth: %i\\n\" % qprog.program_circuit.depth)\n",
"\n",
"show(qprog)"
]
Expand Down Expand Up @@ -213,9 +211,7 @@
"model = set_preferences(model, preferences=preferences)\n",
"qprog = synthesize(model)\n",
"\n",
"circuit = QuantumProgram.from_qprog(qprog)\n",
"\n",
"print(\"Circuit depth: %i\\n\" % circuit.program_circuit.depth)\n",
"print(\"Circuit depth: %i\\n\" % qprog.program_circuit.depth)\n",
"\n",
"show(qprog)"
]
Expand Down Expand Up @@ -306,9 +302,7 @@
"model = set_preferences(model, preferences=preferences)\n",
"qprog = synthesize(model)\n",
"\n",
"circuit = QuantumProgram.from_qprog(qprog)\n",
"\n",
"print(\"Circuit depth: %i\\n\" % circuit.program_circuit.depth)\n",
"print(\"Circuit depth: %i\\n\" % qprog.program_circuit.depth)\n",
"\n",
"show(qprog)"
]
Expand Down Expand Up @@ -863,8 +857,8 @@
"\n",
" end = time.time()\n",
"\n",
" #circuit = QuantumProgram.from_qprog(qprog)\n",
" #circuit.show(True)\n",
"\n",
" # show(qprog)\n",
"\n",
" error_rate = results_error_rate(res)\n",
"\n",
Expand Down
4 changes: 1 addition & 3 deletions community/basic_examples/superposition/superposition.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
"\n",
"qprog = synthesize(model)\n",
"\n",
"circuit = QuantumProgram.from_qprog(qprog)\n",
"\n",
"circuit.show()"
"show(qprog)\n"
]
},
{
Expand Down
9 changes: 3 additions & 6 deletions tests/utils_for_testbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,15 @@ def validate_quantum_program_size(

return validate_quantum_program_size(quantum_program, other_width, other_depth)

qp = QuantumProgram.from_qprog(quantum_program)


actual_width = qp.data.width
actual_width = quantum_program.data.width
if expected_width is not None:
assert (
actual_width <= expected_width
), f"The width of the circuit changed! (for the worse!). From {expected_width} to {actual_width}"
assert allow_zero_size or actual_width > 0, "Got a 0-width circuit."

assert qp.transpiled_circuit is not None # for mypy
actual_depth = qp.transpiled_circuit.depth
assert quantum_program.transpiled_circuit is not None # for mypy
actual_depth = quantum_program.transpiled_circuit.depth
if expected_depth is not None:
assert (
actual_depth <= expected_depth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@
"\n",
"qprog = synthesize(qmod)\n",
"\n",
"circuit = QuantumProgram.from_qprog(qprog)\n",
"print(f\"Classiq's exponentiation depth is {circuit.transpiled_circuit.depth}\")\n",
"print(f\"Classiq's exponentiation depth is {qprog.transpiled_circuit.depth}\")\n",
"print(\n",
" f\"Classiq's exponentiation CX-count is {circuit.transpiled_circuit.count_ops['cx']}\"\n",
" f\"Classiq's exponentiation CX-count is {qprog.transpiled_circuit.count_ops['cx']}\"\n",
")\n",
"show(qprog)"
]
Expand Down
Loading