| 37 | // ---------------------------------------------------------------------------------------- |
| 38 | |
| 39 | void shor_encode ( |
| 40 | quantum_register& reg |
| 41 | ) |
| 42 | /*! |
| 43 | requires |
| 44 | - reg.num_bits() == 1 |
| 45 | ensures |
| 46 | - #reg.num_bits() == 9 |
| 47 | - #reg == the Shor error coding of the input register |
| 48 | !*/ |
| 49 | { |
| 50 | DLIB_CASSERT(reg.num_bits() == 1,""); |
| 51 | |
| 52 | quantum_register zeros; |
| 53 | zeros.set_num_bits(8); |
| 54 | reg.append(zeros); |
| 55 | |
| 56 | using namespace dlib::quantum_gates; |
| 57 | const gate<1> h = hadamard(); |
| 58 | const gate<1> i = noop(); |
| 59 | |
| 60 | // Note that the expression (h,i) represents the tensor product of the 1 qubit |
| 61 | // h gate with the 1 qubit i gate and larger versions of this expression |
| 62 | // represent even bigger tensor products. So as you see below, we make gates |
| 63 | // big enough to apply to our quantum register by listing out all the gates we |
| 64 | // want to go into the tensor product and then we just apply the resulting gate |
| 65 | // to the quantum register. |
| 66 | |
| 67 | // Now apply the gates that constitute Shor's encoding to the input register. |
| 68 | (cnot<3,0>(),i,i,i,i,i).apply_gate_to(reg); |
| 69 | (cnot<6,0>(),i,i).apply_gate_to(reg); |
| 70 | (h,i,i,h,i,i,h,i,i).apply_gate_to(reg); |
| 71 | (cnot<1,0>(),i,cnot<1,0>(),i,cnot<1,0>(),i).apply_gate_to(reg); |
| 72 | (cnot<2,0>(),cnot<2,0>(),cnot<2,0>()).apply_gate_to(reg); |
| 73 | } |
| 74 | |
| 75 | // ---------------------------------------------------------------------------------------- |
| 76 |
no test coverage detected