Skip to content

Commit

Permalink
Update deprecated pandas in Fourier Checking tutorial (#5751)
Browse files Browse the repository at this point in the history
- Dataframe.append is deprecated and generates tons of
warnings in the notebook on the quantum AI site.
- Change this to pandas.concat().
  • Loading branch information
dstrain115 authored Jul 13, 2022
1 parent b64aab2 commit 5a07f7e
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions docs/experiments/fourier_checking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@
"for _ in range(number_of_functions_to_try):\n",
" dist, f = choose_random_function()\n",
" decision = randomized_alg(f, samples_size_per_function)\n",
" res = res.append({\n",
" \"Distribution\": dist,\n",
" \"Decision\": decision,\n",
" \"Count\": 1\n",
" }, ignore_index=True)\n",
" res=pd.concat([res, pd.DataFrame({\n",
" \"Distribution\": [dist],\n",
" \"Decision\":[decision],\n",
" \"Count\": [1]\n",
" })], ignore_index=True)\n",
"confusion = res.pivot_table(index=\"Distribution\",\n",
" columns=\"Decision\",\n",
" values=\"Count\",\n",
Expand Down Expand Up @@ -322,12 +322,11 @@
" decision = randomized_alg(f, samples_size_per_function)\n",
" constant_minus_blanaced_count += 1 if decision == \"constant\" else -1\n",
" final_decision = \"constant\" if constant_minus_blanaced_count > 0 else \"balanced\"\n",
" res = res.append(\n",
" {\n",
" \"Distribution\": dist,\n",
" \"Decision\": final_decision,\n",
" \"Count\": 1\n",
" }, ignore_index=True)\n",
" res=pd.concat([res, pd.DataFrame({\n",
" \"Distribution\": [dist],\n",
" \"Decision\":[final_decision],\n",
" \"Count\": [1]\n",
" })], ignore_index=True)\n",
"confusion = res.pivot_table(index=\"Distribution\",\n",
" columns=\"Decision\",\n",
" values=\"Count\",\n",
Expand Down Expand Up @@ -867,18 +866,12 @@
" circuit = cirq.Circuit(fourier_checking_algorithm(qubits, fs, gs))\n",
" obs = s.run(circuit, repetitions=repetitions)\n",
" times_zero_was_measured = len(obs.data[obs.data[qubits_name] == 0])\n",
" if times_zero_was_measured / repetitions > 0.05:\n",
" res = res.append({\n",
" \"Source\": source,\n",
" \"Decision\": \"accept\",\n",
" \"Count\": 1\n",
" }, ignore_index=True)\n",
" else:\n",
" res = res.append({\n",
" \"Source\": source,\n",
" \"Decision\": \"reject\",\n",
" \"Count\": 1\n",
" }, ignore_index=True)\n",
" decision = \"accept\" if times_zero_was_measured / repetitions > 0.05 else \"reject\"\n",
" res=pd.concat([res, pd.DataFrame({\n",
" \"Source\": [source],\n",
" \"Decision\":[decision],\n",
" \"Count\": [1]\n",
" })], ignore_index=True)\n",
"confusion = res.pivot_table(index=\"Source\", columns=\"Decision\", values=\"Count\", aggfunc=\"sum\")\n",
"# Translate the counts into percentage\n",
"confusion.div(confusion.sum(axis=1), axis=0).apply(lambda x: round(x, 4) * 100)"
Expand Down

0 comments on commit 5a07f7e

Please sign in to comment.