MCPcopy Create free account
hub / github.com/davisking/dlib / shor_encode

Function shor_encode

examples/quantum_computing_ex.cpp:39–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37// ----------------------------------------------------------------------------------------
38
39void 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

Callers 1

mainFunction · 0.85

Calls 6

hadamardFunction · 0.85
noopFunction · 0.85
num_bitsMethod · 0.80
set_num_bitsMethod · 0.80
apply_gate_toMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected