Amit commited on
Commit
d17e641
·
1 Parent(s): 71cba39

Minimal demo added. README updated to mention demo.

Browse files
README.md CHANGED
@@ -23,6 +23,9 @@ The repository contains the following:
23
  - plots_display_all.ipynb: the notebook used to display plots of benchmarks (mainly extracting the data from 'data' folder as above and integrating them into the files in 'plot_scripts')
24
  - expectation_plots.ipynb: the notebook used to display plots corresponding to expectation values (mainly extracting the data from 'exp_data' folder and integrating them into the plot files)
25
 
 
 
 
26
  # Zenodo repository
27
 
28
  The container images used to generate the benchmarks and their usage are shared at the Zenodo repository: https://zenodo.org/records/10376217
 
23
  - plots_display_all.ipynb: the notebook used to display plots of benchmarks (mainly extracting the data from 'data' folder as above and integrating them into the files in 'plot_scripts')
24
  - expectation_plots.ipynb: the notebook used to display plots corresponding to expectation values (mainly extracting the data from 'exp_data' folder and integrating them into the plot files)
25
 
26
+
27
+ The `demo` folder has further instructions that reproduces a minimal example of files required to execute the toolchain on a HPC cluster while collecting the profiling data.
28
+
29
  # Zenodo repository
30
 
31
  The container images used to generate the benchmarks and their usage are shared at the Zenodo repository: https://zenodo.org/records/10376217
demo/README.md ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is a demo of the toolchain. The qalgo folder has the quantum algorithm to be benchmarked with folders:
2
+
3
+ - gen_files: This folder has the main machinery that generates the associated run files given the qasm files, job scripts and scope files that scope into environment of the container
4
+ - qasm_files: The quantum algorithm represented using the QASM instruction set
5
+ - qasm_parser: The parser that translates the QASM instruction into the instruction of the simulation package
6
+ - simulation package folder: The folder of the simulation package with the associated run files and job scripts
7
+
8
+ To generate the associated files, in this instance the qiskit files associated with the Heisenberg dynamics:
9
+
10
+ 1. Create qiskit folder in qalgo folder
11
+
12
+ - mkdir -v qiskit
13
+
14
+ 2. Change into the gen_files folder and run the file
15
+
16
+ - python3 create_dir_struct.py (allows to set the options inside the file)
17
+
18
+ 3. In the qiskit folder the following folders are generated:
19
+
20
+ - bash_scripts_st_dp: bash scripts that scope the run files into the environment of the container
21
+ - data_st_dp: data folder to store the time statistics
22
+ - error_st_dp: error folder to store the errors of the job
23
+ - output_st_dp: output folder to store the output of the job
24
+ - job_scripts_st_dp: job scripts folder that has the jobs to be executed on the cluster (tailored for PSI cluster)
25
+ - run_files_st_dp: translated run files from qasm to qiskit instruction set
26
+
27
+ 4. run_jobs_st_dp.sh: pushes all the jobs in the `bash_scripts_st_dp` onto the cluster
28
+
29
+ =============================================================================================================================
30
+
31
+ Note:
32
+
33
+ 1. The above instructions are tailored for a demo i.e., a minimal reproduction of the toolchain and its files (for
34
+ the entire version: please see the files in the folder `toolchain`)
35
+
36
+ 2. 1. The singularity containers are not contained in this repo but are on the zenodo repo. These can be accessed using
37
+ the following commands or as in the job scripts:
38
+
39
+ - singularity shell qucos_sim.sif
40
+
41
+ 3. The containerized image has conda environments for all the packages (also in `bash_script_sample.sh` in zenodo repo) that is
42
+ as follows:
43
+
44
+ ```
45
+ #!/bin/bash -l
46
+ . /app/etc/profile.d/conda.sh
47
+ conda activate sim_package
48
+ python3 /home/<translated_run_file.py>
49
+
50
+ # Available conda environments on CPU singularity image: qucos_sim.sif
51
+ # Can be activated by issuing the commands as above, replace sim_package
52
+ # by the package of choice as below:
53
+ # sim_braket
54
+ # sim_cirq
55
+ # sim_hybridq
56
+ # sim_myqlm
57
+ # sim_myqlm_cpp
58
+ # sim_pennylane
59
+ # sim_pennylane_l
60
+ # sim_projectq
61
+ # sim_qibo
62
+ # sim_qibojit
63
+ # sim_qiskit
64
+ # sim_qpanda
65
+ # sim_qsimcirq
66
+ # sim_qulacs
67
+ # sim_svsim
68
+
69
+ # Available conda environments on GPU singularity image: qucos_gpu_sim.sif
70
+ # Can be activated by issuing the commands as above, replace sim_package
71
+ # by the package of choice as below:
72
+ # sim_hybridq_gpu
73
+ # sim_pennylane_l_gpu
74
+ # sim_qcgpu_gpu
75
+ # sim_qibojit_gpu
76
+ # sim_qiskit_gpu
77
+ # sim_qpanda_gpu
78
+ # sim_qsimcirq_gpu
79
+ # sim_qulacs_gpu
80
+ # sim_svsim_gpu
81
+ ```
82
+
83
+ 4. The use of containerized image implies that the packages installed in the container do not need additional dependencies
84
+ and can be used in a straight out-of-box fashion. However to check the dependencies one can issue the command
85
+ `pip list` once the corresponding conda environment is activated (conda environments listed above).
demo/qalgo/gen_files/create_bash_script.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import os
3
+ import subprocess
4
+
5
+ sim_pack = sys.argv[1]
6
+ task = sys.argv[2]
7
+ com_cap = sys.argv[3]
8
+ prec = sys.argv[4]
9
+
10
+ N_arr = range(6, 36, 2)
11
+
12
+ for N in N_arr:
13
+ with open('{}_{}_{}_{}.sh'.format(task, com_cap, prec, N), 'a') as job_file:
14
+ job_file.write('#!/bin/bash -l\n')
15
+ job_file.write('. /app/etc/profile.d/conda.sh\n')
16
+
17
+ if com_cap == 'st' or com_cap == 'mt':
18
+ job_file.write('conda activate sim_{}\n'.format(sim_pack))
19
+
20
+ elif com_cap == 'gpu':
21
+ job_file.write('conda activate sim_{}_gpu\n'.format(sim_pack))
22
+
23
+ job_file.write('python3 /home/{}_n{}.py\n'.format(task, N))
demo/qalgo/gen_files/create_dir_struct.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ sim_pack = 'qiskit'
4
+ task = 'hdyn'
5
+ com_cap = 'st'
6
+ prec = 'dp'
7
+
8
+ gen_path = os.path.abspath(os.getcwd()) + '/'
9
+ # print(gen_path)
10
+ par_dir_path = os.path.abspath(os.path.join(gen_path, os.pardir))
11
+ # print(par_dir_path)
12
+ sim_path = par_dir_path + '/{}/'.format(sim_pack)
13
+
14
+ # print(sim_path)
15
+
16
+ print(' ############################ ')
17
+
18
+ print('### Create job scripts folder for package: {}, task: {}, compute cap: {}, precision: {}'.format(sim_pack, task, com_cap, prec))
19
+ job_scripts_path = sim_path+'job_scripts_{}_{}'.format(com_cap, prec)
20
+ print(job_scripts_path)
21
+ os.mkdir(job_scripts_path)
22
+
23
+ print('### Create job scripts')
24
+ os.chdir(job_scripts_path)
25
+ cjs = gen_path+'create_job_script.py {} {} {} {}'.format(sim_pack, task, com_cap, prec)
26
+ os.system('python3 {}'.format(cjs))
27
+
28
+ print(' ############################ ')
29
+
30
+ print('### Create bash scripts folder for package: {}, task: {}, compute cap: {}, precision: {}'.format(sim_pack, task, com_cap, prec))
31
+ bash_scripts_path = sim_path+'bash_scripts_{}_{}'.format(com_cap, prec)
32
+ os.mkdir(bash_scripts_path)
33
+
34
+ print('### Create bash scripts')
35
+ os.chdir(bash_scripts_path)
36
+ cbs = gen_path+'create_bash_script.py {} {} {} {}'.format(sim_pack, task, com_cap, prec)
37
+ os.system('python3 {}'.format(cbs))
38
+
39
+ print(' ############################ ')
40
+
41
+ print('### Create output folder')
42
+ os.mkdir(sim_path+'output_{}_{}'.format(com_cap, prec))
43
+
44
+ print('### Create error folder')
45
+ os.mkdir(sim_path+'error_{}_{}'.format(com_cap, prec))
46
+
47
+ print('### Create data folder')
48
+ os.mkdir(sim_path+'data_{}_{}'.format(com_cap, prec))
49
+
50
+ print(' ############################ ')
51
+
52
+ print('### Create run files folder package: {}, task: {}, compute cap: {}, precision: {}'.format(sim_pack, task, com_cap, prec))
53
+ run_files_path = sim_path+'run_files_{}_{}'.format(com_cap, prec)
54
+ os.mkdir(run_files_path)
55
+
56
+ # sim_parser = input("Enter the python file including the path for the parser: ")
57
+ sim_parser = par_dir_path + '/qasm_parser/qasm_qiskit_parser_2pt0_new.py'
58
+ os.system('python3 {}'.format(sim_parser))
59
+
60
+ print(' ############################ ')
61
+
62
+ print('### Create bash scripts to run jobs')
63
+ os.chdir(sim_path)
64
+
65
+ with open('run_jobs_{}_{}.sh'.format(com_cap, prec), 'w') as f:
66
+
67
+ f.write('path={}job_scripts_{}_{}\n'.format(sim_path, com_cap, prec))
68
+ f.write('cd $path\n')
69
+ f.write('for job_script in *.sh; do\n')
70
+ f.write('echo $job_script;\n')
71
+ f.write('sbatch $job_script;\n')
72
+ f.write('done\n')
73
+
demo/qalgo/gen_files/create_job_script.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import sys
3
+ import os
4
+
5
+ N_arr = np.arange(6, 36, 2)
6
+ # N_arr = np.append(N_arr, np.arange(41, 51, 1))
7
+ # _partition = 'hourly'
8
+
9
+ # sim_pack = 'qiskit'
10
+ # task = 'hdyn'
11
+ # com_cap = 'st'
12
+ # prec = 'dp'
13
+
14
+ sim_pack = sys.argv[1]
15
+ task = sys.argv[2]
16
+ com_cap = sys.argv[3]
17
+ prec = sys.argv[4]
18
+
19
+ gen_path = os.path.abspath(os.getcwd()) + '/'
20
+ par_dir_path = os.path.abspath(os.path.join(gen_path, os.pardir)) + '/'
21
+ sim_path = par_dir_path + '/{}/'.format(sim_pack)
22
+
23
+ for ind, N in enumerate(N_arr):
24
+ with open('{}_{}_{}_{}.sh'.format(task, com_cap, prec, N), 'a') as job_file:
25
+ job_file.write('#!/bin/bash -l\n')
26
+ job_file.write('#SBATCH --job-name={}_{}_{}_{}_{}\n'.format(sim_pack, task, com_cap, prec, N))
27
+
28
+ if N < 26:
29
+ job_file.write('#SBATCH --partition=hourly\n')
30
+ else:
31
+ job_file.write('#SBATCH --partition=general\n')
32
+
33
+ if com_cap == 'st':
34
+ job_file.write('#SBATCH --hint=nomultithread\n')
35
+ job_file.write('#SBATCH --nodes=1\n')
36
+ job_file.write('#SBATCH --ntasks=1\n')
37
+ job_file.write('#SBATCH --cpus-per-task=1\n')
38
+ job_file.write('#SBATCH --ntasks-per-core=1\n')
39
+
40
+ elif com_cap == 'mt':
41
+ job_file.write('#SBATCH --hint=multithread\n')
42
+ job_file.write('#SBATCH --nodes=1\n')
43
+ job_file.write('#SBATCH --ntasks=1\n')
44
+ job_file.write('#SBATCH --cpus-per-task=42\n')
45
+ job_file.write('#SBATCH --ntasks-per-core=2\n')
46
+
47
+ if N < 26:
48
+ job_file.write('#SBATCH --mem=30G\n')
49
+ else:
50
+ job_file.write('#SBATCH --mem=300G\n')
51
+ if N < 26:
52
+ job_file.write('#SBATCH --time=01:00:00\n')
53
+ else:
54
+ job_file.write('#SBATCH --time=23:00:00\n')
55
+
56
+ # job_file.write('#SBATCH --mail-user=amit.gangapuram@psi.ch\n')
57
+ # job_file.write('#SBATCH --mail-type=BEGIN,END,FAIL\n')
58
+ # job_file.write('#SBATCH --output /data/user/gangap_a/{}_singular/{}/output_{}_{}/{}_{}_{}_{}.out\n'.format(task, sim_pack, com_cap, prec, task, com_cap, prec, N))
59
+ # job_file.write('#SBATCH --error /data/user/gangap_a/{}_singular/{}/error_{}_{}/{}_{}_{}_{}.err\n'.format(task, sim_pack, com_cap, prec, task, com_cap, prec, N))
60
+ job_file.write('\n\n')
61
+
62
+ if sim_pack == 'projectq' or sim_pack == 'quest' or sim_pack == 'intel_qs_cpp' or sim_pack == 'svsim' or sim_pack == 'hybridq' or sim_pack == 'hiq' or sim_pack == 'qibo' or sim_pack == 'qibojit' or sim_pack == 'qrack_sch' or sim_pack == 'qrack_opt' or sim_pack == 'pennylane_l' or sim_pack == 'qpp' or sim_pack == 'qpanda' or sim_pack =='braket' or sim_pack == 'myqlm' or sim_pack == 'myqlm_cpp':
63
+ if com_cap == 'st':
64
+ job_file.write('OMP_NUM_THREADS=1\n')
65
+ job_file.write('export OMP_NUM_THREADS\n')
66
+
67
+ elif com_cap == 'mt':
68
+ job_file.write('OMP_NUM_THREADS=84\n')
69
+ job_file.write('export OMP_NUM_THREADS\n')
70
+
71
+ job_file.write('export SRUN_CPUS_PER_TASK=$SLURM_CPUS_PER_TASK\n')
72
+
73
+
74
+ else:
75
+ job_file.write('export APPTAINER_BIND="{}bash_scripts_{}_{}/:/brf,{}run_files_{}_{}/:/home,{}data_{}_{}/\"\n'.format(par_dir_path, com_cap, prec, par_dir_path, com_cap, prec, par_dir_path, com_cap, prec))
76
+
77
+ if com_cap == 'gpu':
78
+ job_file.write('singularity exec --nv /data/user/gangap_a/singularity_images/qucos_gpu_sim.sif bash /brf/{}_{}_{}_{}.sh\n'.format(task, com_cap, prec, N))
79
+ else:
80
+ job_file.write('singularity exec <path_to_singularity_image>/qucos_sim.sif bash /brf/{}_{}_{}_{}.sh\n'.format(task, com_cap, prec, N))
81
+
82
+
83
+
demo/qalgo/gen_files/run_jobs_st_dp.sh ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ task='hdyn'
4
+ sim_pack='qiskit'
5
+ com_cap='st'
6
+ prec='dp'
7
+
8
+ cd ..
9
+ cd ${sim_pack}
10
+
11
+ for job_script in *.sh; do
12
+ echo $job_script;
13
+ sbatch $job_script;
14
+ done
15
+
demo/qalgo/qasm_files/qasm_N_10.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_12.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_14.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_16.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_18.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_20.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_22.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_24.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_26.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_28.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_30.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_32.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_34.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_36.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_6.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_files/qasm_N_8.qasm ADDED
The diff for this file is too large to render. See raw diff
 
demo/qalgo/qasm_parser/qasm_qiskit_parser_2pt0_new.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Credit to: https://github.com/qulacs/cirq-qulacs/blob/master/benchmark/benchmark_state_vector_qulacs.py
2
+
3
+ import re
4
+ import subprocess
5
+ import os
6
+
7
+ def parse_qasm_to_package_gen(N, mpt, spt, f_precision, input_filename, output_filename, save_data_path):
8
+
9
+ with open(output_filename, 'w') as f:
10
+
11
+ f.write('import os\n')
12
+ f.write('from qiskit import QuantumRegister, QuantumCircuit, transpile, ClassicalRegister\n')
13
+ f.write('from qiskit.quantum_info.operators import Operator\n')
14
+ f.write('from qiskit.providers.aer import QasmSimulator\n')
15
+ f.write('from qiskit import Aer\n')
16
+ f.write('from time import process_time, perf_counter\n')
17
+ f.write('import numpy as np\n\n')
18
+
19
+ f.write('def U2(p, l):\n')
20
+ f.write(' mat = ((np.cos(0.5*(p + l)) - 1j*np.sin(0.5*(p + l)))/np.sqrt(2))*np.array([[1, -np.cos(l)-1j*np.sin(l)], [np.cos(p) + 1j*np.sin(p), np.cos(l + p) + 1j*np.sin(l + p)]])\n')
21
+ f.write(' return Operator(mat)\n\n')
22
+
23
+ f.write('def U3(t, p, l):\n')
24
+ f.write(' mat = (np.cos(0.5*(p + l)) - 1j*np.sin(0.5*(p + l)))*np.array([[np.cos(t/2.), -np.sin(t/2.)*(np.cos(l) + 1j*np.sin(l))], [np.sin(t/2.)*(np.cos(p) + 1j*np.sin(p)), np.cos(t/2.)*(np.cos(l + p) + 1j*np.sin(l + p))]])\n')
25
+ f.write(' return Operator(mat)\n\n')
26
+
27
+ f.write('t_sp = process_time()\n')
28
+ f.write('t_s = perf_counter()\n')
29
+
30
+ f.write('backend = Aer.get_backend(\'statevector_simulator\')#, max_parallel_threads={}, statevector_parallel_threshold={}, precision=\'{}\')\n'.format(mpt, spt, f_precision))
31
+ f.write('opt = backend.options\n')
32
+ f.write('opt.max_parallel_threads={}\n'.format(mpt))
33
+ f.write('opt.statevector_parallel_threshold={}\n'.format(spt))
34
+ f.write('opt.precision=\'{}\'\n'.format(f_precision))
35
+
36
+ f.write('cir = QuantumCircuit({})\n'.format(N))
37
+ with open(input_filename, "r") as ifile:
38
+ lines = ifile.readlines()
39
+
40
+ lc = 0
41
+ cirq_c = 0
42
+ for line in lines:
43
+
44
+ s = re.search(r"Generated|QASM|include|qreg|Qubits|cirq|x|y|z|h|rx|ry|rz|cx|u2|u3|\bsx\b|\bsxdg\b|s", line)
45
+
46
+ if s is None:
47
+ continue
48
+
49
+ elif s.group() in ['Generated', 'QASM', 'include', 'qreg', 'Qubits']:#, 'cirq']:
50
+ lc = lc + 1
51
+ f.write('# {}\n'.format(s.group()))
52
+ continue
53
+
54
+ elif s.group() == 'cirq':
55
+ lc = lc + 1
56
+ f.write('# {} {}\n'.format(s.group(), cirq_c))
57
+ cirq_c = cirq_c + 1
58
+ continue
59
+
60
+ elif s.group() == 'x' or s.group() == 'y' or s.group() == 'z' or s.group() == 's' or s.group() == 'sx' or s.group() == 'sxdg' or s.group() == 'h':
61
+ lc = lc + 1
62
+ m_i = re.findall(r'\[\d\d*\]', line)
63
+ t_qbit = int(m_i[0].strip('[]'))
64
+ f.write('cir.{}({})\n'.format(s.group(), t_qbit))
65
+ continue
66
+
67
+ elif s.group() == 'rx' or s.group() == 'ry' or s.group() == 'rz':
68
+ lc = lc + 1
69
+ m_r = re.findall(r'\((.*?)\)', line)
70
+ # print(m_r)
71
+ if 'pi' in m_r[0] and 'e' in m_r[0]:
72
+ sp_str = m_r[0].split('e-')
73
+ m_r[0] = [re.findall(r'[-]?\d*\.\d\d*', sp_str[0])[0] + 'E-' + sp_str[1]]
74
+ elif 'pi' in m_r[0]:
75
+ m_r[0] = re.findall(r'[-]?\d*\.\d\d*', m_r[0])
76
+ # print(m_r)
77
+ m_i = re.findall(r'\[\d\d*\]', line)
78
+ t_qbit = int(m_i[0].strip('[]'))
79
+ f.write('cir.{}(np.pi*{}, {})\n'.format(s.group(), float(m_r[0][0]), t_qbit))
80
+ continue
81
+
82
+ elif s.group() == 'cx':
83
+ lc = lc + 1
84
+ match = re.findall(r'\[\d\d*\]', line)
85
+ c_qbit = int(match[0].strip('[]'))
86
+ t_qbit = int(match[1].strip('[]'))
87
+ f.write('cir.cx({}, {})\n'.format(c_qbit, t_qbit))
88
+ continue
89
+
90
+ elif s.group() == 'u2':
91
+ lc = lc + 1
92
+ m_r = re.findall(r'\((.*?,.*?)\)', line)
93
+ m_r = m_r[0].split(',')
94
+ for i, m in enumerate(m_r):
95
+ if 'pi' in m and 'e' in m:
96
+ sp_str = m_r[i].split('e-')
97
+ m_r[i] = [re.findall(r'[-]?\d*\.\d\d*', sp_str[0])[0] + 'E-' + sp_str[1]]
98
+ elif 'pi' in m:
99
+ m_r[i] = re.findall(r'[-]?\d*\.\d\d*', m)
100
+ else:
101
+ m_r[i] = '0'
102
+ m_i = re.findall(r'\[\d\d*\]', line)
103
+ t_qbit = int(m_i[0].strip('[]'))
104
+ # f.write('cir.u(np.pi/2., np.pi*{}, np.pi*{}, {})\n'.format(float(m_r[0][0]), float(m_r[1][0]), t_qbit))
105
+ f.write('cir.append(U2(np.pi*{}, np.pi*{}), [{}])\n'.format(float(m_r[0][0]), float(m_r[1][0]), t_qbit))
106
+ continue
107
+
108
+ elif s.group() == 'u3':
109
+ lc = lc + 1
110
+ m_r = re.findall(r'\((.*?,.*?,.*?)\)', line)
111
+ m_r = m_r[0].split(',')
112
+ for i, m in enumerate(m_r):
113
+ if 'pi' in m and 'e' in m:
114
+ sp_str = m_r[i].split('e-')
115
+ m_r[i] = [re.findall(r'[-]?\d*\.\d\d*', sp_str[0])[0] + 'E-' + sp_str[1]]
116
+ elif 'pi' in m:
117
+ m_r[i] = re.findall(r'[-]?\d*\.\d\d*', m)
118
+ else:
119
+ m_r[i] = '0'
120
+ m_i = re.findall(r'\[\d\d*\]', line)
121
+ t_qbit = int(m_i[0].strip('[]'))
122
+ # f.write('cir.u(np.pi*{}, np.pi*{}, np.pi*{}, {})\n'.format(float(m_r[0][0]), float(m_r[1][0]),float(m_r[2][0]), t_qbit))
123
+ f.write('cir.append(U3(np.pi*{}, np.pi*{}, np.pi*{}), [{}])\n'.format(float(m_r[0][0]), float(m_r[1][0]),float(m_r[2][0]), t_qbit))
124
+ continue
125
+
126
+ f.write('job = backend.run(transpile(cir, backend))\n')
127
+ f.write('result = job.result()\n')
128
+ f.write('outputstate = result.get_statevector(cir)\n')
129
+
130
+ f.write('t_e = perf_counter()\n')
131
+ f.write('t_ep = process_time()\n')
132
+
133
+ f.write('os.chdir(\'{}\')\n'.format(save_data_path))
134
+ f.write('np.save(\'time_n{}.npy\', [t_e - t_s, t_ep - t_sp])\n'.format(N))
135
+ # f.write('print(t_e - t_s)\n')
136
+ # f.write('print(t_ep - t_sp)\n')
137
+
138
+
139
+ # result = subprocess.run(["grep", ".", input_filename, "|", "wc", "-l"], text=True)#stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
140
+ _cmd = "grep . " + input_filename + "| wc -l"
141
+ lc_res = subprocess.check_output(_cmd, shell=True)
142
+ print(int(lc_res) == lc)
143
+ # print(lc)
144
+
145
+
146
+ task = 'hdyn'
147
+ sim_pack = 'qiskit'
148
+ com_cap = 'st'
149
+ prec = 'dp'
150
+
151
+ gen_path = os.path.abspath(os.getcwd())
152
+ print(gen_path)
153
+ par_dir_path = os.path.abspath(os.path.join(gen_path, os.pardir))
154
+ print(par_dir_path)
155
+ par2_dir_path = os.path.abspath(os.path.join(par_dir_path, os.pardir))
156
+ print(par2_dir_path)
157
+
158
+
159
+ for N in range(6, 38, 2):
160
+ input_file_path = par2_dir_path + '/qasm_files/'
161
+ input_file = input_file_path + 'qasm_N_{}.qasm'.format(N)
162
+
163
+ save_file_path = par2_dir_path + '/{}/data_{}_{}'.format(sim_pack, com_cap, prec)
164
+
165
+ output_file_path = par2_dir_path + '/{}/run_files_{}_{}/'.format(sim_pack, com_cap, prec)
166
+
167
+ output_file = output_file_path + '{}_n{}.py'.format(task, N)
168
+ parse_qasm_to_package_gen(N, 1, 40, "double", input_file, output_file, save_file_path)