From 034bb0756d6d35f6c68f2e764dd8ea6768cf4c64 Mon Sep 17 00:00:00 2001 From: Or Samimi Golan Date: Sun, 24 Nov 2024 12:21:23 +0200 Subject: [PATCH] added metadata files and qmod for dqi --- ..._max_xorsat.ipynb => dqi_max_xorsat.ipynb} | 13 +- algorithms/dqi/dqi_max_xorsat.json | 6 + algorithms/dqi/dqi_max_xorsat.qmod | 588 ++++++++++++++++++ .../dqi/dqi_max_xorsat.synthesis_options.json | 51 ++ tests/resources/timeouts.yaml | 2 + 5 files changed, 650 insertions(+), 10 deletions(-) rename algorithms/dqi/{DQI_max_xorsat.ipynb => dqi_max_xorsat.ipynb} (99%) create mode 100644 algorithms/dqi/dqi_max_xorsat.json create mode 100644 algorithms/dqi/dqi_max_xorsat.qmod create mode 100644 algorithms/dqi/dqi_max_xorsat.synthesis_options.json diff --git a/algorithms/dqi/DQI_max_xorsat.ipynb b/algorithms/dqi/dqi_max_xorsat.ipynb similarity index 99% rename from algorithms/dqi/DQI_max_xorsat.ipynb rename to algorithms/dqi/dqi_max_xorsat.ipynb index 24f0fa3b1..eba36c8f1 100644 --- a/algorithms/dqi/DQI_max_xorsat.ipynb +++ b/algorithms/dqi/dqi_max_xorsat.ipynb @@ -797,20 +797,12 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "4628f4a1-7ead-4c75-b6df-68da252a2a0d", "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Opening: https://nightly.platform.classiq.io/circuit/d8906bbd-b43a-4faf-bae7-d280fcdea180?version=0.59.0.dev6\n" - ] - } - ], + "outputs": [], "source": [ "from classiq.execution import *\n", "\n", @@ -833,6 +825,7 @@ " execution_preferences=ExecutionPreferences(num_shots=10000),\n", ")\n", "\n", + "write_qmod(qmod, \"dqi_max_xorsat\")\n", "qprog = synthesize(qmod)\n", "show(qprog, display_url=False)" ] diff --git a/algorithms/dqi/dqi_max_xorsat.json b/algorithms/dqi/dqi_max_xorsat.json new file mode 100644 index 000000000..bc5148440 --- /dev/null +++ b/algorithms/dqi/dqi_max_xorsat.json @@ -0,0 +1,6 @@ +{ + "friendly_name": "Decoded Quantum Interferometry (DQI) for MaxCut", + "description": "Solving the MaxCut Problem using the DQI Algorithm in the setting of max-XORSAT", + "qmod_type": ["algorithms"], + "level": ["advanced"] +} diff --git a/algorithms/dqi/dqi_max_xorsat.qmod b/algorithms/dqi/dqi_max_xorsat.qmod new file mode 100644 index 000000000..5bb9acb82 --- /dev/null +++ b/algorithms/dqi/dqi_max_xorsat.qmod @@ -0,0 +1,588 @@ +qfunc inplace_binary_to_one_hot_expanded___0(one_hot: qbit[4]) { + temp_0: qbit; + temp_1: qbit; + temp_2: qbit; + temp_3: qbit; + one_hot -> {temp_0, temp_1, temp_2, temp_3}; + {temp_2, temp_0, temp_3, temp_1} -> one_hot; + X(one_hot[0]); + CX(one_hot[1], one_hot[0]); + one_hot___0_0: qbit; + one_hot___1_0: qbit; + one_hot___2_0: qbit; + one_hot___3_0: qbit; + within { + one_hot -> {one_hot___0_0, one_hot___1_0, one_hot___2_0, one_hot___3_0}; + } apply { + control (one_hot___3_0) { + SWAP(one_hot___0_0, one_hot___2_0); + } + } + CX(one_hot[2], one_hot[3]); + CX(one_hot[3], one_hot[1]); +} + +qfunc binary_to_one_hot_expanded___0(input binary: qnum<2, False, 0>, output one_hot: qbit[4]) { + extension: qbit[2]; + allocate(2, extension); + {binary, extension} -> one_hot; + inplace_binary_to_one_hot_expanded___0(one_hot); +} + +qfunc iteration_expanded___0(qvar: qbit[4]) { + CX(qvar[3], qvar[2]); +} + +qfunc iteration_expanded___1(qvar: qbit[4]) { + CX(qvar[2], qvar[1]); +} + +qfunc iteration_expanded___2(qvar: qbit[4]) { + CX(qvar[1], qvar[0]); +} + +qfunc inplace_one_hot_to_unary_expanded___0(qvar: qbit[4]) { + iteration_expanded___0(qvar); + iteration_expanded___1(qvar); + iteration_expanded___2(qvar); + X(qvar[0]); +} + +qfunc one_hot_to_unary_expanded___0(input one_hot: qbit[4], output unary: qbit[3]) { + inplace_one_hot_to_unary_expanded___0(one_hot); + lsb: qbit; + one_hot -> {lsb, unary}; + free(lsb); +} + +qfunc binary_to_unary_expanded___0(input binary: qnum<2, False, 0>, output unary: qbit[3]) { + one_hot: qbit[4]; + binary_to_one_hot_expanded___0(binary, one_hot); + one_hot_to_unary_expanded___0(one_hot, unary); +} + +qfunc pad_zeros_expanded___0(input qvar: qbit[3], output qvar_padded: qbit[6]) { + extension: qbit[3]; + allocate(3, extension); + {qvar, extension} -> qvar_padded; +} + +qfunc _dicke_split_cycle_shift_expanded___0(qvar: qbit[6]) { + within { + CX(qvar[1], qvar[0]); + } apply { + qvar___0_0: qbit; + qvar___1_0: qbit; + qvar___2_0: qbit; + qvar___3_0: qbit; + qvar___4_0: qbit; + qvar___5_0: qbit; + within { + qvar -> {qvar___0_0, qvar___1_0, qvar___2_0, qvar___3_0, qvar___4_0, qvar___5_0}; + } apply { + control (qvar___0_0) { + RY(2.3005, qvar___1_0); + } + } + } + within { + CX(qvar[2], qvar[0]); + } apply { + qvar___0_1: qbit; + qvar___1_1: qbit; + qvar___2_1: qbit; + qvar___3_1: qbit; + qvar___4_1: qbit; + qvar___5_1: qbit; + within { + qvar -> {qvar___0_1, qvar___1_1, qvar___2_1, qvar___3_1, qvar___4_1, qvar___5_1}; + } apply { + result__temp___0: qbit; + within { + result__temp___0 = qvar___0_1 & qvar___1_1; + } apply { + control (result__temp___0) { + RY(1.9106, qvar___2_1); + } + } + } + } +} + +qfunc _dicke_split_cycle_shift_expanded___1(qvar: qbit[5]) { + within { + CX(qvar[1], qvar[0]); + } apply { + qvar___0_2: qbit; + qvar___1_2: qbit; + qvar___2_2: qbit; + qvar___3_2: qbit; + qvar___4_2: qbit; + within { + qvar -> {qvar___0_2, qvar___1_2, qvar___2_2, qvar___3_2, qvar___4_2}; + } apply { + control (qvar___0_2) { + RY(2.2143, qvar___1_2); + } + } + } + within { + CX(qvar[2], qvar[0]); + } apply { + qvar___0_3: qbit; + qvar___1_3: qbit; + qvar___2_3: qbit; + qvar___3_3: qbit; + qvar___4_3: qbit; + within { + qvar -> {qvar___0_3, qvar___1_3, qvar___2_3, qvar___3_3, qvar___4_3}; + } apply { + result__temp___1: qbit; + within { + result__temp___1 = qvar___0_3 & qvar___1_3; + } apply { + control (result__temp___1) { + RY(1.7722, qvar___2_3); + } + } + } + } +} + +qfunc _dicke_split_cycle_shift_expanded___2(qvar: qbit[4]) { + within { + CX(qvar[1], qvar[0]); + } apply { + qvar___0_4: qbit; + qvar___1_4: qbit; + qvar___2_4: qbit; + qvar___3_4: qbit; + within { + qvar -> {qvar___0_4, qvar___1_4, qvar___2_4, qvar___3_4}; + } apply { + control (qvar___0_4) { + RY(2.0944, qvar___1_4); + } + } + } + within { + CX(qvar[2], qvar[0]); + } apply { + qvar___0_5: qbit; + qvar___1_5: qbit; + qvar___2_5: qbit; + qvar___3_5: qbit; + within { + qvar -> {qvar___0_5, qvar___1_5, qvar___2_5, qvar___3_5}; + } apply { + result__temp___2: qbit; + within { + result__temp___2 = qvar___0_5 & qvar___1_5; + } apply { + control (result__temp___2) { + RY(1.5708, qvar___2_5); + } + } + } + } +} + +qfunc _dicke_split_cycle_shift_expanded___3(qvar: qbit[3]) { + within { + CX(qvar[1], qvar[0]); + } apply { + qvar___0_6: qbit; + qvar___1_6: qbit; + qvar___2_6: qbit; + within { + qvar -> {qvar___0_6, qvar___1_6, qvar___2_6}; + } apply { + control (qvar___0_6) { + RY(1.9106, qvar___1_6); + } + } + } + within { + CX(qvar[2], qvar[0]); + } apply { + qvar___0_7: qbit; + qvar___1_7: qbit; + qvar___2_7: qbit; + within { + qvar -> {qvar___0_7, qvar___1_7, qvar___2_7}; + } apply { + result__temp___3: qbit; + within { + result__temp___3 = qvar___0_7 & qvar___1_7; + } apply { + control (result__temp___3) { + RY(1.231, qvar___2_7); + } + } + } + } +} + +qfunc _dicke_split_cycle_shift_expanded___4(qvar: qbit[2]) { + within { + CX(qvar[1], qvar[0]); + } apply { + qvar___0_8: qbit; + qvar___1_8: qbit; + within { + qvar -> {qvar___0_8, qvar___1_8}; + } apply { + control (qvar___0_8) { + RY(1.5708, qvar___1_8); + } + } + } +} + +qfunc prepare_dick_state_unary_input_expanded___0(qvar: qbit[1]) { +} + +qfunc prepare_dick_state_unary_input_expanded___1(qvar: qbit[2]) { + _dicke_split_cycle_shift_expanded___4(qvar); + prepare_dick_state_unary_input_expanded___0(qvar[1:2]); +} + +qfunc prepare_dick_state_unary_input_expanded___2(qvar: qbit[3]) { + _dicke_split_cycle_shift_expanded___3(qvar); + prepare_dick_state_unary_input_expanded___1(qvar[1:3]); +} + +qfunc prepare_dick_state_unary_input_expanded___3(qvar: qbit[4]) { + _dicke_split_cycle_shift_expanded___2(qvar); + prepare_dick_state_unary_input_expanded___2(qvar[1:4]); +} + +qfunc prepare_dick_state_unary_input_expanded___4(qvar: qbit[5]) { + _dicke_split_cycle_shift_expanded___1(qvar); + prepare_dick_state_unary_input_expanded___3(qvar[1:5]); +} + +qfunc prepare_dick_state_unary_input_expanded___5(qvar: qbit[6]) { + _dicke_split_cycle_shift_expanded___0(qvar); + prepare_dick_state_unary_input_expanded___4(qvar[1:6]); +} + +qfunc iteration_expanded___3(y: qbit[6]) { + Z(y[0]); +} + +qfunc iteration_expanded___4(y: qbit[6]) { + Z(y[1]); +} + +qfunc iteration_expanded___5(y: qbit[6]) { + Z(y[2]); +} + +qfunc iteration_expanded___6(y: qbit[6]) { + Z(y[3]); +} + +qfunc iteration_expanded___7(y: qbit[6]) { + Z(y[4]); +} + +qfunc iteration_expanded___8(y: qbit[6]) { + Z(y[5]); +} + +qfunc vector_product_phase_expanded___0(y: qbit[6]) { + iteration_expanded___3(y); + iteration_expanded___4(y); + iteration_expanded___5(y); + iteration_expanded___6(y); + iteration_expanded___7(y); + iteration_expanded___8(y); +} + +qfunc matrix_vector_product_expanded___0(y: qbit[6], output out: qbit[6]) { + allocate(6, out); + y___0_0: qbit; + y___1_0: qbit; + y___2_0: qbit; + y___3_0: qbit; + y___4_0: qbit; + y___5_0: qbit; + within { + y -> {y___0_0, y___1_0, y___2_0, y___3_0, y___4_0, y___5_0}; + } apply { + out[0] ^= ((((y___0_0 ^ y___1_0) ^ 0) ^ 0) ^ 0) ^ 0; + } + y___0_1: qbit; + y___1_1: qbit; + y___2_1: qbit; + y___3_1: qbit; + y___4_1: qbit; + y___5_1: qbit; + within { + y -> {y___0_1, y___1_1, y___2_1, y___3_1, y___4_1, y___5_1}; + } apply { + out[1] ^= ((((y___0_1 ^ 0) ^ y___2_1) ^ 0) ^ 0) ^ 0; + } + y___0_2: qbit; + y___1_2: qbit; + y___2_2: qbit; + y___3_2: qbit; + y___4_2: qbit; + y___5_2: qbit; + within { + y -> {y___0_2, y___1_2, y___2_2, y___3_2, y___4_2, y___5_2}; + } apply { + out[2] ^= (((0 ^ y___2_2) ^ y___3_2) ^ 0) ^ 0; + } + y___0_3: qbit; + y___1_3: qbit; + y___2_3: qbit; + y___3_3: qbit; + y___4_3: qbit; + y___5_3: qbit; + within { + y -> {y___0_3, y___1_3, y___2_3, y___3_3, y___4_3, y___5_3}; + } apply { + out[3] ^= ((0 ^ y___3_3) ^ y___4_3) ^ 0; + } + y___0_4: qbit; + y___1_4: qbit; + y___2_4: qbit; + y___3_4: qbit; + y___4_4: qbit; + y___5_4: qbit; + within { + y -> {y___0_4, y___1_4, y___2_4, y___3_4, y___4_4, y___5_4}; + } apply { + out[4] ^= ((((0 ^ y___1_4) ^ 0) ^ 0) ^ 0) ^ y___5_4; + } + y___0_5: qbit; + y___1_5: qbit; + y___2_5: qbit; + y___3_5: qbit; + y___4_5: qbit; + y___5_5: qbit; + within { + y -> {y___0_5, y___1_5, y___2_5, y___3_5, y___4_5, y___5_5}; + } apply { + out[5] ^= (0 ^ y___4_5) ^ y___5_5; + } +} + +qfunc syndrome_decode_lookuptable_expanded___0(syndrome: qnum<6, False, 0>, error: qnum<6, False, 0>) { + syndrome___array_cast_0: qbit[6]; + within { + real_xor_constant(63, syndrome); + syndrome -> syndrome___array_cast_0; + } apply { + control (syndrome___array_cast_0) { + } + } + syndrome___array_cast_1: qbit[6]; + within { + real_xor_constant(60, syndrome); + syndrome -> syndrome___array_cast_1; + } apply { + control (syndrome___array_cast_1) { + real_xor_constant(1, error); + } + } + syndrome___array_cast_2: qbit[6]; + within { + real_xor_constant(46, syndrome); + syndrome -> syndrome___array_cast_2; + } apply { + control (syndrome___array_cast_2) { + real_xor_constant(2, error); + } + } + syndrome___array_cast_3: qbit[6]; + within { + real_xor_constant(57, syndrome); + syndrome -> syndrome___array_cast_3; + } apply { + control (syndrome___array_cast_3) { + real_xor_constant(4, error); + } + } + syndrome___array_cast_4: qbit[6]; + within { + real_xor_constant(51, syndrome); + syndrome -> syndrome___array_cast_4; + } apply { + control (syndrome___array_cast_4) { + real_xor_constant(8, error); + } + } + syndrome___array_cast_5: qbit[6]; + within { + real_xor_constant(23, syndrome); + syndrome -> syndrome___array_cast_5; + } apply { + control (syndrome___array_cast_5) { + real_xor_constant(16, error); + } + } + syndrome___array_cast_6: qbit[6]; + within { + real_xor_constant(15, syndrome); + syndrome -> syndrome___array_cast_6; + } apply { + control (syndrome___array_cast_6) { + real_xor_constant(32, error); + } + } + syndrome___array_cast_7: qbit[6]; + within { + real_xor_constant(45, syndrome); + syndrome -> syndrome___array_cast_7; + } apply { + control (syndrome___array_cast_7) { + real_xor_constant(3, error); + } + } + syndrome___array_cast_8: qbit[6]; + within { + real_xor_constant(58, syndrome); + syndrome -> syndrome___array_cast_8; + } apply { + control (syndrome___array_cast_8) { + real_xor_constant(5, error); + } + } + syndrome___array_cast_9: qbit[6]; + within { + real_xor_constant(48, syndrome); + syndrome -> syndrome___array_cast_9; + } apply { + control (syndrome___array_cast_9) { + real_xor_constant(9, error); + } + } + syndrome___array_cast_10: qbit[6]; + within { + real_xor_constant(20, syndrome); + syndrome -> syndrome___array_cast_10; + } apply { + control (syndrome___array_cast_10) { + real_xor_constant(17, error); + } + } + syndrome___array_cast_11: qbit[6]; + within { + real_xor_constant(12, syndrome); + syndrome -> syndrome___array_cast_11; + } apply { + control (syndrome___array_cast_11) { + real_xor_constant(33, error); + } + } + syndrome___array_cast_12: qbit[6]; + within { + real_xor_constant(40, syndrome); + syndrome -> syndrome___array_cast_12; + } apply { + control (syndrome___array_cast_12) { + real_xor_constant(6, error); + } + } + syndrome___array_cast_13: qbit[6]; + within { + real_xor_constant(34, syndrome); + syndrome -> syndrome___array_cast_13; + } apply { + control (syndrome___array_cast_13) { + real_xor_constant(10, error); + } + } + syndrome___array_cast_14: qbit[6]; + within { + real_xor_constant(6, syndrome); + syndrome -> syndrome___array_cast_14; + } apply { + control (syndrome___array_cast_14) { + real_xor_constant(18, error); + } + } + syndrome___array_cast_15: qbit[6]; + within { + real_xor_constant(30, syndrome); + syndrome -> syndrome___array_cast_15; + } apply { + control (syndrome___array_cast_15) { + real_xor_constant(34, error); + } + } + syndrome___array_cast_16: qbit[6]; + within { + real_xor_constant(53, syndrome); + syndrome -> syndrome___array_cast_16; + } apply { + control (syndrome___array_cast_16) { + real_xor_constant(12, error); + } + } + syndrome___array_cast_17: qbit[6]; + within { + real_xor_constant(17, syndrome); + syndrome -> syndrome___array_cast_17; + } apply { + control (syndrome___array_cast_17) { + real_xor_constant(20, error); + } + } + syndrome___array_cast_18: qbit[6]; + within { + real_xor_constant(9, syndrome); + syndrome -> syndrome___array_cast_18; + } apply { + control (syndrome___array_cast_18) { + real_xor_constant(36, error); + } + } + syndrome___array_cast_19: qbit[6]; + within { + real_xor_constant(27, syndrome); + syndrome -> syndrome___array_cast_19; + } apply { + control (syndrome___array_cast_19) { + real_xor_constant(24, error); + } + } + syndrome___array_cast_20: qbit[6]; + within { + real_xor_constant(3, syndrome); + syndrome -> syndrome___array_cast_20; + } apply { + control (syndrome___array_cast_20) { + real_xor_constant(40, error); + } + } + syndrome___array_cast_21: qbit[6]; + within { + real_xor_constant(39, syndrome); + syndrome -> syndrome___array_cast_21; + } apply { + control (syndrome___array_cast_21) { + real_xor_constant(48, error); + } + } +} + +qfunc dqi_max_xor_sat_expanded___0(output y: qbit[6], output solution: qbit[6]) { + k_num_errors: qnum<2, False, 0>; + prepare_amplitudes([0.0, 0.7071, 0.7071, 0.0], 0, k_num_errors); + k_unary: qbit[3]; + binary_to_unary_expanded___0(k_num_errors, k_unary); + pad_zeros_expanded___0(k_unary, y); + prepare_dick_state_unary_input_expanded___5(y); + vector_product_phase_expanded___0(y); + matrix_vector_product_expanded___0(y, solution); + syndrome_decode_lookuptable_expanded___0(solution, y); + hadamard_transform(solution); +} + +qfunc main(output y: qbit[6], output solution: qbit[6]) { + dqi_max_xor_sat_expanded___0(y, solution); +} diff --git a/algorithms/dqi/dqi_max_xorsat.synthesis_options.json b/algorithms/dqi/dqi_max_xorsat.synthesis_options.json new file mode 100644 index 000000000..c195e7a57 --- /dev/null +++ b/algorithms/dqi/dqi_max_xorsat.synthesis_options.json @@ -0,0 +1,51 @@ +{ + "constraints": { + "max_width": null, + "max_depth": null, + "max_gate_count": {}, + "optimization_parameter": "width" + }, + "preferences": { + "machine_precision": 8, + "backend_service_provider": null, + "backend_name": null, + "custom_hardware_settings": { + "basis_gates": [ + "sxdg", + "tdg", + "t", + "u", + "y", + "cy", + "sx", + "p", + "u1", + "r", + "ry", + "id", + "z", + "s", + "h", + "cx", + "sdg", + "cz", + "rz", + "x", + "rx", + "u2" + ], + "connectivity_map": null, + "is_symmetric_connectivity": true + }, + "debug_mode": true, + "synthesize_all_separately": false, + "output_format": ["qasm"], + "pretty_qasm": true, + "qasm3": null, + "transpilation_option": "auto optimize", + "solovay_kitaev_max_iterations": null, + "timeout_seconds": 300, + "optimization_timeout_seconds": null, + "random_seed": 1746217737 + } +} diff --git a/tests/resources/timeouts.yaml b/tests/resources/timeouts.yaml index 63efd2202..184887f75 100644 --- a/tests/resources/timeouts.yaml +++ b/tests/resources/timeouts.yaml @@ -1,3 +1,5 @@ +algorithms/dqi/dqi_max_xorsat.ipynb: 200 +algorithms/dqi/dqi_max_xorsat.qmod: 200 algorithms/algebraic/discrete_log/discrete_log.ipynb: 600 algorithms/algebraic/discrete_log/discrete_log.qmod: 300 algorithms/algebraic/discrete_log/discrete_log_large.qmod: 600