Internal:Quantum Information Science (QIS General): Difference between revisions
No edit summary |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 10: | Line 10: | ||
== Code == | == Code == | ||
=== Qiskit === | === Qiskit === | ||
==== CPU ==== | |||
We can multithread the execution of circuits on Wahab to expedite measurement. An easy way is by using the following: | |||
<syntaxhighlight lang="python"> | |||
ideal_backend = AerSimulator(method='density_matrix') | |||
ideal_backend.set_options(precision="single", max_parallel_threads=0) | |||
</syntaxhighlight> | |||
Setting max_parallel_threads to 0 enables the simulator to utilize all allocated cores. So, our .sh file may look something like: | |||
<syntaxhighlight lang="python"> | |||
#!/bin/bash -l | |||
#SBATCH --job-name=DENSITY_MATRIX_CPU | |||
#SBATCH --output=CPU.out | |||
#SBATCH --ntasks=512 | |||
cat << EOF | |||
this job is called $SLURM_JOB_NAME and its ID is $SLURM_JOB_ID | |||
job $SLURM_JOB_ID has being allocated $SLURM_NTASKS cores across $SLURM_NNODES hosts | |||
job $SLURM_JOB_ID will be running on the following machines: | |||
EOF | |||
echo $SLURM_NODELIST | |||
enable_lmod | |||
module load container_env python3 | |||
crun -p ~/envs/python3.10 python3 -u ./main.py | |||
</syntaxhighlight> | |||
Which yields the output file CPU.out: | |||
<syntaxhighlight lang="python"> | |||
this job is called DENSITY_MATRIX_CPU and its ID is 1846321 | |||
job 1846321 has being allocated 512 cores across 27 hosts | |||
job 1846321 will be running on the following machines: | |||
d1-w6420a-[03,05-06,10,12,14-15,19,21-23],d4-w6420b-[01,03,05-06,08,10-11],e2-w6420b-[02-03,07,13-14,16,18-20] | |||
</syntaxhighlight> | |||
With, of course, maximized thread execution. Note, that it is possible to hinder performance on circuits if the number of qubits/depth is insufficient. It is also possible to execute multiple circuits simultaneously using the max_parallel_experiments option. | |||
==== GPU ==== | ==== GPU ==== | ||
| Line 35: | Line 80: | ||
crun -p ~/envs/python3.10 python3 -u ./main.py | crun -p ~/envs/python3.10 python3 -u ./main.py | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Matplotlib === | === Matplotlib === | ||
| Line 146: | Line 190: | ||
== Papers == | == Papers == | ||
=== Pulse Control === | === Pulse Control === | ||
A Categorical | A Categorical Order Theory of Pulse Scheduling in Gate-Based Quantum Computing[https://olddominion-my.sharepoint.com/personal/nchrisoc_odu_edu/_layouts/15/onedrive.aspx?ga=1&id=%2Fpersonal%2Fnchrisoc%5Fodu%5Fedu%2FDocuments%2FSpring%5F23%2Fqml%5Fpapers%2FA%20categorical%20order%20theory%20of%20pulse%20scheduling%20in%20gate%2Dbased%20quantum%20computing%2Epdf&parent=%2Fpersonal%2Fnchrisoc%5Fodu%5Fedu%2FDocuments%2FSpring%5F23%2Fqml%5Fpapers] | ||
Latest revision as of 15:56, 7 July 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
CPU
We can multithread the execution of circuits on Wahab to expedite measurement. An easy way is by using the following:
ideal_backend = AerSimulator(method='density_matrix')
ideal_backend.set_options(precision="single", max_parallel_threads=0)
Setting max_parallel_threads to 0 enables the simulator to utilize all allocated cores. So, our .sh file may look something like:
#!/bin/bash -l
#SBATCH --job-name=DENSITY_MATRIX_CPU
#SBATCH --output=CPU.out
#SBATCH --ntasks=512
cat << EOF
this job is called $SLURM_JOB_NAME and its ID is $SLURM_JOB_ID
job $SLURM_JOB_ID has being allocated $SLURM_NTASKS cores across $SLURM_NNODES hosts
job $SLURM_JOB_ID will be running on the following machines:
EOF
echo $SLURM_NODELIST
enable_lmod
module load container_env python3
crun -p ~/envs/python3.10 python3 -u ./main.py
Which yields the output file CPU.out:
this job is called DENSITY_MATRIX_CPU and its ID is 1846321
job 1846321 has being allocated 512 cores across 27 hosts
job 1846321 will be running on the following machines:
d1-w6420a-[03,05-06,10,12,14-15,19,21-23],d4-w6420b-[01,03,05-06,08,10-11],e2-w6420b-[02-03,07,13-14,16,18-20]
With, of course, maximized thread execution. Note, that it is possible to hinder performance on circuits if the number of qubits/depth is insufficient. It is also possible to execute multiple circuits simultaneously using the max_parallel_experiments option.
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:
# Original plots must be defined first
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
# [x_start, y_start, x_len, y_len]
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()
Papers
Pulse Control
A Categorical Order Theory of Pulse Scheduling in Gate-Based Quantum Computing[2]

