Skip to content

Commit

Permalink
Update benchmarking scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
chmwzc committed May 23, 2024
1 parent c3fa31b commit e8b0317
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
11 changes: 6 additions & 5 deletions benchmarks/benchmarks/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ def circuit_benchmark(
# Construct UCC circuit ansatz using some hydrogen chain
# 1. Get molecule first
start_time = time.time()
# mol = build_molecule(n_hydrogens)
# assert n_hydrogens % 2 == 0, f"{n_hydrogens} must be even"
hh_bond_length = 0.75 # angstroms
geom = [("H", (0.0, 0.0, _i * hh_bond_length)) for _i in range(n_hydrogens)]
mol = Molecule(geom)
mol.run_pyscf()
logs.log(pyscf_time=time.time() - start_time)
mol.nso = 2 * n_hydrogens
mol.nelec = n_hydrogens
# mol.run_pyscf() # No need to run PySCF, just need to define mol.nso and mol.nelec
logs.log(build_mol_time=time.time() - start_time)
# Build the actual UCC ansatz
start_time = time.time()
circuit = ucc_ansatz(mol)
circuit = ucc_ansatz(mol, use_mp2_guess=False)
logs.log(creation_time=time.time() - start_time)

# from benchmarks import circuits
Expand Down Expand Up @@ -105,7 +106,7 @@ def circuit_benchmark(
creation_times, simulation_times, transfer_times = [], [], []
for _ in range(nreps):
start_time = time.time()
circuit = ucc_ansatz(mol)
circuit = ucc_ansatz(mol, use_mp2_guess=False)

# circuit = qibo.models.Circuit(nqubits)
# circuit.add(gates)
Expand Down
55 changes: 44 additions & 11 deletions benchmarks/run-benchmark.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
#!/bin/bash

#
# Test variables
#
data_folder="data"
nreps=5
precisions="double" # "single double"

nreps=10
# backends="numpy qibojit tensorflow pytorch"
backends="tensorflow" # ZC note: pytorch backend not fully implemented

# platforms="numba cupy cuquantum"
platforms="cupy cuquantum" # ZC note: If using numba platform with GPU available, will it use the GPU or stick to CPU?

n_hydrogens="4" # "2 4 6 8 10"

# echo "Main script starts"
# Run main.py with various command-line arguments/options
for n_hydrogen in 2 4 6 8; do
for backend in numpy qibojit; do
filename="h${n_hydrogen}_${backend}"
for precision in single double; do
python main.py --n_hydrogens ${n_hydrogen} --backend ${backend} --nreps ${nreps} --precision ${precision} --filename ${filename}.dat &>> ${filename}.log
echo &>> ${filename}.log
done
# for n_hydrogen in 2 4 6 8; do
for n_hydrogen in ${n_hydrogens}; do
# echo ${n_hydrogen}
for backend in ${backends}; do
# for backend in numpy qibojit; do
if [ "${backend}" == "qibojit" ]; then
for platform in ${platforms}; do
# for platform in numba cupy cuquantum; do
filename="h${n_hydrogen}_${backend}_${platform}"
for precision in ${precisions}; do
# for precision in single double; do
python main.py --n_hydrogens ${n_hydrogen} --backend ${backend} --platform ${platform} --nreps ${nreps} --precision ${precision} --filename ${filename}.dat &>> ${filename}.log
echo &>> ${filename}.log
done

# Move the .log and .dat file into data/ folder
if [ -d "${data_folder}" ]; then
mv ${filename}.dat ${filename}.log "${data_folder}"
fi
done
else
filename="h${n_hydrogen}_${backend}"
for precision in ${precisions}; do
python main.py --n_hydrogens ${n_hydrogen} --backend ${backend} --nreps ${nreps} --precision ${precision} --filename ${filename}.dat &>> ${filename}.log
echo &>> ${filename}.log
done

# Move the .log and .dat file into data/ folder
if [ -d "data" ]; then
mv ${filename}.dat ${filename}.log
# Move the .log and .dat file into data/ folder
if [ -d "data" ]; then
mv ${filename}.dat ${filename}.log "${data_folder}"
fi
fi
done
done

0 comments on commit e8b0317

Please sign in to comment.