Skip to content
Open

Hhl new #1317

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
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,7 @@
"def main(indicator: Output[QBit], test: Output[QBit]) -> None:\n",
"\n",
" state = QArray()\n",
" # free(state)\n",
"\n",
" compared_state = QArray()\n",
" # free(compared_state)\n",
" rescaled_eig = QNum()\n",
" allocate(QPE_RESOLUTION_SIZE, UNSIGNED, QPE_RESOLUTION_SIZE, rescaled_eig)\n",
" prepare_amplitudes(b_list, 0, state)\n",
Expand Down Expand Up @@ -661,10 +658,7 @@
"outputs": [],
"source": [
"MAX_WIDTH_SWAP_TEST = 25\n",
"constraints = Constraints(\n",
" max_width=MAX_WIDTH_SWAP_TEST,\n",
" # optimization_parameter=OptimizationParameter.DEPTH,\n",
")\n",
"constraints = Constraints(max_width=MAX_WIDTH_SWAP_TEST)\n",
"preferences = Preferences(\n",
" optimization_level=0, optimization_timeout_seconds=90, transpilation_option=\"none\"\n",
")\n",
Expand Down Expand Up @@ -692,7 +686,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Quantum program link: https://platform.classiq.io/circuit/35jejQgpemeARnyckevOUff3PsD\n"
"Quantum program link: https://platform.classiq.io/circuit/35tN4TKVCACNL14VMInDJb2alDZ\n"
]
}
],
Expand Down Expand Up @@ -740,7 +734,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Fidelity between basic HHL and classical solutions: 0.9575437746802776\n"
"Fidelity between basic HHL and classical solutions: 0.9526849928765404\n"
]
}
],
Expand Down Expand Up @@ -794,7 +788,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Quantum program link: https://platform.classiq.io/circuit/35jewVJCfz6qFWnj4neZxImOmxh\n"
"Quantum program link: https://platform.classiq.io/circuit/35tNJgp5JBnQjy397u9i5ZqNFvs\n"
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
"preferences": {
"custom_hardware_settings": {
"basis_gates": [
"ry",
"id",
"u1",
"x",
"rz",
"cx",
"p",
"s",
"u1",
"sxdg",
"u",
"cz",
"h",
"rx",
"tdg",
"rz",
"sdg",
"sxdg",
"r",
"sx",
"cx",
"h",
"z",
"rx",
"p",
"t",
"cy",
"cz",
"u2",
"y",
"r"
"sdg",
"id",
"cy",
"ry",
"t"
],
"is_symmetric_connectivity": true
},
Expand All @@ -38,7 +38,7 @@
"optimization_timeout_seconds": 90,
"output_format": ["qasm"],
"pretty_qasm": true,
"random_seed": 2019804740,
"random_seed": 3201343675,
"synthesize_all_separately": false,
"timeout_seconds": 300,
"transpilation_option": "none"
Expand Down
397 changes: 202 additions & 195 deletions algorithms/hhl/hhl/hhl.ipynb

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions algorithms/hhl/hhl/hhl_exact.qmod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
qfunc load_b_expanded___0(amplitudes: real[], output state: qbit[2]) {
prepare_amplitudes(amplitudes, 0.0, state);
qfunc load_b_expanded___0(amplitudes: real[], output memory: qbit[2]) {
prepare_amplitudes(amplitudes, 0.0, memory);
}

qfunc apply_to_all_expanded___0(target: qbit[4]) {
Expand All @@ -12,35 +12,35 @@ qfunc hamiltonian_evolution_with_power_0_lambda___0_0_expanded___0(pw: int, targ
power (pw) {
unitary([
[
((-0.09406240950199844) + 0.8149069223122054j),
(0.03521871946675125 - 0.029763534641642615j),
((-0.018800717000078303) - 0.16142879795007103j),
((-0.09406240950199857) + 0.8149069223122054j),
(0.03521871946675126 - 0.029763534641642615j),
((-0.018800717000078293) - 0.16142879795007106j),
(0.43769245930764733 + 0.32705554908759304j)
],
[
(0.03521871946675126 - 0.029763534641642626j),
((-0.15347248298890337) - 0.1727528247294824j),
(0.23117644455908545 + 0.8872069971297386j),
(0.2397182575488357 + 0.21548267921288922j)
(0.03521871946675127 - 0.029763534641642633j),
((-0.15347248298890326) - 0.17275282472948233j),
(0.23117644455908531 + 0.8872069971297389j),
(0.23971825754883572 + 0.21548267921288933j)
],
[
((-0.018800717000078272) - 0.16142879795007106j),
(0.23117644455908531 + 0.8872069971297386j),
((-0.12191317205164587) + 0.1320013812642838j),
(0.2958406910149558 + 0.11488938733473114j)
((-0.01880071700007826) - 0.16142879795007103j),
(0.23117644455908523 + 0.8872069971297386j),
((-0.1219131720516462) + 0.13200138126428373j),
(0.29584069101495575 + 0.11488938733473114j)
],
[
(0.43769245930764744 + 0.3270555490875932j),
(0.23971825754883574 + 0.21548267921288933j),
(0.29584069101495586 + 0.11488938733473113j),
((-0.6563827949579104) + 0.2569098899110467j)
(0.43769245930764744 + 0.32705554908759327j),
(0.2397182575488357 + 0.21548267921288933j),
(0.29584069101495586 + 0.1148893873347311j),
((-0.6563827949579104) + 0.25690988991104674j)
]
], target);
}
}

qfunc unitary_with_power_0_lambda___0_0_expanded___0(k: int, state_captured__hhl__1: qbit[2]) {
hamiltonian_evolution_with_power_0_lambda___0_0_expanded___0(k, state_captured__hhl__1);
qfunc unitary_with_power_0_lambda___0_0_expanded___0(k: int, memory_captured__hhl__1: qbit[2]) {
hamiltonian_evolution_with_power_0_lambda___0_0_expanded___0(k, memory_captured__hhl__1);
}

qfunc qft_no_swap_expanded___0(qbv: qbit[4]) {
Expand All @@ -59,11 +59,11 @@ qfunc qft_expanded___0(target: qbit[4]) {
qft_no_swap_expanded___0(target);
}

qfunc qpe_flexible_expanded___0(phase: qbit[4], state_captured__hhl__1: qbit[2]) {
qfunc qpe_flexible_expanded___0(phase: qbit[4], memory_captured__hhl__1: qbit[2]) {
apply_to_all_expanded___0(phase);
repeat (index: 4) {
control (phase[index]) {
unitary_with_power_0_lambda___0_0_expanded___0(2 ** index, state_captured__hhl__1);
unitary_with_power_0_lambda___0_0_expanded___0(2 ** index, memory_captured__hhl__1);
}
}
invert {
Expand Down Expand Up @@ -138,27 +138,27 @@ qfunc assign_amplitude_table_expanded___0(index: qbit[4], indicator: qbit) {
}
}

qfunc hhl_expanded___0(rhs_vector: real[], output state: qbit[2], output phase: qnum<4, False, 4>, output indicator: qbit) {
allocate(4, False, 4, phase);
qfunc hhl_expanded___0(rhs_vector: real[], output memory: qbit[2], output estimator: qnum<4, False, 4>, output indicator: qbit) {
allocate(4, False, 4, estimator);
load_b_expanded___0([
0.18257418583505536,
0.3651483716701107,
0.7302967433402214,
0.5477225575051661
], state);
], memory);
allocate(1, indicator);
within {
qpe_flexible_expanded___0(phase, state);
qpe_flexible_expanded___0(estimator, memory);
} apply {
assign_amplitude_table_expanded___0(phase, indicator);
assign_amplitude_table_expanded___0(estimator, indicator);
}
}

qfunc main(output res: qnum<2, False, 0>, output phase_var: qnum<4, False, 4>, output indicator: qbit) {
qfunc main(output res: qnum<2, False, 0>, output estimator_var: qnum<4, False, 4>, output indicator: qbit) {
hhl_expanded___0([
0.18257418583505536,
0.3651483716701107,
0.7302967433402214,
0.5477225575051661
], res, phase_var, indicator);
], res, estimator_var, indicator);
}
30 changes: 15 additions & 15 deletions algorithms/hhl/hhl/hhl_exact.synthesis_options.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
"custom_hardware_settings": {
"basis_gates": [
"cz",
"t",
"rx",
"rz",
"sxdg",
"cx",
"z",
"s",
"id",
"sdg",
"x",
"tdg",
"y",
"sx",
"cx",
"u",
"cy",
"id",
"rx",
"ry",
"r",
"p",
"u2",
"rz",
"y",
"ry",
"x",
"r",
"sx",
"u1",
"h",
"t",
"z",
"u"
"tdg",
"h"
],
"is_symmetric_connectivity": true
},
Expand All @@ -36,7 +36,7 @@
"optimization_level": 1,
"output_format": ["qasm"],
"pretty_qasm": true,
"random_seed": 514333184,
"random_seed": 979174742,
"synthesize_all_separately": false,
"timeout_seconds": 300,
"transpilation_option": "auto optimize"
Expand Down
26 changes: 13 additions & 13 deletions algorithms/hhl/hhl/hhl_trotter.qmod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
qfunc load_b_expanded___0(amplitudes: real[], output state: qbit[2]) {
prepare_amplitudes(amplitudes, 0.0, state);
qfunc load_b_expanded___0(amplitudes: real[], output memory: qbit[2]) {
prepare_amplitudes(amplitudes, 0.0, memory);
}

qfunc apply_to_all_expanded___0(target: qbit[4]) {
Expand Down Expand Up @@ -86,8 +86,8 @@ qfunc hamiltonian_evolution_with_power_0_lambda___0_0_expanded___0(pw: int, targ
}, (-6.2831853072) * pw, 1, 4 * ceiling(1.8 ** log(pw, 2)), target);
}

qfunc unitary_with_power_0_lambda___0_0_expanded___0(k: int, state_captured__hhl__1: qbit[2]) {
hamiltonian_evolution_with_power_0_lambda___0_0_expanded___0(k, state_captured__hhl__1);
qfunc unitary_with_power_0_lambda___0_0_expanded___0(k: int, memory_captured__hhl__1: qbit[2]) {
hamiltonian_evolution_with_power_0_lambda___0_0_expanded___0(k, memory_captured__hhl__1);
}

qfunc qft_no_swap_expanded___0(qbv: qbit[4]) {
Expand All @@ -106,11 +106,11 @@ qfunc qft_expanded___0(target: qbit[4]) {
qft_no_swap_expanded___0(target);
}

qfunc qpe_flexible_expanded___0(phase: qbit[4], state_captured__hhl__1: qbit[2]) {
qfunc qpe_flexible_expanded___0(phase: qbit[4], memory_captured__hhl__1: qbit[2]) {
apply_to_all_expanded___0(phase);
repeat (index: 4) {
control (phase[index]) {
unitary_with_power_0_lambda___0_0_expanded___0(2 ** index, state_captured__hhl__1);
unitary_with_power_0_lambda___0_0_expanded___0(2 ** index, memory_captured__hhl__1);
}
}
invert {
Expand Down Expand Up @@ -185,27 +185,27 @@ qfunc assign_amplitude_table_expanded___0(index: qbit[4], indicator: qbit) {
}
}

qfunc hhl_expanded___0(rhs_vector: real[], output state: qbit[2], output phase: qnum<4, False, 4>, output indicator: qbit) {
allocate(4, False, 4, phase);
qfunc hhl_expanded___0(rhs_vector: real[], output memory: qbit[2], output estimator: qnum<4, False, 4>, output indicator: qbit) {
allocate(4, False, 4, estimator);
load_b_expanded___0([
0.1825741858,
0.3651483717,
0.7302967433,
0.5477225575
], state);
], memory);
allocate(1, indicator);
within {
qpe_flexible_expanded___0(phase, state);
qpe_flexible_expanded___0(estimator, memory);
} apply {
assign_amplitude_table_expanded___0(phase, indicator);
assign_amplitude_table_expanded___0(estimator, indicator);
}
}

qfunc main(output res: qnum<2, False, 0>, output phase_var: qnum<4, False, 4>, output indicator: qbit) {
qfunc main(output res: qnum<2, False, 0>, output estimator_var: qnum<4, False, 4>, output indicator: qbit) {
hhl_expanded___0([
0.1825741858,
0.3651483717,
0.7302967433,
0.5477225575
], res, phase_var, indicator);
], res, estimator_var, indicator);
}
30 changes: 15 additions & 15 deletions algorithms/hhl/hhl/hhl_trotter.synthesis_options.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
"custom_hardware_settings": {
"basis_gates": [
"cz",
"t",
"rx",
"rz",
"sxdg",
"cx",
"z",
"s",
"id",
"sdg",
"x",
"tdg",
"y",
"sx",
"cx",
"u",
"cy",
"id",
"rx",
"ry",
"r",
"p",
"u2",
"rz",
"y",
"ry",
"x",
"r",
"sx",
"u1",
"h",
"t",
"z",
"u"
"tdg",
"h"
],
"is_symmetric_connectivity": true
},
Expand All @@ -36,7 +36,7 @@
"optimization_level": 1,
"output_format": ["qasm"],
"pretty_qasm": true,
"random_seed": 2764534899,
"random_seed": 351634037,
"synthesize_all_separately": false,
"timeout_seconds": 300,
"transpilation_option": "auto optimize"
Expand Down
Loading