Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions algorithms/bernstein_vazirani/bernstein_vazirani.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@
"@qfunc\n",
"def bv_function(a: CInt, x: QArray):\n",
" aux = QBit()\n",
" allocate(aux)\n",
" within_apply(\n",
" lambda: hadamard_transform(x),\n",
" lambda: within_apply(\n",
" lambda: (allocate(aux), X(aux), H(aux)), lambda: bv_predicate(a, x, aux)\n",
" ),\n",
" )"
" lambda: within_apply(lambda: (X(aux), H(aux)), lambda: bv_predicate(a, x, aux)),\n",
" )\n",
" free(aux)"
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion algorithms/bernstein_vazirani/bernstein_vazirani.qmod
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ qperm bv_predicate(a: int, const x: qbit[], res: qbit) {

qfunc bv_function(a: int, x: qbit[]) {
aux: qbit;
allocate(aux);
within {
hadamard_transform(x);
} apply {
within {
allocate(aux);
X(aux);
H(aux);
} apply {
bv_predicate(a, x, aux);
}
}
free(aux);
}

qfunc main(output x: qnum<5>) {
Expand Down
19 changes: 10 additions & 9 deletions algorithms/simon/simon.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"source": [
"### Quantum Part\n",
"\n",
"The quantum part of the algorithm is rather simple, calling the quantum implementation of $f(x)$, between two calls of the hadamard transform. The call of $f$ is done out-of-place, onto a quantum variable $y$, whereas only the final state of $x$ is relevant to the classical postprocess to follow. "
"The quantum part of the algorithm is rather simple, calling the quantum implementation of $f(x)$, between two calls of the hadamard transform. The call of $f$ is done out-of-place, onto a quantum variable $res$, whereas only the final state of $x$ is relevant to the classical postprocess to follow. "
]
},
{
Expand All @@ -86,8 +86,7 @@
"\n",
"\n",
"@qfunc\n",
"def simon_qfunc(f_qfunc: QCallable[QNum, Output[QNum]], x: QNum):\n",
" res = QNum()\n",
"def simon_qfunc(f_qfunc: QCallable[QNum, Output[QNum]], x: QNum, res: Output[QNum]):\n",
" within_apply(lambda: hadamard_transform(x), lambda: f_qfunc(x, res))"
]
},
Expand Down Expand Up @@ -376,9 +375,9 @@
"\n",
"\n",
"@qfunc\n",
"def main(x: Output[QNum[NUM_QUBITS]]):\n",
"def main(x: Output[QNum[NUM_QUBITS]], res: Output[QNum]):\n",
" allocate(x)\n",
" simon_qfunc(lambda x, res: simon_qfunc_simple(S_SECRET, x, res), x)\n",
" simon_qfunc(lambda x, res: simon_qfunc_simple(S_SECRET, x, res), x, res)\n",
"\n",
"\n",
"qmod_2 = create_model(\n",
Expand Down Expand Up @@ -411,7 +410,7 @@
"with ExecutionSession(qprog_2, execution_preferences=prefs_more_shots) as es:\n",
" result_2 = es.sample()\n",
"\n",
"bitstrings = result_2.dataframe[\"bitstring\"].tolist()\n",
"bitstrings = [f\"{x:0{NUM_QUBITS}b}\" for x in result_2.dataframe[\"x\"].tolist()]\n",
"reversed_bitstrings = [b[::-1] for b in bitstrings]\n",
"samples = [[int(bit) for bit in b] for b in reversed_bitstrings]"
]
Expand Down Expand Up @@ -602,9 +601,11 @@
"outputs": [],
"source": [
"@qfunc\n",
"def main(x: Output[QNum[NUM_QUBITS]]):\n",
"def main(x: Output[QNum[NUM_QUBITS]], res: Output[QNum]):\n",
" allocate(x)\n",
" simon_qfunc(lambda x, res: simon_qfunc_with_bipartite_s(PARTITION_INDEX, x, res), x)\n",
" simon_qfunc(\n",
" lambda x, res: simon_qfunc_with_bipartite_s(PARTITION_INDEX, x, res), x, res\n",
" )\n",
"\n",
"\n",
"qmod_4 = create_model(main)\n",
Expand Down Expand Up @@ -643,7 +644,7 @@
"with ExecutionSession(qprog_4, execution_preferences=prefs_more_shots) as es:\n",
" result_4 = es.sample()\n",
"\n",
"bitstrings = result_4.dataframe[\"bitstring\"].tolist()\n",
"bitstrings = [f\"{x:0{NUM_QUBITS}b}\" for x in result_4.dataframe[\"x\"].tolist()]\n",
"reversed_bitstrings = [b[::-1] for b in bitstrings]\n",
"samples = [[int(bit) for bit in b] for b in reversed_bitstrings]"
]
Expand Down
7 changes: 3 additions & 4 deletions algorithms/simon/simon_example.qmod
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
qfunc simon_qfunc(f_qfunc: qfunc (qnum, output qnum), x: qnum) {
res: qnum;
qfunc simon_qfunc(f_qfunc: qfunc (qnum, output qnum), x: qnum, output res: qnum) {
within {
hadamard_transform(x);
} apply {
Expand All @@ -11,9 +10,9 @@ qperm simon_qfunc_simple(s: int, const x: qnum, output res: qnum) {
res = min(x, x ^ s);
}

qfunc main(output x: qnum<5>) {
qfunc main(output x: qnum<5>, output res: qnum) {
allocate(x);
simon_qfunc(lambda(x, res) {
simon_qfunc_simple(6, x, res);
}, x);
}, x, res);
}
7 changes: 3 additions & 4 deletions algorithms/simon/simon_shallow_example.qmod
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
qfunc simon_qfunc(f_qfunc: qfunc (qnum, output qnum), x: qnum) {
res: qnum;
qfunc simon_qfunc(f_qfunc: qfunc (qnum, output qnum), x: qnum, output res: qnum) {
within {
hadamard_transform(x);
} apply {
Expand All @@ -18,9 +17,9 @@ qperm simon_qfunc_with_bipartite_s(partition_index: int, const x: qbit[], output
}
}

qfunc main(output x: qnum<6>) {
qfunc main(output x: qnum<6>, output res: qnum) {
allocate(x);
simon_qfunc(lambda(x, res) {
simon_qfunc_with_bipartite_s(4, x, res);
}, x);
}, x, res);
}