From e8b031784bc624d71ac9164c144c986acb501409 Mon Sep 17 00:00:00 2001 From: Wong Zi Cheng <70616433+chmwzc@users.noreply.github.com> Date: Thu, 23 May 2024 08:22:42 +0000 Subject: [PATCH] Update benchmarking scripts --- benchmarks/benchmarks/scripts.py | 11 ++++--- benchmarks/run-benchmark.sh | 55 +++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/benchmarks/benchmarks/scripts.py b/benchmarks/benchmarks/scripts.py index 06bb436..bbe78a0 100644 --- a/benchmarks/benchmarks/scripts.py +++ b/benchmarks/benchmarks/scripts.py @@ -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 @@ -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) diff --git a/benchmarks/run-benchmark.sh b/benchmarks/run-benchmark.sh index 5122207..bdf9e82 100755 --- a/benchmarks/run-benchmark.sh +++ b/benchmarks/run-benchmark.sh @@ -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