Skip to content

Commit

Permalink
[QI2-1223] Remove duplicated e2e login code (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
oschusler authored Dec 23, 2024
1 parent cd9c8da commit e64fff7
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 254 deletions.
19 changes: 10 additions & 9 deletions docs/notebooks/QI2 Performance Test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,30 @@
}
],
"source": [
"def pcircuit(nqubits, depth = 10):\n",
" \"\"\" Circuit to test performance of quantum computer \"\"\"\n",
"def pcircuit(nqubits, depth=10):\n",
" \"\"\"Circuit to test performance of quantum computer\"\"\"\n",
" q = QuantumRegister(nqubits)\n",
" ans = ClassicalRegister(nqubits)\n",
" qc = QuantumCircuit(q, ans)\n",
"\n",
" for level in range(depth):\n",
" for qidx in range(nqubits):\n",
" qc.h( q[qidx] )\n",
" qc.h(q[qidx])\n",
" qc.barrier()\n",
" for qidx in range(nqubits):\n",
" qc.rx(np.pi/2, q[qidx])\n",
" qc.rx(np.pi / 2, q[qidx])\n",
" qc.barrier()\n",
"\n",
" for qidx in range(nqubits):\n",
" if qidx!=0:\n",
" if qidx != 0:\n",
" qc.cx(q[qidx], q[0])\n",
" for qidx in range(nqubits):\n",
" qc.measure(q[qidx], ans[qidx])\n",
" return q, qc\n",
"\n",
"q,qc = pcircuit(4, 1)\n",
"qc.draw(output='mpl')"
"\n",
"q, qc = pcircuit(4, 1)\n",
"qc.draw(output=\"mpl\")"
]
},
{
Expand Down Expand Up @@ -142,10 +143,10 @@
}
],
"source": [
"counts = results.data()['counts']\n",
"counts = results.data()[\"counts\"]\n",
"result_map = {}\n",
"for key in counts:\n",
" bin_str = format(int(key, 16),'04b') \n",
" bin_str = format(int(key, 16), \"04b\")\n",
" result_map[bin_str] = counts[key]\n",
"\n",
"plot_histogram(result_map)"
Expand Down
46 changes: 22 additions & 24 deletions docs/notebooks/Super Dense Coding.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
},
"outputs": [],
"source": [
"def superdense_encoding_circuit(bit_a: int =0, bit_b: int =0) -> QuantumCircuit:\n",
"def superdense_encoding_circuit(bit_a: int = 0, bit_b: int = 0) -> QuantumCircuit:\n",
" circuit = QuantumCircuit(2, 2)\n",
" qubit_a = 0\n",
" qubit_b = 1\n",
Expand All @@ -100,30 +100,29 @@
" circuit.measure(qubit_b, qubit_b)\n",
" circuit.ry(1.57079632679, qubit_a)\n",
" circuit.ry(-1.57079632679, qubit_b)\n",
" circuit.cz(qubit_b,qubit_a)\n",
" circuit.cz(qubit_b, qubit_a)\n",
"\n",
" ## apply variable gate\n",
" encode_gate = bit_a + 2**bit_b\n",
" if encode_gate == 0: # identity I\n",
" if encode_gate == 0: # identity I\n",
" circuit.id(qubit_a)\n",
" elif encode_gate == 1: # X\n",
" elif encode_gate == 1: # X\n",
" circuit.x(qubit_a)\n",
" elif encode_gate == 2: # Z\n",
" elif encode_gate == 2: # Z\n",
" circuit.z(qubit_a)\n",
" elif encode_gate == 3: # Y\n",
" elif encode_gate == 3: # Y\n",
" circuit.y(qubit_a)\n",
"\n",
" circuit.cz(qubit_b, qubit_a)\n",
" circuit.ry(-1.57079632679, qubit_a)\n",
" circuit.ry(1.57079632679, qubit_b)\n",
"\n",
"\n",
" # maximum-likelihood 3 readout (ML3 RO)\n",
" circuit.measure(qubit_b, qubit_a) # in qiskit this measures in z basis\n",
" circuit.measure(qubit_b, qubit_a) # in qiskit this measures in z basis\n",
" circuit.measure(qubit_b, qubit_a) # in qiskit this measures in z basis\n",
"\n",
" return circuit\n"
" return circuit"
]
},
{
Expand Down Expand Up @@ -166,22 +165,22 @@
"for bit_a in range(2):\n",
" for bit_b in range(2):\n",
" circuit = superdense_encoding_circuit(bit_a, bit_b)\n",
" \n",
"\n",
" # if using qxelarator\n",
" #cqasm_string = dumps(circuit)\n",
" #results = execute_string(cqasm_string, iterations=100).results\n",
" #result_map[f'{bit_a}{bit_b}'] = results\n",
" # cqasm_string = dumps(circuit)\n",
" # results = execute_string(cqasm_string, iterations=100).results\n",
" # result_map[f'{bit_a}{bit_b}'] = results\n",
"\n",
" # if using thq QI2 Platform\n",
" job = backend.run(circuit, shots=1024)\n",
" results = job.result(wait_for_results=True) \n",
" counts = results.data()['counts']\n",
" results = job.result(wait_for_results=True)\n",
" counts = results.data()[\"counts\"]\n",
" result_counts = {}\n",
" for key in counts:\n",
" bin_str = format(int(key, 16),'04b') \n",
" bin_str = format(int(key, 16), \"04b\")\n",
" result_counts[bin_str] = counts[key]\n",
" \n",
" result_map[f'{bit_a}{bit_b}'] = result_counts"
"\n",
" result_map[f\"{bit_a}{bit_b}\"] = result_counts"
]
},
{
Expand Down Expand Up @@ -212,18 +211,17 @@
},
"outputs": [],
"source": [
"\n",
"fig, axs = plt.subplots(2, 2, figsize=(8, 6))\n",
"for index, key in enumerate(result_map):\n",
" results = result_map[key]\n",
" entries = list(results.keys())\n",
" occurrences = list(results.values())\n",
" i0 = int(index/2)\n",
" i1 = index % 2 \n",
" axs[i0][i1].bar(entries, occurrences, color='skyblue')\n",
" axs[i0][i1].set_title(f'Supercoding {key}')\n",
" axs[i0][i1].set_xlabel('Entries')\n",
" axs[i0][i1].set_ylabel('Occurrences')\n",
" i0 = int(index / 2)\n",
" i1 = index % 2\n",
" axs[i0][i1].bar(entries, occurrences, color=\"skyblue\")\n",
" axs[i0][i1].set_title(f\"Supercoding {key}\")\n",
" axs[i0][i1].set_xlabel(\"Entries\")\n",
" axs[i0][i1].set_ylabel(\"Occurrences\")\n",
"\n",
"# Adjust layout to prevent overlap\n",
"plt.tight_layout()\n",
Expand Down
Loading

0 comments on commit e64fff7

Please sign in to comment.