Internal:Quantum Information Science (QIS General): Difference between revisions
| Line 35: | Line 35: | ||
crun -p ~/envs/python3.10 python3 -u ./main.py | crun -p ~/envs/python3.10 python3 -u ./main.py | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Matplotlib === | |||
==== Inset Plot ==== | |||
creating an inset plot requires defining inset axes within a pre defined larger plot. For example, if we create a regular lineplot: | |||
<syntaxhighlight lang="python"> | |||
fig, ax = plt.subplots() | |||
plt.plot( | |||
qubits, | |||
qc_cx_3, | |||
"-o", | |||
label="n+1 optimized", | |||
linewidth=2, | |||
color="grey", | |||
markeredgecolor="k" | |||
) | |||
plt.plot( | |||
qubits, | |||
qc_cx_op_3, | |||
"-o", | |||
label="2n optimized", | |||
linewidth=2, | |||
color="mediumpurple", | |||
markeredgecolor="k" | |||
) | |||
plt.ylabel("CX Count") | |||
plt.xlabel("n Qubits") | |||
plt.xticks(qubits) | |||
plt.legend(framealpha=1) | |||
plt.grid() | |||
plt.title("QHED Number of CX Operations") | |||
plt.savefig("test.png") | |||
plt.show() | |||
</syntaxhighlight> | |||
[[File:Inset1.png]] | |||
Import the following the modules for inset plots and define them underneath the original plt.plot() methods: | |||
<syntaxhighlight lang="python"> | |||
fig, ax = plt.subplots() | |||
plt.plot( | |||
qubits, | |||
qc_cx_3, | |||
"-o", | |||
label="n+1 optimized", | |||
linewidth=2, | |||
color="grey", | |||
markeredgecolor="k" | |||
) | |||
plt.plot( | |||
qubits, | |||
qc_cx_op_3, | |||
"-o", | |||
label="2n optimized", | |||
linewidth=2, | |||
color="mediumpurple", | |||
markeredgecolor="k" | |||
) | |||
# Define length and height of inset box | |||
axins = ax.inset_axes([2.8,700, 2, 1000], transform=ax.transData) | |||
axins.plot( | |||
qubits, | |||
qc_cx_3, | |||
"-o", | |||
label="n+1 optimized", | |||
linewidth=2, | |||
color="grey", | |||
markeredgecolor="k" | |||
) | |||
axins.plot( | |||
qubits, | |||
qc_cx_op_3, | |||
"-o", | |||
label="2n optimized", | |||
linewidth=2, | |||
color="mediumpurple", | |||
markeredgecolor="k" | |||
) | |||
axins.set_xlim(1.7, 4.5) # Limit the region for zoom | |||
axins.set_ylim(1, 200) | |||
axins.set_xticks([2,3,4]) | |||
axins.grid() | |||
# | |||
## draw a bbox of the region of the inset axes in the parent axes and | |||
## connecting lines between the bbox and the inset axes area | |||
mark_inset(ax, axins, loc1=3, loc2=4, fc="none", ec="0.5") | |||
plt.ylabel("CX Count") | |||
plt.xlabel("n Qubits") | |||
plt.xticks(qubits) | |||
plt.legend(framealpha=1) | |||
plt.grid() | |||
plt.title("QHED Number of CX Operations") | |||
plt.savefig("test2.png") | |||
plt.show() | |||
</syntaxhighlight> | |||
[[File:Inset2.png]] | |||
Revision as of 16:46, 2 May 2023
QIS General
I will use this page to keep a general progression and categorization about QIS ranging from theory to useful code.
Notebooks
QIS General
Custom built QIS notebooks (some modeled after Nielsen's lectures) can be found here[1].
Code
Qiskit
GPU
Calling a GPU to execute quantum circuits is relatively straight forward. First, choose your backend. This can be ideal, noisy, or a snapshot from a real qiskit quantum device. Once you have your simulator selected, use the *set_options* method to set the device:
try:
simulator_gpu = Aer.get_backend('aer_simulator')
simulator_gpu.set_options(device='GPU')
except AerError as e:
print('Err:\n',e)
When running the script on Wahab, a GPU must be allocated for this. The .sh file should look something like this:
#!/bin/bash
#SBATCH -p gpu
#SBATCH --gres gpu:1
enable_lmod
module load container_env python3
crun -p ~/envs/python3.10 python3 -u ./main.py
Matplotlib
Inset Plot
creating an inset plot requires defining inset axes within a pre defined larger plot. For example, if we create a regular lineplot:
fig, ax = plt.subplots()
plt.plot(
qubits,
qc_cx_3,
"-o",
label="n+1 optimized",
linewidth=2,
color="grey",
markeredgecolor="k"
)
plt.plot(
qubits,
qc_cx_op_3,
"-o",
label="2n optimized",
linewidth=2,
color="mediumpurple",
markeredgecolor="k"
)
plt.ylabel("CX Count")
plt.xlabel("n Qubits")
plt.xticks(qubits)
plt.legend(framealpha=1)
plt.grid()
plt.title("QHED Number of CX Operations")
plt.savefig("test.png")
plt.show()
Import the following the modules for inset plots and define them underneath the original plt.plot() methods:
fig, ax = plt.subplots()
plt.plot(
qubits,
qc_cx_3,
"-o",
label="n+1 optimized",
linewidth=2,
color="grey",
markeredgecolor="k"
)
plt.plot(
qubits,
qc_cx_op_3,
"-o",
label="2n optimized",
linewidth=2,
color="mediumpurple",
markeredgecolor="k"
)
# Define length and height of inset box
axins = ax.inset_axes([2.8,700, 2, 1000], transform=ax.transData)
axins.plot(
qubits,
qc_cx_3,
"-o",
label="n+1 optimized",
linewidth=2,
color="grey",
markeredgecolor="k"
)
axins.plot(
qubits,
qc_cx_op_3,
"-o",
label="2n optimized",
linewidth=2,
color="mediumpurple",
markeredgecolor="k"
)
axins.set_xlim(1.7, 4.5) # Limit the region for zoom
axins.set_ylim(1, 200)
axins.set_xticks([2,3,4])
axins.grid()
#
## draw a bbox of the region of the inset axes in the parent axes and
## connecting lines between the bbox and the inset axes area
mark_inset(ax, axins, loc1=3, loc2=4, fc="none", ec="0.5")
plt.ylabel("CX Count")
plt.xlabel("n Qubits")
plt.xticks(qubits)
plt.legend(framealpha=1)
plt.grid()
plt.title("QHED Number of CX Operations")
plt.savefig("test2.png")
plt.show()

