Commit 2303e53d authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Added adder circuit example for dm-sim and random circuit for TNQVM

Signed-off-by: Nguyen, Thien Minh's avatarThien Nguyen <>
parent 2a74ae2c
* quantum ripple-carry adder
* Cuccaro et al, quant-ph/0410184
// Install DM-SIM plugin:
// qcor -install-plugin
// Using DM-Sim:
// qcor -linker g++ -qrt nisq adder.qasm -shots 1024 -qpu dm-sim[gpus:1]
// Note: on a login node, GPU-GPU comm is disabled, hence can only run with 1 GPU.
// Multi-GPU on compute node: e.g, see the bsub example:
gate ccx a,b,c
h c;
cx b,c; tdg c;
cx a,c; t c;
cx b,c; tdg c;
cx a,c; t b; t c; h c;
cx a,b; t a; tdg b;
cx a,b;
gate majority a, b, c {
cx c, b;
cx c, a;
ccx a, b, c;
gate unmaj a, b, c {
ccx a, b, c;
cx c, a;
cx a, b;
qubit cin;
qubit a[4];
qubit b[4];
qubit cout;
bit ans[5];
// Input values:
uint[4] a_in = 1;
uint[4] b_in = 15;
for i in [0:4] {
if (bool(a_in[i])) {
x a[i];
if (bool(b_in[i])) {
x b[i];
// add a to b, storing result in b
majority cin, b[0], a[0];
for i in [0: 3] {
majority a[i], b[i + 1], a[i + 1];
cx a[3], cout;
for i in [2: -1: -1] {
unmaj a[i], b[i+1], a[i+1];
unmaj cin, b[0], a[0];
measure b[0:3] -> ans[0:3];
measure cout[0] -> ans[4];
\ No newline at end of file
include "";
const n_qubits = 50;
const n_layers = 12;
qubit q[n_qubits];
// Compile: qcor random_circuit.qasm
// Run by: mpiexec -n <N> ./a.out -qrt nisq -qpu tnqvm -qpu-config tnqvm.ini
// Loop over layers
float[64] theta = 1.234;
for i in [0:n_layers] {
// Single qubit layers:
for j in [0:n_qubits] {
rx(theta) q[j];
// For demonstration purposes, just change the
// angle in each layer by adding 1.0.
theta += 1.0;
// Entanglement layers:
for j in [0:n_qubits - 1] {
cx q[j], q[j+1];
#BSUB -W 1
#BSUB -nnodes 1
#BSUB -o out_cc.txt -e err_cc.txt
module load python/3.8.10 gcc/9.3.0 cuda/11.4.0 openblas/0.3.15-omp
## "--smpiargs=-gpu" is for enabling GPU-Direct RDMA
## 4 GPUs
jsrun -n4 -a1 -g1 -c1 --smpiargs="-gpu" ./a.out
\ No newline at end of file
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment