Skip to content

Commit 55588cb

Browse files
revised quantum counting qmods
1 parent 12c391d commit 55588cb

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

algorithms/amplitude_amplification_and_estimation/quantum_counting/quantum_counting_iqae.qmod

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@
77
// this qubit implements the marking oracle used inside amplitude amplification iterations.
88

99

10-
// Defining the QStruct, containing the quantum variables a and b
10+
// Defining the qstruct, containing the quantum variables a and b, each with two qubits
1111
qstruct OracleVars {
1212
a: qnum<2>;
1313
b: qnum<2>;
1414
}
1515

1616

17-
// Configuration constants
18-
A_BITS: int = 2;
19-
B_BITS: int = 2;
2017

21-
PROBLEM_QUBITS: int = A_BITS + B_BITS; // 4 qubits: a[2] || b[2]
22-
THRESHOLD: int = 2; // predicate: (a + b) <= THRESHOLD
18+
PROBLEM_QUBITS: int = 4; // 4 qubits
19+
THRESHOLD: int = 2; // predicate: (a + b) <= THRESHOLD
2320

2421

2522

algorithms/amplitude_amplification_and_estimation/quantum_counting/quantum_counting_qpe.qmod

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
// the solution ratio; QPE extracts an estimate of that phase.
1212

1313

14-
// Problem sizes (in qubits)
15-
A_BITS: int = 2;
16-
B_BITS: int = 2;
14+
1715

1816
// Mark states for which (a + b) <= THRESHOLD
1917
THRESHOLD: int = 2;
@@ -22,13 +20,13 @@ THRESHOLD: int = 2;
2220
// Larger values provide finer phase resolution.
2321
PHASE_QUBITS: int = 5;
2422

25-
// Defining the QStruct, containing the quantum variables a and b
23+
// Defining the qstruct, containing the quantum variables a and b
2624
qstruct OracleVars {
2725
a: qnum<2>;
2826
b: qnum<2>;
2927
}
3028

31-
// Predicate: flips `res` iff the input (a, b) is a "good" solution.
29+
// Predicate: flips `res` iff the input (a, b) is a marked solution.
3230
qperm arith_equation(const state: OracleVars, res: qbit) {
3331
res ^= (state.a + state.b) <= 2;
3432
}
@@ -43,7 +41,7 @@ qfunc arith_oracle(state: OracleVars) {
4341
qfunc main(output phase_var: qnum<PHASE_QUBITS, UNSIGNED, PHASE_QUBITS>) {
4442
state_var: OracleVars;
4543

46-
allocate(state_var); // Initiates the ancilla QStruct
44+
allocate(state_var); // Initiates the ancilla qstruct
4745
allocate(phase_var); // Initiates the phase quantum variable
4846

4947
// Prepare a uniform superposition over all (a, b) inputs.

0 commit comments

Comments
 (0)