Skip to content

Commit

Permalink
Shor in library corrected - post-processing
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavyoran committed Jan 12, 2025
1 parent 655507f commit 852a875
Show file tree
Hide file tree
Showing 5 changed files with 535 additions and 228 deletions.
43 changes: 23 additions & 20 deletions algorithms/algebraic/shor/doubly_controlled_modular_adder.qmod
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,44 @@ qfunc check_msb(ref: int, x: qbit[], aux: qbit) {
}
}

qfunc ccmod_add(N: int, a: int, phi_b: qbit[], c1: qbit, c2: qbit, aux: qbit) {
qfunc ccmod_add(N: int, a: int, phi_b: qbit[], c1: qbit, c2: qbit) {
ctrl: qbit[];
{c1, c2} -> ctrl;
control (ctrl) {
phase_lad(a, phi_b);
}
invert {
phase_lad(N, phi_b);
}
check_msb(1, phi_b, aux);
control (aux) {
phase_lad(N, phi_b);
}
aux: qbit;
within {
allocate(1, aux);
{c1, c2} -> ctrl;
} apply {
control (ctrl) {
phase_lad(a, phi_b);
}
invert {
control (ctrl) {
phase_lad(a, phi_b);
phase_lad(N, phi_b);
}
check_msb(1, phi_b, aux);
control (aux) {
phase_lad(N, phi_b);
}
within {
invert {
control (ctrl) {
phase_lad(a, phi_b);
}
}
} apply {
check_msb(0, phi_b, aux);
}
} apply {
check_msb(0, phi_b, aux);
}
ctrl -> {c1, c2};
}

qfunc main(output b: qnum, output ctrl: qbit[2], output aux: qbit) {
qfunc main(output b: qnum, output ctrl: qbit[2]) {
allocate(5, b);
allocate(2, ctrl);
allocate(1, aux);
b ^= 8;
X(ctrl[0]);
X(ctrl[1]);
within {
qft(b);
} apply {
ccmod_add(15, 9, b, ctrl[0], ctrl[1], aux);
ccmod_add(15, 9, b, ctrl[0], ctrl[1]);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
{}
{
"constraints": {
"max_gate_count": {},
"optimization_parameter": "no_opt"
},
"preferences": {
"machine_precision": 8,
"custom_hardware_settings": {
"basis_gates": [
"u1",
"h",
"sxdg",
"z",
"y",
"u2",
"r",
"p",
"sx",
"s",
"t",
"cy",
"tdg",
"x",
"rx",
"rz",
"cx",
"cz",
"ry",
"sdg",
"id",
"u"
],
"is_symmetric_connectivity": true
},
"debug_mode": true,
"synthesize_all_separately": false,
"optimization_level": 3,
"output_format": ["qasm"],
"pretty_qasm": true,
"transpilation_option": "auto optimize",
"timeout_seconds": 300,
"random_seed": 3976221924
}
}
Loading

0 comments on commit 852a875

Please sign in to comment.