diff --git a/examples/qec_decoder_toolkit/Quantinuum_hseries_qec_decoder_toolkit.ipynb b/examples/qec_decoder_toolkit/Quantinuum_hseries_qec_decoder_toolkit.ipynb index 99a70a1f..2d21b61a 100644 --- a/examples/qec_decoder_toolkit/Quantinuum_hseries_qec_decoder_toolkit.ipynb +++ b/examples/qec_decoder_toolkit/Quantinuum_hseries_qec_decoder_toolkit.ipynb @@ -533,10 +533,7 @@ "\n", "* `c`\n", "* `pfu`\n", - "* `pfu_old`\n", - "* `syn`\n", - "* `syn_old`\n", - "* `syn_new`" + "* `syn`" ] }, { @@ -559,17 +556,11 @@ "creg = BitRegister(\"c\", 3)\n", "circuit.add_c_register(creg)\n", "\n", - "pfu_old = BitRegister(\"pfu_old\", 3)\n", - "circuit.add_c_register(pfu_old)\n", + "pfu = BitRegister(\"pfu\", 3)\n", + "circuit.add_c_register(pfu)\n", "\n", "syn = BitRegister(\"syn\", 2)\n", - "circuit.add_c_register(syn)\n", - "\n", - "syn_old = BitRegister(\"syn_old\", 2)\n", - "circuit.add_c_register(syn_old)\n", - "\n", - "syn_new = BitRegister(\"syn_new\", 2)\n", - "circuit.add_c_register(syn_new);" + "circuit.add_c_register(syn);" ] }, { @@ -597,17 +588,14 @@ "circuit.CX(qreg[1], areg[0])\n", "circuit.CX(qreg[2], areg[0])\n", "circuit.Measure(areg[0], syn[1])\n", - "circuit.Reset(areg[0])\n", - "\n", - "circuit.add_classicalexpbox_register(RegXor(syn_old, syn), syn_new)\n", - "circuit.add_c_copyreg(syn, syn_old);" + "circuit.Reset(areg[0])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The `add_wasm_to_reg` method is used to apply the `decode3` function, defined in the Wasm module, to the bit registers, `syn` and `pfu`. The output of `decode3` is written to the bit register, `pfu_old`. `add_c_xor_to_registers` is used to set the value of `pfu_old` to the output of the expression, `pfu_old` ^ `pfu`. `add_c_setreg` is used to set the all the bits in the classical register, `pfu`, to `False`." + "The `add_wasm_to_reg` method is used to apply the `decode3` function, defined in the Wasm module, to the bit registers, `syn` and `pfu`. The output of `decode3` is written to the bit register, `pfu`. `add_c_xor_to_registers` is used to set the value of `pfu` to the output of the expression, `pfu` ^ `pfu`. `add_c_setreg` is used to set the all the bits in the classical register, `pfu`, to `False`." ] }, { @@ -616,9 +604,9 @@ "metadata": {}, "outputs": [], "source": [ - "circuit.add_wasm_to_reg(\"decode3\", wasm_file_handler, [syn_new, pfu_old], [pfu_old])\n", + "circuit.add_wasm_to_reg(\"decode3\", wasm_file_handler, [syn, pfu], [pfu])\n", "for i in range(3):\n", - " circuit.X(qreg[i], condition_bits=[pfu_old[i]], condition_value=1);" + " circuit.X(qreg[i], condition_bits=[pfu[i]], condition_value=1);" ] }, { @@ -644,12 +632,9 @@ "circuit.Measure(areg[0], syn[1])\n", "circuit.Reset(areg[0])\n", "\n", - "circuit.add_classicalexpbox_register(RegXor(syn_old, syn), syn_new)\n", - "circuit.add_c_copyreg(syn, syn_old)\n", - "\n", - "circuit.add_wasm_to_reg(\"decode3\", wasm_file_handler, [syn_new, pfu_old], [pfu_old])\n", + "circuit.add_wasm_to_reg(\"decode3\", wasm_file_handler, [syn, pfu], [pfu])\n", "for i in range(3):\n", - " circuit.X(qreg[i], condition_bits=[pfu_old[i]], condition_value=1)" + " circuit.X(qreg[i], condition_bits=[pfu[i]], condition_value=1)" ] }, { @@ -692,18 +677,9 @@ "metadata": {}, "outputs": [], "source": [ - "circuit.add_classicalexpbox_register(syn_old ^ syn, syn_new);" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "circuit.add_wasm_to_reg(\"decode3\", wasm_file_handler, [syn_new, pfu_old], [pfu_old])\n", + "circuit.add_wasm_to_reg(\"decode3\", wasm_file_handler, [syn, pfu], [pfu])\n", "for i in range(3):\n", - " circuit.X(qreg[i], condition_bits=[pfu_old[i]], condition_value=1);" + " circuit.X(qreg[i], condition_bits=[pfu[i]], condition_value=1);" ] }, { @@ -712,7 +688,7 @@ "metadata": {}, "outputs": [], "source": [ - "circuit.add_classicalexpbox_register(pfu_old ^ creg, pfu_old);" + "circuit.add_classicalexpbox_register(pfu ^ creg, pfu);" ] }, { @@ -871,7 +847,7 @@ "metadata": {}, "outputs": [], "source": [ - "logical_error(result, n_shots, creg, pfu_old).head()" + "logical_error(result, n_shots, creg, pfu).head()" ] }, { diff --git a/examples/qec_decoder_toolkit/repetition_code/c/src/lib.c b/examples/qec_decoder_toolkit/repetition_code/c/src/lib.c index 54e39354..f3d6886f 100644 --- a/examples/qec_decoder_toolkit/repetition_code/c/src/lib.c +++ b/examples/qec_decoder_toolkit/repetition_code/c/src/lib.c @@ -2,16 +2,20 @@ void init() { return; } -int decode3(int syn, int pfu_old) { - int pfu; - if (syn == 1) { - pfu = 1; - } else if (syn == 3) { - pfu = 2; - } else if (syn == 2) { - pfu = 4; +int syn_old; + +int decode3(int syn, int pfu) { + int syn_new = syn ^ syn_old; + int val; + if (syn_new == 1) { + val = 1; + } else if (syn_new == 3) { + val = 2; + } else if (syn_new == 2) { + val = 4; } else { return 0; } - return pfu_old ^ pfu; + syn_old = syn; + return val ^ pfu; } diff --git a/examples/qec_decoder_toolkit/repetition_code/rust/src/lib.rs b/examples/qec_decoder_toolkit/repetition_code/rust/src/lib.rs index 94d536d1..0473cbb7 100644 --- a/examples/qec_decoder_toolkit/repetition_code/rust/src/lib.rs +++ b/examples/qec_decoder_toolkit/repetition_code/rust/src/lib.rs @@ -1,5 +1,7 @@ use std::collections::HashMap; +static mut SYN_OLD: i32 = 0; + #[no_mangle] fn init(){ // This function can have nothing it in, or load some initial function. @@ -11,19 +13,28 @@ fn init(){ fn decode3(syn: i32, pfu: i32) -> i32 { //takes in a string and returns and a string let mut decoder:HashMap = HashMap::new(); + // let syn_new: i32 = SYN_OLD ^ syn; decoder.insert(1, 1); //001 = 1, if syn = 1 then error on qubit 0 decoder.insert(3, 2); //010 = 2, if sny = 3 then error on qubit 1 decoder.insert(2, 4); //100 = 4, if syn = 2 then error on qubit 2 + unsafe { + SYN_OLD = syn; + println!("SYN_OLD: {}, syn: {}", SYN_OLD, syn) + } + if syn == 0 { return pfu; } else { - let pfu_old = pfu ^ decoder[&syn]; - return pfu_old; + return pfu ^ decoder[&syn]; } } +fn main() -> i32 { + let pfu: i32 = decode3(1, 2); + return 0; +} // #[test] // fn test_decode3() {