Skip to content

Commit

Permalink
Updates for 0.51.0
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-naveh committed Sep 29, 2024
1 parent 78df43a commit 16dc6ef
Show file tree
Hide file tree
Showing 17 changed files with 875 additions and 415 deletions.
11 changes: 2 additions & 9 deletions algorithms/algebraic/discrete_log/discrete_log.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
" x2: QArray[QBit],\n",
" func_res: Output[QArray[QBit]],\n",
") -> None:\n",
"\n",
" allocate(ceiling(log(N_modulus, 2)), func_res)\n",
"\n",
" inplace_prepare_int(1, func_res)\n",
Expand Down Expand Up @@ -215,9 +214,7 @@
{
"name": "stdout",
"output_type": "stream",
"text": [
""
]
"text": []
}
],
"source": [
Expand Down Expand Up @@ -401,9 +398,7 @@
{
"name": "stdout",
"output_type": "stream",
"text": [
""
]
"text": []
}
],
"source": [
Expand Down Expand Up @@ -550,8 +545,6 @@
}
],
"source": [
"import math\n",
"\n",
"logarithm = None\n",
"for sample in parsed:\n",
" try:\n",
Expand Down
12 changes: 3 additions & 9 deletions algorithms/algebraic/shor/shor_modular_exponentiation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@
{
"name": "stdout",
"output_type": "stream",
"text": [
""
]
"text": []
}
],
"source": [
Expand Down Expand Up @@ -571,16 +569,12 @@
"cell_type": "code",
"execution_count": 10,
"id": "8e9d0b08-f3f8-4e95-a468-bfeec010d97c",
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
""
]
"text": []
}
],
"source": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,7 @@
{
"name": "stdout",
"output_type": "stream",
"text": [
""
]
"text": []
}
],
"source": [
Expand Down Expand Up @@ -561,16 +559,12 @@
"cell_type": "code",
"execution_count": 14,
"id": "b127fa25-1285-49f4-9fe3-43a57f984d2d",
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
""
]
"text": []
}
],
"source": [
Expand All @@ -597,9 +591,7 @@
"cell_type": "code",
"execution_count": 15,
"id": "c1110098-1af8-4c2a-9ca7-14b8d36e75f3",
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down
48 changes: 7 additions & 41 deletions algorithms/grover/grover_max_cut/grover_max_cut.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@
" )\n",
"\n",
"\n",
"qmod = create_model(main)"
"qmod = create_model(main)\n",
"qmod = set_constraints(qmod, max_width=22)\n",
"write_qmod(qmod, \"grover_max_cut\")"
]
},
{
Expand All @@ -224,28 +226,6 @@
"We proceed by synthesizing the circuit using Classiq's synthesis engine. The synthesis should take approximately several seconds:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "542b41be-c61c-42cf-a6ea-062a9c8abc01",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"qmod = set_constraints(qmod, Constraints(max_width=22))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "e400ac31-f38f-4855-a00b-c3b599ce299c",
"metadata": {},
"outputs": [],
"source": [
"write_qmod(qmod, \"grover_max_cut\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
Expand Down Expand Up @@ -284,9 +264,7 @@
{
"name": "stdout",
"output_type": "stream",
"text": [
""
]
"text": []
}
],
"source": [
Expand Down Expand Up @@ -342,19 +320,7 @@
},
"outputs": [],
"source": [
"optimization_result = execute(qprog).result()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "9ccbd6e5-c1ce-4818-bebe-78294e0690fe",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"res = optimization_result[0].value"
"optimization_result = execute(qprog).result_value()"
]
},
{
Expand Down Expand Up @@ -420,7 +386,7 @@
}
],
"source": [
"res.parsed_counts"
"optimization_result.parsed_counts"
]
},
{
Expand All @@ -440,7 +406,7 @@
},
"outputs": [],
"source": [
"most_probable_result = res.parsed_counts[0]"
"most_probable_result = optimization_result.parsed_counts[0]"
]
},
{
Expand Down
48 changes: 3 additions & 45 deletions algorithms/hhl/hhl/hhl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
}
],
"source": [
"from classiq import matrix_to_hamiltonian\n",
"from classiq import *\n",
"\n",
"hamiltonian = matrix_to_hamiltonian(A)\n",
"n = len(hamiltonian[0].pauli)\n",
Expand Down Expand Up @@ -256,19 +256,6 @@
},
"outputs": [],
"source": [
"from classiq import (\n",
" CArray,\n",
" CInt,\n",
" CReal,\n",
" Output,\n",
" QArray,\n",
" QBit,\n",
" QCallable,\n",
" prepare_amplitudes,\n",
" qfunc,\n",
")\n",
"\n",
"\n",
"@qfunc\n",
"def load_b(\n",
" amplitudes: CArray[CReal], state: Output[QArray[QBit]], bound: CReal\n",
Expand Down Expand Up @@ -323,22 +310,6 @@
},
"outputs": [],
"source": [
"from classiq import (\n",
" CInt,\n",
" Output,\n",
" PauliTerm,\n",
" QArray,\n",
" QBit,\n",
" QCallable,\n",
" QNum,\n",
" allocate,\n",
" allocate_num,\n",
" create_model,\n",
" qfunc,\n",
" qpe_flexible,\n",
" synthesize,\n",
" within_apply,\n",
")\n",
"from classiq.qmod.symbolic import floor, log\n",
"\n",
"# Parameters for the initial state preparation\n",
Expand All @@ -365,7 +336,6 @@
" phase: Output[QNum],\n",
" indicator: Output[QBit],\n",
"):\n",
"\n",
" # Allocate a quantum number for the phase with given precision\n",
" allocate_num(precision, False, precision, phase)\n",
"\n",
Expand Down Expand Up @@ -410,7 +380,6 @@
" ClassiqSimulatorBackendNames,\n",
" ExecutionPreferences,\n",
")\n",
"from classiq.synthesis import set_execution_preferences\n",
"\n",
"backend_preferences = ClassiqBackendPreferences(\n",
" backend_name=ClassiqSimulatorBackendNames.SIMULATOR_STATEVECTOR\n",
Expand Down Expand Up @@ -463,7 +432,6 @@
"outputs": [],
"source": [
"def read_positions(circuit_hhl, res_hhl):\n",
"\n",
" # positions of control qubit\n",
" target_pos = res_hhl.physical_qubits_map[\"indicator\"][0]\n",
"\n",
Expand Down Expand Up @@ -520,7 +488,6 @@
"outputs": [],
"source": [
"def quantum_solution(circuit_hhl, res_hhl, precision):\n",
"\n",
" target_pos, sol_pos, phase_pos = read_positions(circuit_hhl, res_hhl)\n",
"\n",
" # Read Quantum solution from the entries of `res` registers, where the target register `indicator` is 1 and the `phase` register is in state |0>^m\n",
Expand Down Expand Up @@ -561,7 +528,6 @@
"\n",
"\n",
"def quantum_solution_preprocessed(A, b, circuit_hhl, res_hhl, precision, disp=True):\n",
"\n",
" # Classical solution\n",
" sol_classical = np.linalg.solve(A, b)\n",
" if disp:\n",
Expand All @@ -587,7 +553,6 @@
"\n",
"\n",
"def show_solutions(A, b, circuit_hhl, res_hhl, precision, check=True, disp=True):\n",
"\n",
" # Classical solution and preprocessed quantum solution\n",
" sol_classical, qsol_corrected = quantum_solution_preprocessed(\n",
" A, b, circuit_hhl, res_hhl, QPE_SIZE, disp=disp\n",
Expand Down Expand Up @@ -747,15 +712,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
"",
"Circuit depth = 461\n",
"Circuit CX count = 288\n"
]
}
],
"source": [
"from classiq import QuantumProgram, show, synthesize\n",
"\n",
"qprog_hhl_exact = synthesize(qmod_hhl_exact)\n",
"show(qprog_hhl_exact)\n",
"\n",
Expand Down Expand Up @@ -798,10 +760,9 @@
},
"outputs": [],
"source": [
"from classiq import execute\n",
"from classiq.execution import ExecutionDetails\n",
"\n",
"res_hhl_exact = execute(qprog_hhl_exact).result()[0].value"
"res_hhl_exact = execute(qprog_hhl_exact).result_value()"
]
},
{
Expand Down Expand Up @@ -920,7 +881,6 @@
},
"outputs": [],
"source": [
"from classiq import CArray, CReal, suzuki_trotter\n",
"from classiq.qmod.symbolic import ceiling, log\n",
"\n",
"\n",
Expand Down Expand Up @@ -961,7 +921,6 @@
},
"outputs": [],
"source": [
"from classiq import Output, create_model, prepare_amplitudes, synthesize\n",
"from classiq.qmod.symbolic import floor\n",
"\n",
"# parameters for the amplitude preparation\n",
Expand Down Expand Up @@ -1033,7 +992,6 @@
"name": "stdout",
"output_type": "stream",
"text": [
"",
"Circuit depth = 5074\n",
"Circuit CX count = 2968\n",
"\n",
Expand Down Expand Up @@ -1067,7 +1025,7 @@
"print()\n",
"\n",
"# Show results\n",
"res_hhl_trotter = execute(qprog_hhl_trotter).result()[0].value\n",
"res_hhl_trotter = execute(qprog_hhl_trotter).result_value()\n",
"show_solutions(A, b, circuit_hhl_trotter, res_hhl_trotter, precision)"
]
},
Expand Down
Loading

0 comments on commit 16dc6ef

Please sign in to comment.