├── .gitignore ├── README.md ├── benchmarks-QuTiP ├── __init__.py ├── addition_dense_dense.py ├── addition_dense_sparse.py ├── addition_sparse_dense.py ├── addition_sparse_sparse.py ├── benchmarkutils.py ├── coherentstate.py ├── displace.py ├── expect_operator.py ├── expect_state.py ├── multiplication_bra_dense.py ├── multiplication_bra_sparse.py ├── multiplication_dense_dense.py ├── multiplication_dense_ket.py ├── multiplication_dense_sparse.py ├── multiplication_sparse_dense.py ├── multiplication_sparse_ket.py ├── multiplication_sparse_sparse.py ├── ptrace_operator.py ├── ptrace_state.py ├── qfunc_operator.py ├── qfunc_state.py ├── timeevolution_master_cavity.py ├── timeevolution_master_jaynescummings.py ├── timeevolution_master_particle.py ├── timeevolution_master_timedependent_cavity.py ├── timeevolution_master_timedependent_cavity_cython.py ├── timeevolution_master_timedependent_jaynescummings.py ├── timeevolution_master_timedependent_jaynescummings_cython.py ├── timeevolution_master_timedependent_particle.py ├── timeevolution_master_timedependent_particle_cython.py ├── timeevolution_mcwf_cavity.py ├── timeevolution_mcwf_jaynescummings.py ├── timeevolution_mcwf_particle.py ├── timeevolution_schroedinger_cavity.py ├── timeevolution_schroedinger_jaynescummings.py ├── timeevolution_schroedinger_particle.py ├── variance_operator.py ├── variance_state.py ├── wigner_operator.py └── wigner_state.py ├── benchmarks-QuantumOptics.jl ├── addition_dense_dense.jl ├── addition_dense_sparse.jl ├── addition_sparse_dense.jl ├── addition_sparse_sparse.jl ├── benchmarkutils.jl ├── coherentstate.jl ├── displace.jl ├── expect_operator.jl ├── expect_state.jl ├── multiplication_bra_dense.jl ├── multiplication_bra_sparse.jl ├── multiplication_dense_dense.jl ├── multiplication_dense_ket.jl ├── multiplication_dense_sparse.jl ├── multiplication_sparse_dense.jl ├── multiplication_sparse_ket.jl ├── multiplication_sparse_sparse.jl ├── ptrace_operator.jl ├── ptrace_state.jl ├── qfunc_operator.jl ├── qfunc_state.jl ├── timeevolution_master_cavity.jl ├── timeevolution_master_jaynescummings.jl ├── timeevolution_master_particle.jl ├── timeevolution_master_timedependent_cavity.jl ├── timeevolution_master_timedependent_jaynescummings.jl ├── timeevolution_master_timedependent_particle.jl ├── timeevolution_mcwf_cavity.jl ├── timeevolution_mcwf_jaynescummings.jl ├── timeevolution_mcwf_particle.jl ├── timeevolution_schroedinger_cavity.jl ├── timeevolution_schroedinger_jaynescummings.jl ├── timeevolution_schroedinger_particle.jl ├── timeevolution_schroedinger_particle_fft.jl ├── variance_operator.jl ├── variance_state.jl ├── wigner_operator.jl └── wigner_state.jl ├── benchmarks-QuantumOpticsToolbox ├── bench_expect_operator.m ├── bench_expect_state.m ├── bench_multiplication_dense_dense.m ├── bench_multiplication_dense_sparse.m ├── bench_multiplication_sparse_dense.m ├── bench_multiplication_sparse_sparse.m ├── bench_ptrace.m ├── bench_timeevolution_master_cavity.m ├── bench_timeevolution_master_jaynescummings.m ├── bench_timeevolution_master_particle.m ├── checkbenchmark.m ├── runall.m └── savebenchmark.m ├── checks └── .keep ├── clear.sh ├── collect_results.py ├── extract_code.py ├── hardware_specs.py ├── make.jl ├── plot_results.py ├── results-collected └── .keep ├── results └── .keep └── runall.py /.gitignore: -------------------------------------------------------------------------------- 1 | results/ 2 | results-collected/ 3 | checks/ 4 | sourcecode/ 5 | *.qo 6 | *.dat 7 | __pycache__/ 8 | *.py[cod] 9 | *$py.class 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Benchmarks for quantum-optics frameworks 2 | 3 | This repository collects a set of examples which can be used to compare different numerical quantum optics frameworks. The aim is to create implementations for the following frameworks: 4 | * Quantum Optics Toolbox (Matlab) 5 | * QuTiP (Python) 6 | * QuantumOptics.jl (Julia) 7 | * C++QED (No example implemented at the moment) 8 | 9 | 10 | ## Performing the benchmarks 11 | 12 | ### Setting up the testing environment 13 | 14 | To reduce noise use dedicated cpu core for the benchmarks. This can be done with cset: 15 | 16 | sudo cset shield -k on -c 0 17 | sudo cset shield --user=sebastian --group=users -e bash 18 | 19 | Especially for julia, one still has to set the users home directory: 20 | 21 | HOME=/home/sebastian 22 | 23 | ### Running the benchmarks 24 | 25 | Now one can either manually run benchmarks of interest by simply executing the benchmark file or alternatively use the `runall.py` script to run them all automatically. 26 | 27 | 28 | ### Export data to website 29 | 30 | After the benchmarks have been performed simply run: 31 | 32 | `julia make.jl` 33 | 34 | 35 | ## More information to this repository 36 | 37 | ### The benchmark files 38 | 39 | Every single benchmark file has more or less the same structure. A `setup` function that is used to create objects that is needed to perform the actual benchmark. The execution time of this code is not measured. The benchmark function which is called repeatedly with the previously calculated objects. And code needed to configure and perform the benchmark and check that the output is correct. Depending on each example, the time is measured that it takes to evaluate a function a certain number of times. This process is repeated a few times and the minimal time is used as benchmark time. 40 | 41 | ### Structure of the repository 42 | 43 | * `benchmarks-{framework}`: where the benchmark files are. 44 | * `results`: The results of the benchmarking is stored here as json files. 45 | * `checks`: The output generated from QuantumOptics.jl is stored here and later on compared to QuTiP's output to make sure that the examples calculate the same things. At the moment the toolbox results are not checked. 46 | * `results-collected`: All benchmarking results for each example are stored together in one json file. 47 | * `sourcecode`: The source code of the different implementations of all examples is extracted and stripped from all boilerplate code. This makes it easy to present on the website what exactly was tested. 48 | 49 | ### Helper scripts 50 | 51 | * `runall.py`: Benchmarks can be performed manually by executing the corresponding benchmark file or run automatically with the help of this script. 52 | * `collect_results.py`: Collects the benchmarking results from the `results` directory, collects all benchmarks belonging to the same example into one file and writes the output as json into the `results-collected` directory. 53 | * `extract_code.py`: Extracts the important benchmark code from all implementations and stores them in the `sourcecode` folder. Each file is executed to make sure that it really works. 54 | * `hardware_specs.py`: Collects information about hardware and used software and stores it in the results directory. 55 | * `plot_results-py`: Uses matplotlib to visualize the benchmark results stored in `results-collected`. 56 | * `make.jl`: Runs `collect_results.py`, `extract_code.py`, `hardware_specs.py` and copies all files of interest into the correct website directories in `../QuantumOptics.jl-website`. 57 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qojulia/QuantumOptics.jl-benchmarks/c3e7a1fdb60457fd21508cf8b04598420cc9d548/benchmarks-QuTiP/__init__.py -------------------------------------------------------------------------------- /benchmarks-QuTiP/addition_dense_dense.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import benchmarkutils 3 | 4 | name = "addition_dense_dense" 5 | 6 | samples = 2 7 | evals = 5 8 | cutoffs = range(50, 801, 50) 9 | 10 | 11 | def setup(N): 12 | op1 = np.random.rand(N, N) * 0.2j 13 | op2 = np.random.rand(N, N) * 0.1j 14 | return op1, op2 15 | 16 | 17 | def f(op1, op2): 18 | return op1 + op2 19 | 20 | 21 | print("Benchmarking:", name) 22 | print("Cutoff: ", end="", flush=True) 23 | results = [] 24 | for N in cutoffs: 25 | print(N, "", end="", flush=True) 26 | op1, op2 = setup(N) 27 | t = benchmarkutils.run_benchmark(f, op1, op2, samples=samples, evals=evals) 28 | results.append({"N": N, "t": t}) 29 | print() 30 | 31 | benchmarkutils.save(name, results) 32 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/addition_dense_sparse.py: -------------------------------------------------------------------------------- 1 | import scipy.sparse as sp 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | basename = "addition_dense_sparse" 6 | 7 | samples = 2 8 | evals = 5 9 | cutoffs = range(50, 801, 50) 10 | S = [0.1, 0.01, 0.001] 11 | Nrand = 5 12 | 13 | 14 | def setup(N, s): 15 | op1 = np.random.rand(N, N) * 0.2j 16 | op2 = sp.rand(N, N, s, dtype=float) * 0.1j 17 | return op1, op2 18 | 19 | 20 | def f(op1, op2): 21 | return op1 + op2 22 | 23 | 24 | for s in S: 25 | name = basename + "_" + str(s).replace(".", "") 26 | print("Benchmarking:", name) 27 | print("Cutoff: ", end="", flush=True) 28 | results = [] 29 | for N in cutoffs: 30 | print(N, "", end="", flush=True) 31 | T = 0. 32 | for i in range(Nrand): 33 | op1, op2 = setup(N, s) 34 | T += benchmarkutils.run_benchmark(f, op1, op2, 35 | samples=samples, evals=evals) 36 | results.append({"N": N, "t": T / Nrand}) 37 | print() 38 | benchmarkutils.save(name, results) 39 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/addition_sparse_dense.py: -------------------------------------------------------------------------------- 1 | import scipy.sparse as sp 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | basename = "addition_sparse_dense" 6 | 7 | samples = 2 8 | evals = 5 9 | cutoffs = range(50, 801, 50) 10 | S = [0.1, 0.01, 0.001] 11 | Nrand = 5 12 | 13 | 14 | def setup(N, s): 15 | op1 = sp.rand(N, N, s, dtype=float) * 0.2j 16 | op2 = np.random.rand(N, N) * 0.1j 17 | return op1, op2 18 | 19 | 20 | def f(op1, op2): 21 | return op1 + op2 22 | 23 | 24 | for s in S: 25 | name = basename + "_" + str(s).replace(".", "") 26 | print("Benchmarking:", name) 27 | print("Cutoff: ", end="", flush=True) 28 | results = [] 29 | for N in cutoffs: 30 | print(N, "", end="", flush=True) 31 | T = 0. 32 | for i in range(Nrand): 33 | op1, op2 = setup(N, s) 34 | T += benchmarkutils.run_benchmark(f, op1, op2, 35 | samples=samples, evals=evals) 36 | results.append({"N": N, "t": T / Nrand}) 37 | print() 38 | benchmarkutils.save(name, results) 39 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/addition_sparse_sparse.py: -------------------------------------------------------------------------------- 1 | import scipy.sparse as sp 2 | import benchmarkutils 3 | 4 | basename = "addition_sparse_sparse" 5 | 6 | samples = 2 7 | evals = 5 8 | cutoffs = range(50, 801, 50) 9 | S = [0.1, 0.01, 0.001] 10 | Nrand = 5 11 | 12 | 13 | def setup(N, s): 14 | op1 = sp.rand(N, N, s, dtype=float) * 0.2j 15 | op2 = sp.rand(N, N, s, dtype=float) * 0.1j 16 | return op1, op2 17 | 18 | 19 | def f(op1, op2): 20 | return op1 + op2 21 | 22 | 23 | for s in S: 24 | name = basename + "_" + str(s).replace(".", "") 25 | print("Benchmarking:", name) 26 | print("Cutoff: ", end="", flush=True) 27 | results = [] 28 | for N in cutoffs: 29 | print(N, "", end="", flush=True) 30 | T = 0. 31 | for i in range(Nrand): 32 | op1, op2 = setup(N, s) 33 | T += benchmarkutils.run_benchmark(f, op1, op2, 34 | samples=samples, evals=evals) 35 | results.append({"N": N, "t": T / Nrand}) 36 | print() 37 | benchmarkutils.save(name, results) 38 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/benchmarkutils.py: -------------------------------------------------------------------------------- 1 | import timeit 2 | import json 3 | import qutip 4 | import numpy as np 5 | 6 | benchmark_directory = "benchmarks-QuTiP" 7 | commitID = qutip.version.version 8 | result_path = "../results/results-QuTiP-{}-{}.json" 9 | 10 | def examplename(name): 11 | if name.endswith("]"): 12 | return name.rsplit("[", 1)[0] 13 | else: 14 | return name 15 | 16 | 17 | def run_benchmark(f, *args, samples=5, evals=1): 18 | D = {"f": f, "args": args} 19 | t = timeit.repeat("f(*args)", globals=D, number=evals, repeat=samples) 20 | return min(t)/evals 21 | 22 | 23 | def check(name, D, eps=1e-5): 24 | f = open("../checks/" + examplename(name) + ".json") 25 | data = json.load(f) 26 | for (N, result) in D.items(): 27 | r = data[str(N)] 28 | if np.isnan(result) or abs(result-r)/abs(r) > eps: 29 | print("Warning: Result may be incorrect in", name, ": ", result, "<->", r) 30 | 31 | 32 | def save(name, results): 33 | f = open(result_path.format(commitID, name), "w") 34 | json.dump(results, f) 35 | f.close() 36 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/coherentstate.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "coherentstate" 6 | 7 | samples = 5 8 | evals = 100 9 | cutoffs = range(50, 501, 50) 10 | 11 | def setup(N): 12 | alpha = np.log(N) 13 | return alpha 14 | 15 | def f(N, alpha): 16 | return qt.coherent(N, alpha, method="analytic") 17 | 18 | print("Benchmarking:", name) 19 | print("Cutoff: ", end="", flush=True) 20 | checks = {} 21 | results = [] 22 | for N in cutoffs: 23 | print(N, "", end="", flush=True) 24 | alpha = setup(N) 25 | checks[N] = qt.expect(qt.destroy(N), f(N, alpha)) 26 | t = benchmarkutils.run_benchmark(f, N, alpha, samples=samples, evals=evals) 27 | results.append({"N": N, "t": t}) 28 | print() 29 | 30 | benchmarkutils.check(name, checks, 0.05) 31 | benchmarkutils.save(name, results) 32 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/displace.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "displace" 6 | 7 | samples = 3 8 | evals = 10 9 | cutoffs = range(10, 151, 10) 10 | 11 | def setup(N): 12 | alpha = np.log(N) 13 | return alpha 14 | 15 | def f(N, alpha): 16 | return qt.displace(N, alpha) 17 | 18 | print("Benchmarking:", name) 19 | print("Cutoff: ", end="", flush=True) 20 | checks = {} 21 | results = [] 22 | for N in cutoffs: 23 | print(N, "", end="", flush=True) 24 | alpha = setup(N) 25 | checks[N] = qt.expect(qt.destroy(N), f(N, alpha)) 26 | t = benchmarkutils.run_benchmark(f, N, alpha, samples=samples, evals=evals) 27 | results.append({"N": N, "t": t}) 28 | print() 29 | 30 | benchmarkutils.check(name, checks, 0.05) 31 | benchmarkutils.save(name, results) 32 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/expect_operator.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "expect_operator" 6 | 7 | samples = 5 8 | evals = 100 9 | cutoffs = range(100, 2501, 100) 10 | 11 | def setup(N): 12 | op = (qt.destroy(N) + qt.create(N)) 13 | psi = qt.Qobj(np.ones(N, complex)/(N**(1/2))) 14 | rho = psi*psi.dag() 15 | return op, rho 16 | 17 | def f(op, rho): 18 | return qt.expect(op, rho) 19 | 20 | print("Benchmarking:", name) 21 | print("Cutoff: ", end="", flush=True) 22 | checks = {} 23 | results = [] 24 | for N in cutoffs: 25 | print(N, "", end="", flush=True) 26 | op, rho = setup(N) 27 | checks[N] = f(op, rho) 28 | t = benchmarkutils.run_benchmark(f, op, rho, samples=samples, evals=evals) 29 | results.append({"N": N, "t": t}) 30 | print() 31 | 32 | benchmarkutils.check(name, checks) 33 | benchmarkutils.save(name, results) 34 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/expect_state.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "expect_state" 6 | 7 | samples = 5 8 | evals = 100 9 | cutoffs = range(5000, 150001, 5000) 10 | 11 | def setup(N): 12 | op = (qt.destroy(N) + qt.create(N)) 13 | psi = qt.Qobj(np.ones(N, complex)/(N**(1/2))) 14 | return op, psi 15 | 16 | def f(op, psi): 17 | return qt.expect(op, psi) 18 | 19 | print("Benchmarking:", name) 20 | print("Cutoff: ", end="", flush=True) 21 | checks = {} 22 | results = [] 23 | for N in cutoffs: 24 | print(N, "", end="", flush=True) 25 | op, psi = setup(N) 26 | checks[N] = f(op, psi) 27 | t = benchmarkutils.run_benchmark(f, op, psi, samples=samples, evals=evals) 28 | results.append({"N": N, "t": t}) 29 | print() 30 | 31 | benchmarkutils.check(name, checks) 32 | benchmarkutils.save(name, results) 33 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/multiplication_bra_dense.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import benchmarkutils 3 | 4 | name = "multiplication_bra_dense" 5 | 6 | samples = 2 7 | evals = 5 8 | cutoffs = range(50, 501, 50) 9 | 10 | 11 | def setup(N): 12 | op1 = qt.rand_dm(N, N) * 0.2j 13 | psi = qt.rand_ket(N).dag().full().ravel() 14 | return op1, psi 15 | 16 | 17 | def f(op1, psi): 18 | return psi * op1 19 | 20 | 21 | print("Benchmarking:", name) 22 | print("Cutoff: ", end="", flush=True) 23 | results = [] 24 | for N in cutoffs: 25 | print(N, "", end="", flush=True) 26 | op1, psi = setup(N) 27 | t = benchmarkutils.run_benchmark(f, op1, psi, 28 | samples=samples, evals=evals) 29 | results.append({"N": N, "t": t}) 30 | print() 31 | benchmarkutils.save(name, results) 32 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/multiplication_bra_sparse.py: -------------------------------------------------------------------------------- 1 | import scipy.sparse as sp 2 | import qutip as qt 3 | import benchmarkutils 4 | 5 | basename = "multiplication_bra_sparse" 6 | 7 | samples = 2 8 | evals = 5 9 | cutoffs = range(100, 1001, 100) 10 | S = [0.1, 0.01, 0.001] 11 | Nrand = 5 12 | 13 | 14 | def setup(N, s): 15 | data = sp.rand(N, N, s, dtype=float) * 0.2j 16 | op1 = qt.Qobj(data) 17 | psi = qt.rand_ket(N).dag().full().ravel() 18 | return op1, psi 19 | 20 | 21 | def f(op1, psi): 22 | return psi * op1 23 | 24 | 25 | for s in S: 26 | name = basename + "_" + str(s).replace(".", "") 27 | print("Benchmarking:", name) 28 | print("Cutoff: ", end="", flush=True) 29 | results = [] 30 | for N in cutoffs: 31 | print(N, "", end="", flush=True) 32 | T = 0. 33 | for i in range(Nrand): 34 | op1, psi = setup(N, s) 35 | T += benchmarkutils.run_benchmark(f, op1, psi, 36 | samples=samples, evals=evals) 37 | results.append({"N": N, "t": T / Nrand}) 38 | print() 39 | benchmarkutils.save(name, results) 40 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/multiplication_dense_dense.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import benchmarkutils 3 | 4 | name = "multiplication_dense_dense" 5 | 6 | samples = 2 7 | evals = 5 8 | cutoffs = range(50, 601, 50) 9 | 10 | 11 | def setup(N): 12 | op1 = np.random.rand(N, N) * 0.2j 13 | op2 = np.random.rand(N, N) * 0.1j 14 | return op1, op2 15 | 16 | 17 | def f(op1, op2): 18 | return op1 * op2 19 | 20 | 21 | print("Benchmarking:", name) 22 | print("Cutoff: ", end="", flush=True) 23 | results = [] 24 | for N in cutoffs: 25 | print(N, "", end="", flush=True) 26 | op1, op2 = setup(N) 27 | t = benchmarkutils.run_benchmark(f, op1, op2, samples=samples, evals=evals) 28 | results.append({"N": N, "t": t}) 29 | print() 30 | 31 | benchmarkutils.save(name, results) 32 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/multiplication_dense_ket.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import benchmarkutils 3 | 4 | name = "multiplication_dense_ket" 5 | 6 | samples = 2 7 | evals = 5 8 | cutoffs = range(50, 501, 50) 9 | 10 | 11 | def setup(N): 12 | op1 = qt.rand_dm(N, N) * 0.2j 13 | psi = qt.rand_ket(N).full().ravel() 14 | return op1, psi 15 | 16 | 17 | def f(op1, psi): 18 | return op1 * psi 19 | 20 | 21 | print("Benchmarking:", name) 22 | print("Cutoff: ", end="", flush=True) 23 | results = [] 24 | for N in cutoffs: 25 | print(N, "", end="", flush=True) 26 | op1, psi = setup(N) 27 | t = benchmarkutils.run_benchmark(f, op1, psi, 28 | samples=samples, evals=evals) 29 | results.append({"N": N, "t": t}) 30 | print() 31 | benchmarkutils.save(name, results) 32 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/multiplication_dense_sparse.py: -------------------------------------------------------------------------------- 1 | import scipy.sparse as sp 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | basename = "multiplication_dense_sparse" 6 | 7 | samples = 2 8 | evals = 5 9 | cutoffs = range(50, 1001, 50) 10 | S = [0.1, 0.01, 0.001] 11 | Nrand = 5 12 | 13 | 14 | def setup(N, s): 15 | op1 = np.random.rand(N, N) * 0.2j 16 | op2 = sp.rand(N, N, s, dtype=float) * 0.1j 17 | return op1, op2 18 | 19 | 20 | def f(op1, op2): 21 | return op1 * op2 22 | 23 | 24 | for s in S: 25 | name = basename + "_" + str(s).replace(".", "") 26 | print("Benchmarking:", name) 27 | print("Cutoff: ", end="", flush=True) 28 | results = [] 29 | for N in cutoffs: 30 | print(N, "", end="", flush=True) 31 | T = 0. 32 | for i in range(Nrand): 33 | op1, op2 = setup(N, s) 34 | T += benchmarkutils.run_benchmark(f, op1, op2, 35 | samples=samples, evals=evals) 36 | results.append({"N": N, "t": T / Nrand}) 37 | print() 38 | benchmarkutils.save(name, results) 39 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/multiplication_sparse_dense.py: -------------------------------------------------------------------------------- 1 | import scipy.sparse as sp 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | basename = "multiplication_sparse_dense" 6 | 7 | samples = 2 8 | evals = 5 9 | cutoffs = range(50, 1001, 50) 10 | S = [0.1, 0.01, 0.001] 11 | Nrand = 5 12 | 13 | 14 | def setup(N, s): 15 | op1 = sp.rand(N, N, s, dtype=float) * 0.2j 16 | op2 = np.random.rand(N, N) * 0.1j 17 | return op1, op2 18 | 19 | 20 | def f(op1, op2): 21 | return op1 * op2 22 | 23 | 24 | for s in S: 25 | name = basename + "_" + str(s).replace(".", "") 26 | print("Benchmarking:", name) 27 | print("Cutoff: ", end="", flush=True) 28 | results = [] 29 | for N in cutoffs: 30 | print(N, "", end="", flush=True) 31 | T = 0. 32 | for i in range(Nrand): 33 | op1, op2 = setup(N, s) 34 | T += benchmarkutils.run_benchmark(f, op1, op2, 35 | samples=samples, evals=evals) 36 | results.append({"N": N, "t": T / Nrand}) 37 | print() 38 | benchmarkutils.save(name, results) 39 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/multiplication_sparse_ket.py: -------------------------------------------------------------------------------- 1 | import scipy.sparse as sp 2 | import qutip as qt 3 | import benchmarkutils 4 | 5 | basename = "multiplication_sparse_ket" 6 | 7 | samples = 2 8 | evals = 5 9 | cutoffs = range(100, 1001, 100) 10 | S = [0.1, 0.01, 0.001] 11 | Nrand = 5 12 | 13 | 14 | def setup(N, s): 15 | data = sp.rand(N, N, s, dtype=float) * 0.2j 16 | op1 = qt.Qobj(data) 17 | psi = qt.rand_ket(N).full().ravel() 18 | return op1, psi 19 | 20 | 21 | def f(op1, psi): 22 | return op1 * psi 23 | 24 | 25 | for s in S: 26 | name = basename + "_" + str(s).replace(".", "") 27 | print("Benchmarking:", name) 28 | print("Cutoff: ", end="", flush=True) 29 | results = [] 30 | for N in cutoffs: 31 | print(N, "", end="", flush=True) 32 | T = 0. 33 | for i in range(Nrand): 34 | op1, psi = setup(N, s) 35 | T += benchmarkutils.run_benchmark(f, op1, psi, 36 | samples=samples, evals=evals) 37 | results.append({"N": N, "t": T / Nrand}) 38 | print() 39 | benchmarkutils.save(name, results) 40 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/multiplication_sparse_sparse.py: -------------------------------------------------------------------------------- 1 | import scipy.sparse as sp 2 | import benchmarkutils 3 | 4 | basename = "multiplication_sparse_sparse" 5 | 6 | samples = 2 7 | evals = 5 8 | cutoffs = range(50, 1001, 50) 9 | S = [0.1, 0.01, 0.001] 10 | Nrand = 5 11 | 12 | 13 | def setup(N, s): 14 | op1 = sp.rand(N, N, s, dtype=float) * 0.2j 15 | op2 = sp.rand(N, N, s, dtype=float) * 0.1j 16 | return op1, op2 17 | 18 | 19 | def f(op1, op2): 20 | return op1 * op2 21 | 22 | 23 | for s in S: 24 | name = basename + "_" + str(s).replace(".", "") 25 | print("Benchmarking:", name) 26 | print("Cutoff: ", end="", flush=True) 27 | results = [] 28 | for N in cutoffs: 29 | print(N, "", end="", flush=True) 30 | T = 0. 31 | for i in range(Nrand): 32 | op1, op2 = setup(N, s) 33 | T += benchmarkutils.run_benchmark(f, op1, op2, 34 | samples=samples, evals=evals) 35 | results.append({"N": N, "t": T / Nrand}) 36 | print() 37 | benchmarkutils.save(name, results) 38 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/ptrace_operator.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "ptrace_operator" 6 | 7 | samples = 5 8 | evals = 100 9 | cutoffs = range(2, 16) 10 | 11 | 12 | def setup(N): 13 | def create_suboperator(c0, alpha, N): 14 | x = np.linspace(0., 1., N**2) 15 | data = (c0 + alpha * x).reshape(N, N) 16 | return qt.Qobj(data) 17 | op1 = create_suboperator(1, 0.2, N) 18 | op2 = create_suboperator(-2, 0.3, N) 19 | op3 = create_suboperator(3, 0.4, 2) 20 | op4 = create_suboperator(4, 0.5, 2) 21 | op = qt.tensor(op1, op2, op3, op4) 22 | return op 23 | 24 | 25 | def f(op): 26 | return qt.ptrace(op, [0, 3]) 27 | 28 | 29 | print("Benchmarking:", name) 30 | print("Cutoff: ", end="", flush=True) 31 | checks = {} 32 | results = [] 33 | for N in cutoffs: 34 | print(N, "", end="", flush=True) 35 | op = setup(N) 36 | checks[N] = abs(f(op).full()).sum() 37 | t = benchmarkutils.run_benchmark(f, op, samples=samples, evals=evals) 38 | results.append({"N": 4*N**2, "t": t}) 39 | print() 40 | 41 | benchmarkutils.check(name, checks) 42 | benchmarkutils.save(name, results) 43 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/ptrace_state.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "ptrace_state" 6 | 7 | samples = 5 8 | evals = 100 9 | cutoffs = range(2, 16) 10 | 11 | 12 | def setup(N): 13 | def create_substate(c0, alpha, N): 14 | x = np.linspace(0., 1., N) 15 | data = (c0 + alpha * x).conj() 16 | return qt.Qobj(data) 17 | psi1 = create_substate(1, 0.2, N) 18 | psi2 = create_substate(-2, 0.3, N) 19 | psi3 = create_substate(3, 0.4, 2) 20 | psi4 = create_substate(4, 0.5, 2) 21 | psi = qt.tensor(psi1, psi2, psi3, psi4) 22 | return psi 23 | 24 | 25 | def f(psi): 26 | return qt.ptrace(psi, [0, 3]) 27 | 28 | 29 | print("Benchmarking:", name) 30 | print("Cutoff: ", end="", flush=True) 31 | checks = {} 32 | results = [] 33 | for N in cutoffs: 34 | print(N, "", end="", flush=True) 35 | psi = setup(N) 36 | checks[N] = abs(f(psi).full()).sum() 37 | t = benchmarkutils.run_benchmark(f, psi, samples=samples, evals=evals) 38 | results.append({"N": 4 * N**2, "t": t}) 39 | print() 40 | 41 | benchmarkutils.check(name, checks) 42 | benchmarkutils.save(name, results) 43 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/qfunc_operator.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "qfunc_operator" 6 | 7 | samples = 3 8 | evals = 5 9 | cutoffs = range(10, 101, 10) 10 | 11 | def setup(N): 12 | alpha = 0.7 13 | xvec = np.linspace(-50, 50, 101) 14 | yvec = np.linspace(-50, 50, 101) 15 | state = qt.coherent(N, alpha) 16 | op = state*state.dag() 17 | return op, xvec, yvec 18 | 19 | def f(state, xvec, yvec): 20 | return qt.qfunc(state, xvec, yvec) 21 | 22 | print("Benchmarking:", name) 23 | print("Cutoff: ", end="", flush=True) 24 | checks = {} 25 | results = [] 26 | for N in cutoffs: 27 | print(N, "", end="", flush=True) 28 | op, xvec, yvec = setup(N) 29 | alpha_check = 0.6 + 0.1j 30 | checks[N] = f(op, [alpha_check.real], [alpha_check.imag])[0, 0] 31 | t = benchmarkutils.run_benchmark(f, op, xvec, yvec, samples=samples, evals=evals) 32 | results.append({"N": N, "t": t}) 33 | print() 34 | 35 | benchmarkutils.check(name, checks) 36 | benchmarkutils.save(name, results) 37 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/qfunc_state.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "qfunc_state" 6 | 7 | samples = 3 8 | evals = 5 9 | cutoffs = range(10, 101, 10) 10 | 11 | def setup(N): 12 | alpha = 0.7 13 | xvec = np.linspace(-50, 50, 100) 14 | yvec = np.linspace(-50, 50, 100) 15 | state = qt.coherent(N, alpha) 16 | return state, xvec, yvec 17 | 18 | def f(state, xvec, yvec): 19 | return qt.qfunc(state, xvec, yvec) 20 | 21 | print("Benchmarking:", name) 22 | print("Cutoff: ", end="", flush=True) 23 | checks = {} 24 | results = [] 25 | for N in cutoffs: 26 | print(N, "", end="", flush=True) 27 | state, xvec, yvec = setup(N) 28 | alpha_check = 0.6 + 0.1j 29 | checks[N] = f(state, [alpha_check.real], [alpha_check.imag])[0, 0] 30 | t = benchmarkutils.run_benchmark(f, state, xvec, yvec, samples=samples, evals=evals) 31 | results.append({"N": N, "t": t}) 32 | print() 33 | 34 | benchmarkutils.check(name, checks) 35 | benchmarkutils.save(name, results) 36 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_master_cavity.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_master_cavity" 6 | 7 | samples = 3 8 | evals = 3 9 | cutoffs = range(10, 151, 10) 10 | 11 | 12 | def setup(N): 13 | options = qt.Options() 14 | options.atol = 1e-8 15 | options.rtol = 1e-6 16 | return options 17 | 18 | 19 | def f(N, options): 20 | kappa = 1. 21 | eta = 1.5 22 | wc = 1.8 23 | wl = 2. 24 | delta_c = wl - wc 25 | alpha0 = 0.3 - 0.5j 26 | tspan = np.linspace(0, 10, 11) 27 | 28 | a = qt.destroy(N) 29 | at = qt.create(N) 30 | n = at * a 31 | 32 | H = delta_c*n + eta*(a + at) 33 | J = [np.sqrt(kappa) * a] 34 | 35 | psi0 = qt.coherent(N, alpha0) 36 | exp_n = qt.mesolve(H, psi0, tspan, J, [n], options=options).expect[0] 37 | return np.real(exp_n) 38 | 39 | 40 | print("Benchmarking:", name) 41 | print("Cutoff: ", end="", flush=True) 42 | checks = {} 43 | results = [] 44 | for N in cutoffs: 45 | print(N, "", end="", flush=True) 46 | options = setup(N) 47 | checks[N] = sum(f(N, options)) 48 | t = benchmarkutils.run_benchmark(f, N, options, samples=samples, evals=evals) 49 | results.append({"N": N, "t": t}) 50 | print() 51 | 52 | benchmarkutils.check(name, checks) 53 | benchmarkutils.save(name, results) 54 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_master_jaynescummings.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_master_jaynescummings" 6 | 7 | samples = 3 8 | evals = 3 9 | cutoffs = range(5, 81, 5) 10 | 11 | 12 | def setup(N): 13 | options = qt.Options() 14 | options.atol = 1e-8 15 | options.rtol = 1e-6 16 | return options 17 | 18 | 19 | def f(N, options): 20 | wa = 1 21 | wc = 1 22 | g = 2 23 | kappa = 0.5 24 | gamma = 0.1 25 | n_th = 0.75 26 | tspan = np.linspace(0, 10, 11) 27 | 28 | Ia = qt.qeye(2) 29 | Ic = qt.qeye(N) 30 | 31 | a = qt.destroy(N) 32 | at = qt.create(N) 33 | n = at * a 34 | 35 | sm = qt.sigmam() 36 | sp = qt.sigmap() 37 | sz = qt.sigmaz() 38 | 39 | H = wc*qt.tensor(n, Ia) + qt.tensor(Ic, wa/2.*sz) + g*(qt.tensor(at, sm) + qt.tensor(a, sp)) 40 | c_ops = [ 41 | qt.tensor(np.sqrt(kappa*(1+n_th)) * a, Ia), 42 | qt.tensor(np.sqrt(kappa*n_th) * at, Ia), 43 | qt.tensor(Ic, np.sqrt(gamma) * sm), 44 | ] 45 | 46 | psi0 = qt.tensor(qt.fock(N, 0), (qt.basis(2, 0) + qt.basis(2, 1)).unit()) 47 | exp_n = qt.mesolve(H, psi0, tspan, c_ops, [qt.tensor(n, Ia)], options=options).expect[0] 48 | return exp_n 49 | 50 | 51 | print("Benchmarking:", name) 52 | print("Cutoff: ", end="", flush=True) 53 | checks = {} 54 | results = [] 55 | for N in cutoffs: 56 | print(N, "", end="", flush=True) 57 | options = setup(N) 58 | checks[N] = sum(f(N, options)) 59 | t = benchmarkutils.run_benchmark(f, N, options, samples=samples, evals=evals) 60 | results.append({"N": 2*N, "t": t}) 61 | print() 62 | 63 | benchmarkutils.check(name, checks) 64 | benchmarkutils.save(name, results) 65 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_master_particle.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_master_particle" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = range(5, 41, 5) 10 | 11 | 12 | def setup(N): 13 | xmin = -5 14 | xmax = 5 15 | x0 = 0.3 16 | p0 = -0.2 17 | sigma0 = 1 18 | dx = (xmax - xmin) / N 19 | pmin = -np.pi / dx 20 | pmax = np.pi / dx 21 | dp = (pmax - pmin) / N 22 | 23 | samplepoints_x = np.linspace(xmin, xmax, N, endpoint=False) 24 | samplepoints_p = np.linspace(pmin, pmax, N, endpoint=False) 25 | 26 | x = qt.Qobj(np.diag(samplepoints_x)) 27 | row0 = [sum([p*np.exp(-1j*p*dxji) for p in samplepoints_p])*dp*dx/(2*np.pi) for dxji in samplepoints_x - xmin] 28 | row0 = np.array(row0) 29 | col0 = row0.conj() 30 | 31 | a = np.zeros([N, N], dtype=complex) 32 | for i in range(N): 33 | a[i, i:] = row0[:N - i] 34 | a[i:, i] = col0[:N - i] 35 | p = qt.Qobj(a) 36 | 37 | H = p**2 + 2 * x**2 38 | 39 | def gaussianstate(x0, p0, sigma0): 40 | alpha = 1./(np.pi**(1/4)*np.sqrt(sigma0))*np.sqrt(dx) 41 | data = alpha*np.exp(1j*p0*(samplepoints_x-x0/2) - (samplepoints_x-x0)**2/(2*sigma0**2)) 42 | return qt.Qobj(data) 43 | 44 | psi0 = gaussianstate(x0, p0, sigma0) 45 | J = [x + 1j * p] 46 | 47 | options = qt.Options() 48 | options.nsteps = 1000000 49 | options.atol = 1e-8 50 | options.rtol = 1e-6 51 | 52 | return psi0, H, x, J, options 53 | 54 | 55 | def f(psi0, H, x, J, options): 56 | tlist = np.linspace(0, 10, 11) 57 | exp_x = qt.mesolve(H, psi0, tlist, J, [x], options=options).expect[0] 58 | return exp_x 59 | 60 | 61 | print("Benchmarking:", name) 62 | print("Cutoff: ", end="", flush=True) 63 | checks = {} 64 | results = [] 65 | for N in cutoffs: 66 | print(N, "", end="", flush=True) 67 | psi0, H, x, J, options = setup(N) 68 | checks[N] = sum(f(psi0, H, x, J, options)) 69 | t = benchmarkutils.run_benchmark(f, psi0, H, x, J, options, samples=samples, evals=evals) 70 | results.append({"N": N, "t": t}) 71 | print() 72 | 73 | benchmarkutils.check(name, checks, 1e-4) 74 | benchmarkutils.save(name, results) 75 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_master_timedependent_cavity.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_master_timedependent_cavity" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = range(10, 131, 10) 10 | 11 | 12 | def setup(N): 13 | options = qt.Options() 14 | options.nsteps = 1000000 15 | options.atol = 1e-8 16 | options.rtol = 1e-6 17 | return options 18 | 19 | 20 | def f(N, options): 21 | kappa = 1. 22 | eta = 1.5 23 | wc = 1.8 24 | wl = 2. 25 | # delta_c = wl - wc 26 | alpha0 = 0.3 - 0.5j 27 | tspan = np.linspace(0, 10, 11) 28 | 29 | a = qt.destroy(N) 30 | at = qt.create(N) 31 | n = qt.num(N) 32 | 33 | J = [np.sqrt(kappa) * a] 34 | psi0 = qt.coherent(N, alpha0) 35 | H = [wc * n, 36 | [eta * a, lambda t, args: np.exp(1j * wl * t)], 37 | [eta * at, lambda t, args: np.exp(-1j * wl * t)]] 38 | alpha_t = qt.mesolve(H, psi0, tspan, J, [a], options=options).expect[0] 39 | return np.real(alpha_t) 40 | 41 | 42 | print("Benchmarking:", name) 43 | print("Cutoff: ", end="", flush=True) 44 | checks = {} 45 | results = [] 46 | for N in cutoffs: 47 | print(N, "", end="", flush=True) 48 | options = setup(N) 49 | checks[N] = sum(f(N, options)) 50 | t = benchmarkutils.run_benchmark(f, N, options, samples=samples, evals=evals) 51 | results.append({"N": N, "t": t}) 52 | print() 53 | 54 | benchmarkutils.check(name, checks, 1e-4) 55 | benchmarkutils.save(name, results) 56 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_master_timedependent_cavity_cython.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_master_timedependent_cavity[cython]" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = range(10, 151, 10) 10 | 11 | 12 | def setup(N): 13 | options = qt.Options() 14 | options.nsteps = 1000000 15 | options.atol = 1e-8 16 | options.rtol = 1e-6 17 | options.rhs_reuse = True 18 | return options 19 | 20 | 21 | def f(N, options): 22 | kappa = 1. 23 | eta = 1.5 24 | wc = 1.8 25 | wl = 2. 26 | # delta_c = wl - wc 27 | alpha0 = 0.3 - 0.5j 28 | tspan = np.linspace(0, 10, 11) 29 | 30 | a = qt.destroy(N) 31 | at = qt.create(N) 32 | n = qt.num(N) 33 | 34 | J = [np.sqrt(kappa) * a] 35 | psi0 = qt.coherent(N, alpha0) 36 | H = [wc * n, 37 | [eta * a, 'exp(1j*{wl}*t)'.format(wl=wl)], 38 | [eta * at, 'exp(-1j*{wl}*t)'.format(wl=wl)]] 39 | alpha_t = qt.mesolve(H, psi0, tspan, J, [a], options=options).expect[0] 40 | return np.real(alpha_t) 41 | 42 | 43 | print("Benchmarking:", name) 44 | print("Cutoff: ", end="", flush=True) 45 | checks = {} 46 | results = [] 47 | for N in cutoffs: 48 | print(N, "", end="", flush=True) 49 | options = setup(N) 50 | checks[N] = sum(f(N, options)) 51 | t = benchmarkutils.run_benchmark(f, N, options, samples=samples, evals=evals) 52 | results.append({"N": N, "t": t}) 53 | print() 54 | 55 | benchmarkutils.check(name, checks, 1e-4) 56 | benchmarkutils.save(name, results) 57 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_master_timedependent_jaynescummings.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_master_timedependent_jaynescummings" 6 | 7 | samples = 3 8 | evals = 6 9 | cutoffs = range(5, 81, 5) 10 | 11 | 12 | def setup(N): 13 | options = qt.Options() 14 | options.atol = 1e-8 15 | options.rtol = 1e-6 16 | return options 17 | 18 | 19 | def f(N, options): 20 | wa = 1 21 | wc = 0.9 22 | delta = wa - wc 23 | g = 2 24 | kappa = 0.5 25 | gamma = 0.1 26 | n_th = 0.75 27 | tspan = np.linspace(0, 10, 11) 28 | 29 | Ia = qt.qeye(2) 30 | Ic = qt.qeye(N) 31 | 32 | a = qt.destroy(N) 33 | at = qt.create(N) 34 | 35 | sm = qt.sigmam() 36 | sp = qt.sigmap() 37 | 38 | # H = wc*qt.tensor(n, Ia) + qt.tensor(Ic, wa/2.*sz) + g*(qt.tensor(at, sm) + qt.tensor(a, sp)) 39 | Ha = g * qt.tensor(at, sm) 40 | Hb = g * qt.tensor(a, sp) 41 | H = [[Ha, lambda t, args: np.exp(-1j*delta*t)], 42 | [Hb, lambda t, args: np.exp(1j*delta*t)]] 43 | c_ops = [ 44 | qt.tensor(np.sqrt(kappa*(1+n_th)) * a, Ia), 45 | qt.tensor(np.sqrt(kappa*n_th) * at, Ia), 46 | qt.tensor(Ic, np.sqrt(gamma) * sm), 47 | ] 48 | 49 | psi0 = qt.tensor(qt.fock(N, 0), (qt.basis(2, 0) + qt.basis(2, 1)).unit()) 50 | exp_n = qt.mesolve(H, psi0, tspan, c_ops, [qt.tensor(a, sp)], options=options).expect[0] 51 | return np.real(exp_n) 52 | 53 | 54 | print("Benchmarking:", name) 55 | print("Cutoff: ", end="", flush=True) 56 | checks = {} 57 | results = [] 58 | for N in cutoffs: 59 | print(N, "", end="", flush=True) 60 | options = setup(N) 61 | checks[N] = sum(f(N, options)) 62 | t = benchmarkutils.run_benchmark(f, N, options, samples=samples, evals=evals) 63 | results.append({"N": 2*N, "t": t}) 64 | print() 65 | 66 | benchmarkutils.check(name, checks) 67 | benchmarkutils.save(name, results) 68 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_master_timedependent_jaynescummings_cython.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_master_timedependent_jaynescummings[cython]" 6 | 7 | samples = 3 8 | evals = 3 9 | cutoffs = range(5, 81, 5) 10 | 11 | 12 | def setup(N): 13 | options = qt.Options() 14 | options.atol = 1e-8 15 | options.rtol = 1e-6 16 | options.rhs_reuse = True 17 | return options 18 | 19 | 20 | def f(N, options): 21 | wa = 1 22 | wc = 0.9 23 | delta = wa - wc 24 | g = 2 25 | kappa = 0.5 26 | gamma = 0.1 27 | n_th = 0.75 28 | tspan = np.linspace(0, 10, 11) 29 | 30 | Ia = qt.qeye(2) 31 | Ic = qt.qeye(N) 32 | 33 | a = qt.destroy(N) 34 | at = qt.create(N) 35 | 36 | sm = qt.sigmam() 37 | sp = qt.sigmap() 38 | 39 | # H = wc*qt.tensor(n, Ia) + qt.tensor(Ic, wa/2.*sz) + g*(qt.tensor(at, sm) + qt.tensor(a, sp)) 40 | Ha = g * qt.tensor(at, sm) 41 | Hb = g * qt.tensor(a, sp) 42 | H = [[Ha, 'exp(-1j* {delta}*t)'.format(delta=delta)], 43 | [Hb, 'exp(1j*{delta}*t)'.format(delta=delta)]] 44 | c_ops = [ 45 | qt.tensor(np.sqrt(kappa*(1+n_th)) * a, Ia), 46 | qt.tensor(np.sqrt(kappa*n_th) * at, Ia), 47 | qt.tensor(Ic, np.sqrt(gamma) * sm), 48 | ] 49 | 50 | psi0 = qt.tensor(qt.fock(N, 0), (qt.basis(2, 0) + qt.basis(2, 1)).unit()) 51 | exp_asp = qt.mesolve(H, psi0, tspan, c_ops, [qt.tensor(a, sp)], options=options).expect[0] 52 | return np.real(exp_asp) 53 | 54 | 55 | print("Benchmarking:", name) 56 | print("Cutoff: ", end="", flush=True) 57 | checks = {} 58 | results = [] 59 | for N in cutoffs: 60 | print(N, "", end="", flush=True) 61 | options = setup(N) 62 | checks[N] = sum(f(N, options)) 63 | t = benchmarkutils.run_benchmark(f, N, options, samples=samples, evals=evals) 64 | results.append({"N": 2*N, "t": t}) 65 | print() 66 | 67 | benchmarkutils.check(name, checks) 68 | benchmarkutils.save(name, results) 69 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_master_timedependent_particle.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_master_timedependent_particle" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = range(5, 31, 5) 10 | 11 | 12 | def setup(N): 13 | xmin = -5 14 | xmax = 5 15 | x0 = 0.3 16 | p0 = -0.2 17 | sigma0 = 1 18 | dx = (xmax - xmin) / N 19 | pmin = -np.pi / dx 20 | pmax = np.pi / dx 21 | dp = (pmax - pmin) / N 22 | 23 | samplepoints_x = np.linspace(xmin, xmax, N, endpoint=False) 24 | samplepoints_p = np.linspace(pmin, pmax, N, endpoint=False) 25 | 26 | x = qt.Qobj(np.diag(samplepoints_x)) 27 | row0 = [sum([p*np.exp(-1j*p*dxji) for p in samplepoints_p])*dp*dx/(2*np.pi) for dxji in samplepoints_x - xmin] 28 | row0 = np.array(row0) 29 | col0 = row0.conj() 30 | 31 | a = np.zeros([N, N], dtype=complex) 32 | for i in range(N): 33 | a[i, i:] = row0[:N - i] 34 | a[i:, i] = col0[:N - i] 35 | p = qt.Qobj(a) 36 | 37 | Hkin = p**2 38 | Vx = 2 * x**2 39 | 40 | def gaussianstate(x0, p0, sigma0): 41 | alpha = 1./(np.pi**(1/4)*np.sqrt(sigma0))*np.sqrt(dx) 42 | data = alpha*np.exp(1j*p0*(samplepoints_x-x0/2) - (samplepoints_x-x0)**2/(2*sigma0**2)) 43 | return qt.Qobj(data) 44 | 45 | psi0 = gaussianstate(x0, p0, sigma0) 46 | J = [x + 1j * p] 47 | 48 | options = qt.Options() 49 | options.nsteps = 1000000 50 | options.atol = 1e-8 51 | options.rtol = 1e-6 52 | 53 | return psi0, Hkin, Vx, J, x, options 54 | 55 | 56 | def f(psi0, Hkin, Vx, J, x, options): 57 | tlist = np.linspace(0, 10, 11) 58 | H = [Hkin, 59 | [Vx, lambda t, args: 1 + np.cos(t)] 60 | ] 61 | exp_x = qt.mesolve(H, psi0, tlist, J, [x], options=options).expect[0] 62 | return exp_x 63 | 64 | 65 | print("Benchmarking:", name) 66 | print("Cutoff: ", end="", flush=True) 67 | checks = {} 68 | results = [] 69 | for N in cutoffs: 70 | print(N, "", end="", flush=True) 71 | psi0, Hkin, Vx, J, x, options = setup(N) 72 | checks[N] = sum(f(psi0, Hkin, Vx, J, x, options)) 73 | t = benchmarkutils.run_benchmark(f, psi0, Hkin, Vx, J, x, options, samples=samples, evals=evals) 74 | results.append({"N": N, "t": t}) 75 | print() 76 | 77 | benchmarkutils.check(name, checks, 1e-4) 78 | benchmarkutils.save(name, results) 79 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_master_timedependent_particle_cython.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_master_timedependent_particle[cython]" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = range(5, 41, 5) 10 | 11 | 12 | def setup(N): 13 | xmin = -5 14 | xmax = 5 15 | x0 = 0.3 16 | p0 = -0.2 17 | sigma0 = 1 18 | dx = (xmax - xmin) / N 19 | pmin = -np.pi / dx 20 | pmax = np.pi / dx 21 | dp = (pmax - pmin) / N 22 | 23 | samplepoints_x = np.linspace(xmin, xmax, N, endpoint=False) 24 | samplepoints_p = np.linspace(pmin, pmax, N, endpoint=False) 25 | 26 | x = qt.Qobj(np.diag(samplepoints_x)) 27 | row0 = [sum([p*np.exp(-1j*p*dxji) for p in samplepoints_p])*dp*dx/(2*np.pi) for dxji in samplepoints_x - xmin] 28 | row0 = np.array(row0) 29 | col0 = row0.conj() 30 | 31 | a = np.zeros([N, N], dtype=complex) 32 | for i in range(N): 33 | a[i, i:] = row0[:N - i] 34 | a[i:, i] = col0[:N - i] 35 | p = qt.Qobj(a) 36 | 37 | Hkin = p**2 38 | Vx = 2 * x**2 39 | 40 | def gaussianstate(x0, p0, sigma0): 41 | alpha = 1./(np.pi**(1/4)*np.sqrt(sigma0))*np.sqrt(dx) 42 | data = alpha*np.exp(1j*p0*(samplepoints_x-x0/2) - (samplepoints_x-x0)**2/(2*sigma0**2)) 43 | return qt.Qobj(data) 44 | 45 | psi0 = gaussianstate(x0, p0, sigma0) 46 | J = [x + 1j * p] 47 | 48 | options = qt.Options() 49 | options.nsteps = 1000000 50 | options.atol = 1e-8 51 | options.rtol = 1e-6 52 | options.rhs_reuse = True 53 | 54 | return psi0, Hkin, Vx, J, x, options 55 | 56 | 57 | def f(psi0, Hkin, Vx, J, x, options): 58 | tlist = np.linspace(0, 10, 11) 59 | H = [Hkin, 60 | [Vx, "1 + np.cos(t)"] 61 | ] 62 | exp_x = qt.mesolve(H, psi0, tlist, J, [x], options=options).expect[0] 63 | return exp_x 64 | 65 | 66 | print("Benchmarking:", name) 67 | print("Cutoff: ", end="", flush=True) 68 | checks = {} 69 | results = [] 70 | for N in cutoffs: 71 | print(N, "", end="", flush=True) 72 | psi0, Hkin, Vx, J, x, options = setup(N) 73 | checks[N] = sum(f(psi0, Hkin, Vx, J, x, options)) 74 | t = benchmarkutils.run_benchmark(f, psi0, Hkin, Vx, J, x, options, samples=samples, evals=evals) 75 | results.append({"N": N, "t": t}) 76 | print() 77 | 78 | benchmarkutils.check(name, checks, 1e-4) 79 | benchmarkutils.save(name, results) 80 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_mcwf_cavity.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_mcwf_cavity" 6 | 7 | samples = 2 8 | evals = 100 9 | cutoffs = range(50, 501, 50) 10 | 11 | 12 | def setup(N): 13 | options = qt.Options() 14 | options.atol = 1e-8 15 | options.rtol = 1e-6 16 | options.num_cpus = 1 17 | return options 18 | 19 | 20 | def f(N, options): 21 | kappa = 1. 22 | eta = 1.5 23 | wc = 1.8 24 | wl = 2. 25 | delta_c = wl - wc 26 | alpha0 = 0.3 - 0.5j 27 | tspan = np.linspace(0, 10, 11) 28 | 29 | a = qt.destroy(N) 30 | at = qt.create(N) 31 | n = at * a 32 | 33 | H = delta_c * n + eta * (a + at) 34 | J = [np.sqrt(kappa) * a] 35 | 36 | psi0 = qt.coherent(N, alpha0) 37 | exp_n = qt.mcsolve(H, psi0, tspan, J, [n], ntraj=evals, options=options).expect[0] 38 | return np.real(exp_n) 39 | 40 | 41 | print("Benchmarking:", name) 42 | print("Cutoff: ", end="", flush=True) 43 | checks = {} 44 | results = [] 45 | for N in cutoffs: 46 | print(N, "", end="", flush=True) 47 | options = setup(N) 48 | checks[N] = sum(f(N, options)) 49 | t = benchmarkutils.run_benchmark(f, N, options, samples=samples, evals=1) 50 | results.append({"N": N, "t": t / evals}) 51 | print() 52 | 53 | benchmarkutils.check(name, checks, eps=0.05) 54 | benchmarkutils.save(name, results) 55 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_mcwf_jaynescummings.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_mcwf_jaynescummings" 6 | 7 | samples = 2 8 | evals = 100 9 | cutoffs = range(50, 501, 50) 10 | 11 | 12 | def setup(N): 13 | options = qt.Options() 14 | options.atol = 1e-8 15 | options.rtol = 1e-6 16 | options.num_cpus = 1 17 | return options 18 | 19 | 20 | def f(N, options): 21 | wa = 1 22 | wc = 1 23 | g = 2 24 | kappa = 0.5 25 | gamma = 0.1 26 | n_th = 0.75 27 | tspan = np.linspace(0, 10, 11) 28 | 29 | Ia = qt.qeye(2) 30 | Ic = qt.qeye(N) 31 | 32 | a = qt.destroy(N) 33 | at = qt.create(N) 34 | n = at * a 35 | 36 | sm = qt.sigmam() 37 | sp = qt.sigmap() 38 | sz = qt.sigmaz() 39 | 40 | H = wc*qt.tensor(n, Ia) + qt.tensor(Ic, wa/2.*sz) + g*(qt.tensor(at, sm) + qt.tensor(a, sp)) 41 | c_ops = [ 42 | qt.tensor(np.sqrt(kappa*(1+n_th)) * a, Ia), 43 | qt.tensor(np.sqrt(kappa*n_th) * at, Ia), 44 | qt.tensor(Ic, np.sqrt(gamma) * sm), 45 | ] 46 | 47 | psi0 = qt.tensor(qt.fock(N, 0), (qt.basis(2, 0) + qt.basis(2, 1)).unit()) 48 | exp_n = qt.mcsolve(H, psi0, tspan, c_ops, [qt.tensor(n, Ia)], ntraj=evals, options=options).expect[0] 49 | return np.real(exp_n) 50 | 51 | 52 | print("Benchmarking:", name) 53 | print("Cutoff: ", end="", flush=True) 54 | checks = {} 55 | results = [] 56 | for N in cutoffs: 57 | print(N, "", end="", flush=True) 58 | options = setup(N) 59 | checks[N] = sum(f(N, options)) 60 | t = benchmarkutils.run_benchmark(f, N, options, samples=samples, evals=1) 61 | results.append({"N": 2*N, "t": t / evals}) 62 | print() 63 | 64 | benchmarkutils.check(name, checks, eps=0.05) 65 | benchmarkutils.save(name, results) 66 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_mcwf_particle.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_mcwf_particle" 6 | 7 | samples = 2 8 | evals = 100 9 | cutoffs = range(10, 101, 10) 10 | 11 | 12 | def setup(N): 13 | xmin = -5 14 | xmax = 5 15 | x0 = 0.3 16 | p0 = -0.2 17 | sigma0 = 1 18 | dx = (xmax - xmin) / N 19 | pmin = -np.pi / dx 20 | pmax = np.pi / dx 21 | dp = (pmax - pmin) / N 22 | 23 | samplepoints_x = np.linspace(xmin, xmax, N, endpoint=False) 24 | samplepoints_p = np.linspace(pmin, pmax, N, endpoint=False) 25 | 26 | x = qt.Qobj(np.diag(samplepoints_x)) 27 | row0 = [sum([p*np.exp(-1j*p*dxji) for p in samplepoints_p])*dp*dx/(2*np.pi) for dxji in samplepoints_x - xmin] 28 | row0 = np.array(row0) 29 | col0 = row0.conj() 30 | 31 | a = np.zeros([N, N], dtype=complex) 32 | for i in range(N): 33 | a[i, i:] = row0[:N - i] 34 | a[i:, i] = col0[:N - i] 35 | p = qt.Qobj(a) 36 | 37 | H = p**2 + 2 * x**2 38 | 39 | def gaussianstate(x0, p0, sigma0): 40 | alpha = 1./(np.pi**(1/4)*np.sqrt(sigma0))*np.sqrt(dx) 41 | data = alpha*np.exp(1j*p0*(samplepoints_x-x0/2) - (samplepoints_x-x0)**2/(2*sigma0**2)) 42 | return qt.Qobj(data) 43 | 44 | psi0 = gaussianstate(x0, p0, sigma0) 45 | J = [x + 1j * p] 46 | 47 | options = qt.Options() 48 | options.nsteps = 1000000 49 | options.atol = 1e-8 50 | options.rtol = 1e-6 51 | options.num_cpus = 1 52 | 53 | return psi0, H, x, J, options 54 | 55 | 56 | def f(psi0, H, x, J, options): 57 | tlist = np.linspace(0, 10, 11) 58 | exp_x = qt.mcsolve(H, psi0, tlist, J, [x], ntraj=evals, options=options).expect[0] 59 | return np.real(exp_x) 60 | 61 | 62 | print("Benchmarking:", name) 63 | print("Cutoff: ", end="", flush=True) 64 | checks = {} 65 | results = [] 66 | for N in cutoffs: 67 | print(N, "", end="", flush=True) 68 | psi0, H, x, J, options = setup(N) 69 | checks[N] = sum(f(psi0, H, x, J, options)) 70 | t = benchmarkutils.run_benchmark(f, psi0, H, x, J, options, samples=samples, evals=1) 71 | results.append({"N": N, "t": t / evals}) 72 | print() 73 | 74 | benchmarkutils.check(name, checks, 0.05) 75 | benchmarkutils.save(name, results) 76 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_schroedinger_cavity.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_schroedinger_cavity" 6 | 7 | samples = 3 8 | evals = 3 9 | cutoffs = range(50, 501, 50) 10 | 11 | 12 | def setup(N): 13 | options = qt.Options() 14 | options.atol = 1e-8 15 | options.rtol = 1e-6 16 | return options 17 | 18 | 19 | def f(N, options): 20 | eta = 1.5 21 | wc = 1.8 22 | wl = 2. 23 | delta_c = wl - wc 24 | alpha0 = 0.3 - 0.5j 25 | tspan = np.linspace(0, 10, 11) 26 | 27 | a = qt.destroy(N) 28 | at = qt.create(N) 29 | n = at * a 30 | 31 | H = delta_c*n + eta*(a + at) 32 | 33 | psi0 = qt.coherent(N, alpha0) 34 | exp_n = qt.mesolve(H, psi0, tspan, [], [n], options=options).expect[0] 35 | return np.real(exp_n) 36 | 37 | 38 | print("Benchmarking:", name) 39 | print("Cutoff: ", end="", flush=True) 40 | checks = {} 41 | results = [] 42 | for N in cutoffs: 43 | print(N, "", end="", flush=True) 44 | options = setup(N) 45 | checks[N] = sum(f(N, options)) 46 | t = benchmarkutils.run_benchmark(f, N, options, samples=samples, evals=evals) 47 | results.append({"N": N, "t": t}) 48 | print() 49 | 50 | benchmarkutils.check(name, checks) 51 | benchmarkutils.save(name, results) 52 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_schroedinger_jaynescummings.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_schroedinger_jaynescummings" 6 | 7 | samples = 3 8 | evals = 3 9 | cutoffs = range(25, 251, 25) 10 | 11 | 12 | def setup(N): 13 | options = qt.Options() 14 | options.atol = 1e-8 15 | options.rtol = 1e-6 16 | return options 17 | 18 | 19 | def f(N, options): 20 | wa = 1 21 | wc = 1 22 | g = 2 23 | tspan = np.linspace(0, 10, 11) 24 | 25 | Ia = qt.qeye(2) 26 | Ic = qt.qeye(N) 27 | 28 | a = qt.destroy(N) 29 | at = qt.create(N) 30 | n = at * a 31 | 32 | sm = qt.sigmam() 33 | sp = qt.sigmap() 34 | sz = qt.sigmaz() 35 | 36 | H = wc*qt.tensor(n, Ia) + qt.tensor(Ic, wa/2.*sz) + g*(qt.tensor(at, sm) + qt.tensor(a, sp)) 37 | 38 | psi0 = qt.tensor(qt.fock(N, 0), (qt.basis(2, 0) + qt.basis(2, 1)).unit()) 39 | exp_n = qt.mesolve(H, psi0, tspan, [], [qt.tensor(n, Ia)], options=options).expect[0] 40 | return exp_n 41 | 42 | 43 | print("Benchmarking:", name) 44 | print("Cutoff: ", end="", flush=True) 45 | checks = {} 46 | results = [] 47 | for N in cutoffs: 48 | print(N, "", end="", flush=True) 49 | options = setup(N) 50 | checks[N] = sum(f(N, options)) 51 | t = benchmarkutils.run_benchmark(f, N, options, samples=samples, evals=evals) 52 | results.append({"N": 2*N, "t": t}) 53 | print() 54 | 55 | benchmarkutils.check(name, checks) 56 | benchmarkutils.save(name, results) 57 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/timeevolution_schroedinger_particle.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "timeevolution_schroedinger_particle" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = range(25, 301, 25) 10 | 11 | 12 | def setup(N): 13 | xmin = -5 14 | xmax = 5 15 | x0 = 0.3 16 | p0 = -0.2 17 | sigma0 = 1 18 | dx = (xmax - xmin) / N 19 | pmin = -np.pi / dx 20 | pmax = np.pi / dx 21 | dp = (pmax - pmin) / N 22 | 23 | samplepoints_x = np.linspace(xmin, xmax, N, endpoint=False) 24 | samplepoints_p = np.linspace(pmin, pmax, N, endpoint=False) 25 | 26 | x = qt.Qobj(np.diag(samplepoints_x)) 27 | row0 = [sum([p*np.exp(-1j*p*dxji) for p in samplepoints_p])*dp*dx/(2*np.pi) for dxji in samplepoints_x - xmin] 28 | row0 = np.array(row0) 29 | col0 = row0.conj() 30 | 31 | a = np.zeros([N, N], dtype=complex) 32 | for i in range(N): 33 | a[i, i:] = row0[:N - i] 34 | a[i:, i] = col0[:N - i] 35 | p = qt.Qobj(a) 36 | 37 | H = p**2 + 2 * x**2 38 | 39 | def gaussianstate(x0, p0, sigma0): 40 | alpha = 1./(np.pi**(1/4)*np.sqrt(sigma0))*np.sqrt(dx) 41 | data = alpha*np.exp(1j*p0*(samplepoints_x-x0/2) - (samplepoints_x-x0)**2/(2*sigma0**2)) 42 | return qt.Qobj(data) 43 | 44 | psi0 = gaussianstate(x0, p0, sigma0) 45 | 46 | options = qt.Options() 47 | options.nsteps = 1000000 48 | options.atol = 1e-8 49 | options.rtol = 1e-6 50 | 51 | return psi0, H, x, options 52 | 53 | 54 | def f(psi0, H, x, options): 55 | tlist = np.linspace(0, 10, 11) 56 | exp_x = qt.mesolve(H, psi0, tlist, [], [x], options=options).expect[0] 57 | return exp_x 58 | 59 | 60 | print("Benchmarking:", name) 61 | print("Cutoff: ", end="", flush=True) 62 | checks = {} 63 | results = [] 64 | for N in cutoffs: 65 | print(N, "", end="", flush=True) 66 | psi0, H, x, options = setup(N) 67 | checks[N] = sum(f(psi0, H, x, options)) 68 | t = benchmarkutils.run_benchmark(f, psi0, H, x, options, samples=samples, evals=evals) 69 | results.append({"N": N, "t": t}) 70 | print() 71 | 72 | benchmarkutils.check(name, checks, 1e-4) 73 | benchmarkutils.save(name, results) 74 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/variance_operator.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "variance_operator" 6 | 7 | samples = 5 8 | evals = 50 9 | cutoffs = range(100, 2001, 100) 10 | 11 | def setup(N): 12 | op = (qt.destroy(N) + qt.create(N)) 13 | psi = qt.Qobj(np.ones(N, complex)/(N**(1/2))) 14 | rho = psi*psi.dag() 15 | return op, rho 16 | 17 | def f(op, rho): 18 | return qt.variance(op, rho) 19 | 20 | print("Benchmarking:", name) 21 | print("Cutoff: ", end="", flush=True) 22 | checks = {} 23 | results = [] 24 | for N in cutoffs: 25 | print(N, "", end="", flush=True) 26 | op, rho = setup(N) 27 | checks[N] = f(op, rho) 28 | t = benchmarkutils.run_benchmark(f, op, rho, samples=samples, evals=evals) 29 | results.append({"N": N, "t": t}) 30 | print() 31 | 32 | benchmarkutils.check(name, checks) 33 | benchmarkutils.save(name, results) 34 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/variance_state.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "variance_state" 6 | 7 | samples = 5 8 | evals = 100 9 | cutoffs = range(5000, 100001, 5000) 10 | 11 | def setup(N): 12 | op = (qt.destroy(N) + qt.create(N)) 13 | psi = qt.Qobj(np.ones(N, complex)/(N**(1/2))) 14 | return op, psi 15 | 16 | def f(op, psi): 17 | return qt.variance(op, psi) 18 | 19 | print("Benchmarking:", name) 20 | print("Cutoff: ", end="", flush=True) 21 | checks = {} 22 | results = [] 23 | for N in cutoffs: 24 | print(N, "", end="", flush=True) 25 | op, psi = setup(N) 26 | checks[N] = f(op, psi) 27 | t = benchmarkutils.run_benchmark(f, op, psi, samples=samples, evals=evals) 28 | results.append({"N": N, "t": t}) 29 | print() 30 | 31 | benchmarkutils.check(name, checks) 32 | benchmarkutils.save(name, results) 33 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/wigner_operator.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "wigner_operator" 6 | 7 | samples = 3 8 | evals = 5 9 | cutoffs = range(10, 101, 10) 10 | 11 | def setup(N): 12 | alpha = 0.7 13 | xvec = np.linspace(-50, 50, 100) 14 | yvec = np.linspace(-50, 50, 100) 15 | state = qt.coherent(N, alpha) 16 | op = state*state.dag() 17 | return op, xvec, yvec 18 | 19 | def f(state, xvec, yvec): 20 | return qt.wigner(state, xvec, yvec) 21 | 22 | print("Benchmarking:", name) 23 | print("Cutoff: ", end="", flush=True) 24 | checks = {} 25 | results = [] 26 | for N in cutoffs: 27 | print(N, "", end="", flush=True) 28 | op, xvec, yvec = setup(N) 29 | alpha_check = 0.6 + 0.1j 30 | checks[N] = f(op, [alpha_check.real], [alpha_check.imag])[0, 0] 31 | t = benchmarkutils.run_benchmark(f, op, xvec, yvec, samples=samples, evals=evals) 32 | results.append({"N": N, "t": t}) 33 | print() 34 | 35 | benchmarkutils.check(name, checks) 36 | benchmarkutils.save(name, results) 37 | -------------------------------------------------------------------------------- /benchmarks-QuTiP/wigner_state.py: -------------------------------------------------------------------------------- 1 | import qutip as qt 2 | import numpy as np 3 | import benchmarkutils 4 | 5 | name = "wigner_state" 6 | 7 | samples = 3 8 | evals = 5 9 | cutoffs = range(10, 101, 10) 10 | 11 | def setup(N): 12 | alpha = 0.7 13 | xvec = np.linspace(-50, 50, 100) 14 | yvec = np.linspace(-50, 50, 100) 15 | state = qt.coherent(N, alpha) 16 | return state, xvec, yvec 17 | 18 | def f(state, xvec, yvec): 19 | return qt.wigner(state, xvec, yvec) 20 | 21 | print("Benchmarking:", name) 22 | print("Cutoff: ", end="", flush=True) 23 | checks = {} 24 | results = [] 25 | for N in cutoffs: 26 | print(N, "", end="", flush=True) 27 | state, xvec, yvec = setup(N) 28 | alpha_check = 0.6 + 0.1j 29 | checks[N] = f(state, [alpha_check.real], [alpha_check.imag])[0, 0] 30 | t = benchmarkutils.run_benchmark(f, state, xvec, yvec, samples=samples, evals=evals) 31 | results.append({"N": N, "t": t}) 32 | print() 33 | 34 | benchmarkutils.check(name, checks) 35 | benchmarkutils.save(name, results) 36 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/addition_dense_dense.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | using Random; Random.seed!(0) 6 | 7 | name = "addition_dense_dense" 8 | 9 | samples = 3 10 | evals = 10 11 | cutoffs = [50:50:800;] 12 | 13 | function setup(N) 14 | b = GenericBasis(N) 15 | op1 = randoperator(b) 16 | op2 = randoperator(b) 17 | result = DenseOperator(b) 18 | op1, op2, result 19 | end 20 | 21 | function f(op1, op2, result) 22 | op1 + op2 23 | end 24 | 25 | println("Benchmarking: ", name) 26 | print("Cutoff: ") 27 | results = [] 28 | for N in cutoffs 29 | print(N, " ") 30 | op1, op2, result = setup(N) 31 | t = @belapsed f($op1, $op2, $result) samples=samples evals=evals 32 | push!(results, Dict("N"=>N, "t"=>t)) 33 | end 34 | println() 35 | 36 | benchmarkutils.save(name, results) 37 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/addition_dense_sparse.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | using SparseArrays 4 | include("benchmarkutils.jl") 5 | 6 | using Random; Random.seed!(0) 7 | 8 | basename = "addition_dense_sparse" 9 | 10 | samples = 2 11 | evals = 5 12 | cutoffs = [50:50:800;] 13 | S = [0.1, 0.01, 0.001] 14 | Nrand = 5 15 | 16 | function setup(N, s) 17 | b = GenericBasis(N) 18 | op1 = randoperator(b) 19 | op2 = SparseOperator(b, sprand(ComplexF64, N, N, s)) 20 | result = DenseOperator(b) 21 | op1, op2, result 22 | end 23 | 24 | function f(op1, op2, result) 25 | op1 + op2 26 | end 27 | 28 | for s in S 29 | name = basename * "_" * replace(string(s), "." => "") 30 | println("Benchmarking: ", name) 31 | print("Cutoff: ") 32 | results = [] 33 | for N in cutoffs 34 | print(N, " ") 35 | T = 0. 36 | for i=1:Nrand 37 | op1, op2, result = setup(N, s) 38 | T += @belapsed f($op1, $op2, $result) samples=samples evals=evals 39 | end 40 | push!(results, Dict("N"=>N, "t"=>T/Nrand)) 41 | end 42 | println() 43 | benchmarkutils.save(name, results) 44 | end 45 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/addition_sparse_dense.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | using SparseArrays 4 | include("benchmarkutils.jl") 5 | 6 | using Random; Random.seed!(0) 7 | 8 | basename = "addition_sparse_dense" 9 | 10 | samples = 2 11 | evals = 5 12 | cutoffs = [50:50:800;] 13 | S = [0.1, 0.01, 0.001] 14 | Nrand = 5 15 | 16 | function setup(N, s) 17 | b = GenericBasis(N) 18 | op1 = SparseOperator(b, sprand(ComplexF64, N, N, s)) 19 | op2 = randoperator(b) 20 | result = DenseOperator(b) 21 | op1, op2, result 22 | end 23 | 24 | function f(op1, op2, result) 25 | op1 + op2 26 | end 27 | 28 | for s in S 29 | name = basename * "_" * replace(string(s), "." => "") 30 | println("Benchmarking: ", name) 31 | print("Cutoff: ") 32 | results = [] 33 | for N in cutoffs 34 | print(N, " ") 35 | T = 0. 36 | for i=1:Nrand 37 | op1, op2, result = setup(N, s) 38 | T += @belapsed f($op1, $op2, $result) samples=samples evals=evals 39 | end 40 | push!(results, Dict("N"=>N, "t"=>T/Nrand)) 41 | end 42 | println() 43 | benchmarkutils.save(name, results) 44 | end 45 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/addition_sparse_sparse.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | using SparseArrays 4 | include("benchmarkutils.jl") 5 | 6 | using Random; Random.seed!(0) 7 | 8 | basename = "addition_sparse_sparse" 9 | 10 | samples = 2 11 | evals = 5 12 | cutoffs = [50:50:1000;] 13 | S = [0.1, 0.01, 0.001] 14 | Nrand = 5 15 | 16 | function setup(N, s) 17 | op1 = sprand(ComplexF64, N, N, s) 18 | op2 = sprand(ComplexF64, N, N, s) 19 | op1, op2 20 | end 21 | 22 | function f(op1, op2) 23 | op1 + op2 24 | end 25 | 26 | for s in S 27 | name = basename * "_" * replace(string(s), "." => "") 28 | println("Benchmarking: ", name) 29 | print("Cutoff: ") 30 | results = [] 31 | for N in cutoffs 32 | print(N, " ") 33 | T = 0. 34 | for i=1:Nrand 35 | op1, op2 = setup(N, s) 36 | T += @belapsed f($op1, $op2) samples=samples evals=evals 37 | end 38 | push!(results, Dict("N"=>N, "t"=>T/Nrand)) 39 | end 40 | println() 41 | benchmarkutils.save(name, results) 42 | end 43 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/benchmarkutils.jl: -------------------------------------------------------------------------------- 1 | module benchmarkutils 2 | 3 | using QuantumOptics 4 | using JSON 5 | 6 | set_zero_subnormals(true) 7 | 8 | # Detect the git commit hash 9 | const rootpath = abspath(".") 10 | const quantumoptics_directory = dirname(dirname(Base.functionloc(QuantumOptics.eval, Tuple{Nothing})[1])) 11 | cd(quantumoptics_directory) 12 | const commitID = read(`git rev-parse --verify HEAD`, String)[1:10] 13 | cd(rootpath) 14 | println("Detected QuantumOptics.jl version: ", commitID) 15 | 16 | benchmark_directory = "benchmarks-QuantumOptics.jl" 17 | checkvalues_directory = "checks" 18 | 19 | function examplename(name) 20 | if endswith(name, "]") 21 | return rsplit(name, "[", limit=2)[1] 22 | end 23 | name 24 | end 25 | 26 | function check(name, D, eps=1e-5) 27 | check_path = "../checks/$(examplename(name)).json" 28 | if ispath(check_path) 29 | println("Checking against check file.") 30 | data = JSON.parsefile(check_path) 31 | for (N, result) in D 32 | r = data[string(N)] 33 | if isnan(result) || abs(result-r)/abs(r) > eps 34 | println("Warning: Result may be incorrect in", name, ": ", result, "<->", r) 35 | end 36 | end 37 | else 38 | println("No check file found - write results to check file.") 39 | f = open(check_path, "w") 40 | write(f, JSON.json(D)) 41 | close(f) 42 | end 43 | end 44 | 45 | function save(name, results) 46 | result_path = "../results/results-QuantumOptics.jl-$commitID-$name.json" 47 | f = open(result_path, "w") 48 | write(f, JSON.json(results)) 49 | close(f) 50 | end 51 | 52 | end # module 53 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/coherentstate.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "coherentstate" 6 | 7 | samples = 5 8 | evals = 10000 9 | cutoffs = [50:50:500;] 10 | 11 | function setup(N) 12 | b = FockBasis(N-1) 13 | alpha = log(N) 14 | b, alpha 15 | end 16 | 17 | function f(b, alpha) 18 | coherentstate(b, alpha) 19 | end 20 | 21 | println("Benchmarking: ", name) 22 | print("Cutoff: ") 23 | checks = Dict{Int, Float64}() 24 | results = [] 25 | for N in cutoffs 26 | print(N, " ") 27 | b, alpha = setup(N) 28 | checks[N] = abs(expect(destroy(b), f(b, alpha))) 29 | t = @belapsed f($b, $alpha) samples=samples evals=evals 30 | push!(results, Dict("N"=>N, "t"=>t)) 31 | end 32 | println() 33 | 34 | benchmarkutils.check(name, checks) 35 | benchmarkutils.save(name, results) 36 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/displace.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "displace" 6 | 7 | samples = 3 8 | evals = 10 9 | cutoffs = [10:10:150;] 10 | 11 | function setup(N) 12 | b = FockBasis(N-1) 13 | alpha = log(N) 14 | b, alpha 15 | end 16 | 17 | function f(b, alpha) 18 | displace(b, alpha) 19 | end 20 | 21 | println("Benchmarking: ", name) 22 | print("Cutoff: ") 23 | checks = Dict{Int, Float64}() 24 | results = [] 25 | for N in cutoffs 26 | print(N, " ") 27 | b, alpha = setup(N) 28 | checks[N] = expect(destroy(b), f(b, alpha)) 29 | t = @belapsed f($b, $alpha) samples=samples evals=evals 30 | push!(results, Dict("N"=>N, "t"=>t)) 31 | end 32 | println() 33 | 34 | benchmarkutils.check(name, checks) 35 | benchmarkutils.save(name, results) 36 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/expect_operator.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "expect_operator" 6 | 7 | samples = 5 8 | evals = 100 9 | cutoffs = [100:100:2500;] 10 | 11 | function setup(N) 12 | b = FockBasis(N-1) 13 | op = (destroy(b) + create(b)) 14 | psi = Ket(b, ones(ComplexF64, N)/sqrt(N)) 15 | rho = psi ⊗ dagger(psi) 16 | op, rho 17 | end 18 | 19 | function f(op, rho) 20 | expect(op, rho) 21 | end 22 | 23 | println("Benchmarking: ", name) 24 | print("Cutoff: ") 25 | checks = Dict{Int, Float64}() 26 | results = [] 27 | for N in cutoffs 28 | print(N, " ") 29 | op, rho = setup(N) 30 | checks[N] = abs(f(op, rho)) 31 | t = @belapsed f($op, $rho) samples=samples evals=evals 32 | push!(results, Dict("N"=>N, "t"=>t)) 33 | end 34 | println() 35 | 36 | benchmarkutils.check(name, checks) 37 | benchmarkutils.save(name, results) 38 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/expect_state.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "expect_state" 6 | 7 | samples = 5 8 | evals = 100 9 | cutoffs = [5000:5000:150000;] 10 | 11 | function setup(N) 12 | b = FockBasis(N-1) 13 | op = (destroy(b) + create(b)) 14 | psi = Ket(b, ones(ComplexF64, N)/sqrt(N)) 15 | op, psi 16 | end 17 | 18 | function f(op, psi) 19 | expect(op, psi) 20 | end 21 | 22 | println("Benchmarking: ", name) 23 | print("Cutoff: ") 24 | checks = Dict{Int, Float64}() 25 | results = [] 26 | for N in cutoffs 27 | print(N, " ") 28 | op, psi = setup(N) 29 | checks[N] = abs(f(op, psi)) 30 | t = @belapsed f($op, $psi) samples=samples evals=evals 31 | push!(results, Dict("N"=>N, "t"=>t)) 32 | end 33 | println() 34 | 35 | benchmarkutils.check(name, checks) 36 | benchmarkutils.save(name, results) 37 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/multiplication_bra_dense.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | using Random; Random.seed!(0) 6 | 7 | name = "multiplication_bra_dense" 8 | 9 | samples = 2 10 | evals = 5 11 | cutoffs = [50:50:500;] 12 | 13 | function setup(N) 14 | b = GenericBasis(N) 15 | op1 = randoperator(b) 16 | psi = dagger(randstate(b)) 17 | result = copy(psi) 18 | op1, psi, result 19 | end 20 | 21 | function f(op1, psi, result) 22 | QuantumOpticsBase.gemv!(ComplexF64(1., 0.), psi, op1, ComplexF64(0., 0.), result) 23 | end 24 | 25 | println("Benchmarking: ", name) 26 | print("Cutoff: ") 27 | results = [] 28 | for N in cutoffs 29 | print(N, " ") 30 | op1, psi, result = setup(N) 31 | t = @belapsed f($op1, $psi, $result) samples=samples evals=evals 32 | push!(results, Dict("N"=>N, "t"=>t)) 33 | end 34 | println() 35 | benchmarkutils.save(name, results) 36 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/multiplication_bra_sparse.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | using SparseArrays 4 | include("benchmarkutils.jl") 5 | 6 | using Random; Random.seed!(0) 7 | 8 | basename = "multiplication_bra_sparse" 9 | 10 | samples = 2 11 | evals = 5 12 | cutoffs = [100:100:1000;] 13 | S = [0.1, 0.01, 0.001] 14 | Nrand = 5 15 | 16 | function setup(N, s) 17 | b = GenericBasis(N) 18 | op1 = SparseOperator(b, sprand(ComplexF64, N, N, s)) 19 | psi = dagger(randstate(b)) 20 | result = copy(psi) 21 | op1, psi, result 22 | end 23 | 24 | function f(op1, psi, result) 25 | QuantumOpticsBase.gemv!(ComplexF64(1., 0.), psi, op1, ComplexF64(0., 0.), result) 26 | end 27 | 28 | for s in S 29 | name = basename * "_" * replace(string(s), "." => "") 30 | println("Benchmarking: ", name) 31 | print("Cutoff: ") 32 | results = [] 33 | for N in cutoffs 34 | print(N, " ") 35 | T = 0. 36 | for i=1:Nrand 37 | op1, psi, result = setup(N, s) 38 | T += @belapsed f($op1, $psi, $result) samples=samples evals=evals 39 | end 40 | push!(results, Dict("N"=>N, "t"=>T/Nrand)) 41 | end 42 | println() 43 | benchmarkutils.save(name, results) 44 | end 45 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/multiplication_dense_dense.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | using Random; Random.seed!(0) 6 | 7 | name = "multiplication_dense_dense" 8 | 9 | samples = 3 10 | evals = 10 11 | cutoffs = [50:50:1000;] 12 | 13 | function setup(N) 14 | b = GenericBasis(N) 15 | op1 = randoperator(b) 16 | op2 = randoperator(b) 17 | result = DenseOperator(b) 18 | op1, op2, result 19 | end 20 | 21 | function f(op1, op2, result) 22 | QuantumOpticsBase.gemm!(ComplexF64(1., 0.), op1, op2, ComplexF64(0., 0.), result) 23 | end 24 | 25 | println("Benchmarking: ", name) 26 | print("Cutoff: ") 27 | results = [] 28 | for N in cutoffs 29 | print(N, " ") 30 | op1, op2, result = setup(N) 31 | t = @belapsed f($op1, $op2, $result) samples=samples evals=evals 32 | push!(results, Dict("N"=>N, "t"=>t)) 33 | end 34 | println() 35 | 36 | benchmarkutils.save(name, results) 37 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/multiplication_dense_ket.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | using Random; Random.seed!(0) 6 | 7 | name = "multiplication_dense_ket" 8 | 9 | samples = 2 10 | evals = 5 11 | cutoffs = [50:50:500;] 12 | 13 | function setup(N) 14 | b = GenericBasis(N) 15 | op1 = randoperator(b) 16 | psi = randstate(b) 17 | result = copy(psi) 18 | op1, psi, result 19 | end 20 | 21 | function f(op1, psi, result) 22 | QuantumOpticsBase.gemv!(ComplexF64(1., 0.), op1, psi, ComplexF64(0., 0.), result) 23 | end 24 | 25 | println("Benchmarking: ", name) 26 | print("Cutoff: ") 27 | results = [] 28 | for N in cutoffs 29 | print(N, " ") 30 | op1, psi, result = setup(N) 31 | t = @belapsed f($op1, $psi, $result) samples=samples evals=evals 32 | push!(results, Dict("N"=>N, "t"=>t)) 33 | end 34 | println() 35 | benchmarkutils.save(name, results) 36 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/multiplication_dense_sparse.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | using SparseArrays 4 | include("benchmarkutils.jl") 5 | 6 | using Random; Random.seed!(0) 7 | 8 | basename = "multiplication_dense_sparse" 9 | 10 | samples = 2 11 | evals = 5 12 | cutoffs = [50:50:1000;] 13 | S = [0.1, 0.01, 0.001] 14 | Nrand = 5 15 | 16 | function setup(N, s) 17 | b = GenericBasis(N) 18 | op1 = randoperator(b) 19 | op2 = SparseOperator(b, sprand(ComplexF64, N, N, s)) 20 | result = DenseOperator(b) 21 | op1, op2, result 22 | end 23 | 24 | function f(op1, op2, result) 25 | QuantumOpticsBase.gemm!(ComplexF64(1., 0.), op1, op2, ComplexF64(0., 0.), result) 26 | end 27 | 28 | for s in S 29 | name = basename * "_" * replace(string(s), "." => "") 30 | println("Benchmarking: ", name) 31 | print("Cutoff: ") 32 | results = [] 33 | for N in cutoffs 34 | print(N, " ") 35 | T = 0. 36 | for i=1:Nrand 37 | op1, op2, result = setup(N, s) 38 | T += @belapsed f($op1, $op2, $result) samples=samples evals=evals 39 | end 40 | push!(results, Dict("N"=>N, "t"=>T/Nrand)) 41 | end 42 | println() 43 | benchmarkutils.save(name, results) 44 | end 45 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/multiplication_sparse_dense.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | using SparseArrays 4 | include("benchmarkutils.jl") 5 | 6 | using Random; Random.seed!(0) 7 | 8 | basename = "multiplication_sparse_dense" 9 | 10 | samples = 2 11 | evals = 5 12 | cutoffs = [50:50:1000;] 13 | S = [0.1, 0.01, 0.001] 14 | Nrand = 5 15 | 16 | function setup(N, s) 17 | b = GenericBasis(N) 18 | op1 = SparseOperator(b, sprand(ComplexF64, N, N, s)) 19 | op2 = randoperator(b) 20 | result = DenseOperator(b) 21 | op1, op2, result 22 | end 23 | 24 | function f(op1, op2, result) 25 | QuantumOpticsBase.gemm!(ComplexF64(1., 0.), op1, op2, ComplexF64(0., 0.), result) 26 | end 27 | 28 | for s in S 29 | name = basename * "_" * replace(string(s), "." => "") 30 | println("Benchmarking: ", name) 31 | print("Cutoff: ") 32 | results = [] 33 | for N in cutoffs 34 | print(N, " ") 35 | T = 0. 36 | for i=1:Nrand 37 | op1, op2, result = setup(N, s) 38 | T += @belapsed f($op1, $op2, $result) samples=samples evals=evals 39 | end 40 | push!(results, Dict("N"=>N, "t"=>T/Nrand)) 41 | end 42 | println() 43 | benchmarkutils.save(name, results) 44 | end 45 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/multiplication_sparse_ket.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | using SparseArrays 4 | include("benchmarkutils.jl") 5 | 6 | using Random; Random.seed!(0) 7 | 8 | basename = "multiplication_sparse_ket" 9 | 10 | samples = 2 11 | evals = 5 12 | cutoffs = [100:100:1000;] 13 | S = [0.1, 0.01, 0.001] 14 | Nrand = 5 15 | 16 | function setup(N, s) 17 | b = GenericBasis(N) 18 | op1 = SparseOperator(b, sprand(ComplexF64, N, N, s)) 19 | psi = randstate(b) 20 | result = copy(psi) 21 | op1, psi, result 22 | end 23 | 24 | function f(op1, psi, result) 25 | QuantumOpticsBase.gemv!(ComplexF64(1., 0.), op1, psi, ComplexF64(0., 0.), result) 26 | end 27 | 28 | for s in S 29 | name = basename * "_" * replace(string(s), "." => "") 30 | println("Benchmarking: ", name) 31 | print("Cutoff: ") 32 | results = [] 33 | for N in cutoffs 34 | print(N, " ") 35 | T = 0. 36 | for i=1:Nrand 37 | op1, psi, result = setup(N, s) 38 | T += @belapsed f($op1, $psi, $result) samples=samples evals=evals 39 | end 40 | push!(results, Dict("N"=>N, "t"=>T/Nrand)) 41 | end 42 | println() 43 | benchmarkutils.save(name, results) 44 | end 45 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/multiplication_sparse_sparse.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | using SparseArrays 4 | include("benchmarkutils.jl") 5 | 6 | using Random; Random.seed!(0) 7 | 8 | basename = "multiplication_sparse_sparse" 9 | 10 | samples = 2 11 | evals = 5 12 | cutoffs = [50:50:1000;] 13 | S = [0.1, 0.01, 0.001] 14 | Nrand = 5 15 | 16 | function setup(N, s) 17 | op1 = sprand(ComplexF64, N, N, s) 18 | op2 = sprand(ComplexF64, N, N, s) 19 | op1, op2 20 | end 21 | 22 | function f(op1, op2) 23 | op1*op2 24 | end 25 | 26 | for s in S 27 | name = basename * "_" * replace(string(s), "." => "") 28 | println("Benchmarking: ", name) 29 | print("Cutoff: ") 30 | results = [] 31 | for N in cutoffs 32 | print(N, " ") 33 | T = 0. 34 | for i=1:Nrand 35 | op1, op2 = setup(N, s) 36 | T += @belapsed f($op1, $op2) samples=samples evals=evals 37 | end 38 | push!(results, Dict("N"=>N, "t"=>T/Nrand)) 39 | end 40 | println() 41 | benchmarkutils.save(name, results) 42 | end 43 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/ptrace_operator.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "ptrace_operator" 6 | 7 | samples = 5 8 | evals = 200 9 | cutoffs = [2:18;] 10 | 11 | function setup(N) 12 | function create_suboperator(c0, alpha, N) 13 | b = GenericBasis(N) 14 | data = transpose(reshape(c0 .+ alpha.*complex(range(0., stop=1., length=N^2)), N, N)) 15 | DenseOperator(b, data) 16 | end 17 | op1 = create_suboperator(1, 0.2, N) 18 | op2 = create_suboperator(-2, 0.3, N) 19 | op3 = create_suboperator(3, 0.4, 2) 20 | op4 = create_suboperator(4, 0.5, 2) 21 | op = tensor(op1, op2, op3, op4) 22 | op 23 | end 24 | 25 | function f(op) 26 | ptrace(op, [2, 3]) 27 | end 28 | 29 | println("Benchmarking: ", name) 30 | print("Cutoff: ") 31 | checks = Dict{Int, Float64}() 32 | results = [] 33 | for N in cutoffs 34 | print(N, " ") 35 | op = setup(N) 36 | checks[N] = sum(abs.(f(op).data)) 37 | t = @belapsed f($op) samples=samples evals=evals 38 | push!(results, Dict("N"=>4*N^2, "t"=>t)) 39 | end 40 | println() 41 | 42 | benchmarkutils.check(name, checks) 43 | benchmarkutils.save(name, results) 44 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/ptrace_state.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "ptrace_state" 6 | 7 | samples = 5 8 | evals = 200 9 | cutoffs = [2:18;] 10 | 11 | function setup(N) 12 | function create_substate(c0, alpha, N) 13 | b = GenericBasis(N) 14 | data = c0 .+ alpha*complex(range(0., stop=1., length=N)) 15 | Ket(b, data) 16 | end 17 | psi1 = create_substate(1, 0.2, N) 18 | psi2 = create_substate(-2, 0.3, N) 19 | psi3 = create_substate(3, 0.4, 2) 20 | psi4 = create_substate(4, 0.5, 2) 21 | psi = tensor(psi1, psi2, psi3, psi4) 22 | psi 23 | end 24 | 25 | function f(psi) 26 | ptrace(psi, [2, 3]) 27 | end 28 | 29 | println("Benchmarking: ", name) 30 | print("Cutoff: ") 31 | checks = Dict{Int, Float64}() 32 | results = [] 33 | for N in cutoffs 34 | print(N, " ") 35 | psi = setup(N) 36 | checks[N] = sum(abs.(f(psi).data)) 37 | t = @belapsed f($psi) samples=samples evals=evals 38 | push!(results, Dict("N"=>4*N^2, "t"=>t)) 39 | end 40 | println() 41 | 42 | benchmarkutils.check(name, checks) 43 | benchmarkutils.save(name, results) 44 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/qfunc_operator.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "qfunc_operator" 6 | 7 | samples = 3 8 | evals = 5 9 | cutoffs = [10:10:100;] 10 | 11 | function setup(N) 12 | alpha = 0.7 13 | xvec = collect(range(-50, stop=50, length=100)) 14 | yvec = collect(range(-50, stop=50, length=100)) 15 | b = FockBasis(N-1) 16 | state = coherentstate(b, alpha) 17 | op = state ⊗ dagger(state) 18 | op, xvec, yvec 19 | end 20 | 21 | function f(state, xvec, yvec) 22 | qfunc(state, xvec, yvec) 23 | end 24 | 25 | println("Benchmarking: ", name) 26 | print("Cutoff: ") 27 | checks = Dict{Int, Float64}() 28 | results = [] 29 | for N in cutoffs 30 | print(N, " ") 31 | op, xvec, yvec = setup(N) 32 | alpha_check = 0.6 + 0.1im 33 | checks[N] = real(f(op, [real(alpha_check)], [imag(alpha_check)])[1, 1]) 34 | t = @belapsed f($op, $xvec, $yvec) samples=samples evals=evals 35 | push!(results, Dict("N"=>N, "t"=>t)) 36 | end 37 | println() 38 | 39 | benchmarkutils.check(name, checks) 40 | benchmarkutils.save(name, results) 41 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/qfunc_state.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "qfunc_state" 6 | 7 | samples = 3 8 | evals = 5 9 | cutoffs = [10:10:100;] 10 | 11 | function setup(N) 12 | alpha = 0.7 13 | xvec = collect(range(-50, stop=50, length=100)) 14 | yvec = collect(range(-50, stop=50, length=100)) 15 | b = FockBasis(N-1) 16 | state = coherentstate(b, alpha) 17 | state, xvec, yvec 18 | end 19 | 20 | function f(state, xvec, yvec) 21 | qfunc(state, xvec, yvec) 22 | end 23 | 24 | println("Benchmarking: ", name) 25 | print("Cutoff: ") 26 | checks = Dict{Int, Float64}() 27 | results = [] 28 | for N in cutoffs 29 | print(N, " ") 30 | state, xvec, yvec = setup(N) 31 | alpha_check = 0.6 + 0.1im 32 | checks[N] = f(state, [real(alpha_check)], [imag(alpha_check)])[1, 1] 33 | t = @belapsed f($state, $xvec, $yvec) samples=samples evals=evals 34 | push!(results, Dict("N"=>N, "t"=>t)) 35 | end 36 | println() 37 | 38 | benchmarkutils.check(name, checks) 39 | benchmarkutils.save(name, results) 40 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_master_cavity.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_master_cavity" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = [10:10:150;] 10 | 11 | function setup(N) 12 | nothing 13 | end 14 | 15 | function f(N) 16 | κ = 1. 17 | η = 1.5 18 | ωc = 1.8 19 | ωl = 2. 20 | Δc = ωl - ωc 21 | α0 = 0.3 - 0.5im 22 | tspan = [0:1.:10;] 23 | 24 | b = FockBasis(N-1) 25 | a = destroy(b) 26 | at = create(b) 27 | n = number(b) 28 | 29 | H = Δc*at*a + η*(a + at) 30 | J = [a] 31 | rates = [κ] 32 | 33 | Ψ₀ = coherentstate(b, α0) 34 | exp_n = Float64[] 35 | fout(t, ρ) = push!(exp_n, real(expect(n, ρ))) 36 | timeevolution.master(tspan, Ψ₀, H, J; rates=rates, fout=fout, reltol=1e-6, abstol=1e-8) 37 | exp_n 38 | end 39 | 40 | println("Benchmarking: ", name) 41 | print("Cutoff: ") 42 | checks = Dict{Int, Float64}() 43 | results = [] 44 | for N in cutoffs 45 | print(N, " ") 46 | checks[N] = abs(sum(f(N))) 47 | t = @belapsed f($N) samples=samples evals=evals 48 | push!(results, Dict("N"=>N, "t"=>t)) 49 | end 50 | println() 51 | 52 | benchmarkutils.check(name, checks) 53 | benchmarkutils.save(name, results) 54 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_master_jaynescummings.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_master_jaynescummings" 6 | 7 | samples = 3 8 | evals = 3 9 | cutoffs = [5:5:80;] 10 | 11 | function setup(N) 12 | nothing 13 | end 14 | 15 | function f(N) 16 | ωa = 1 17 | ωc = 1 18 | g = 2 19 | κ = 0.5 20 | γ = 0.1 21 | n_th = 0.75 22 | tspan = [0.0:1.0:10.0;] 23 | 24 | b_cavity = FockBasis(N-1) 25 | b_atom = SpinBasis(1//2) 26 | b = b_cavity ⊗ b_atom 27 | 28 | a = destroy(b_cavity) 29 | at = create(b_cavity) 30 | n = number(b_cavity) 31 | 32 | sz = sigmaz(b_atom) 33 | sm = sigmam(b_atom) 34 | sp = sigmap(b_atom) 35 | 36 | H = embed(b, 1, ωc*n) + embed(b, 2, ωa*sz/2) + g*(at⊗sm+a⊗sp) 37 | rates = [κ*(1+n_th), κ*n_th, γ] 38 | J = [embed(b, 1, a), embed(b, 1, at), embed(b, 2, sm)] 39 | ψ₀ = fockstate(b_cavity, 0) ⊗ normalize(spinup(b_atom) + spindown(b_atom)) 40 | 41 | exp_n = Float64[] 42 | fout(t, ρ) = push!(exp_n, real(expect(1, n, ρ))) 43 | timeevolution.master(tspan, ψ₀, H, J; rates=rates, fout=fout, reltol=1e-6, abstol=1e-8) 44 | exp_n 45 | end 46 | 47 | println("Benchmarking: ", name) 48 | print("Cutoff: ") 49 | checks = Dict{Int, Float64}() 50 | results = [] 51 | for N in cutoffs 52 | print(N, " ") 53 | checks[N] = sum(f(N)) 54 | t = @belapsed f($N) samples=samples evals=evals 55 | push!(results, Dict("N"=>2*N, "t"=>t)) 56 | end 57 | println() 58 | 59 | benchmarkutils.check(name, checks) 60 | benchmarkutils.save(name, results) 61 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_master_particle.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_master_particle" 6 | 7 | samples = 3 8 | evals = 3 9 | cutoffs = [5:5:60;] 10 | 11 | function setup(N) 12 | xmin = -5 13 | xmax = 5 14 | x0 = 0.3 15 | p0 = -0.2 16 | sigma0 = 1 17 | bx = PositionBasis(xmin, xmax, N) 18 | x = position(bx) 19 | p = momentum(bx) 20 | H = p^2 + 2*x^2 21 | psi0 = gaussianstate(bx, x0, p0, sigma0) 22 | J = [x + 1im*p] 23 | psi0, H, x, J 24 | end 25 | 26 | function f(psi0, H, x, J) 27 | T = [0.0:1.0:10;] 28 | exp_x = Float64[] 29 | fout(t, rho) = push!(exp_x, real(expect(x, rho))) 30 | timeevolution.master(T, psi0, H, J; fout=fout, reltol=1e-6, abstol=1e-8) 31 | exp_x 32 | end 33 | 34 | println("Benchmarking: ", name) 35 | print("Cutoff: ") 36 | checks = Dict{Int, Float64}() 37 | results = [] 38 | for N in cutoffs 39 | print(N, " ") 40 | psi0, H, x, J = setup(N) 41 | checks[N] = sum(f(psi0, H, x, J)) 42 | t = @belapsed f($psi0, $H, $x, $J) samples=samples evals=evals 43 | push!(results, Dict("N"=>N, "t"=>t)) 44 | end 45 | println() 46 | 47 | benchmarkutils.check(name, checks) 48 | benchmarkutils.save(name, results) 49 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_master_timedependent_cavity.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_master_timedependent_cavity" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = [10:10:150;] 10 | 11 | function setup(N) 12 | nothing 13 | end 14 | 15 | function f(N) 16 | κ = 1. 17 | η = 1.5 18 | ωc = 1.8 19 | ωl = 2. 20 | Δc = ωl - ωc 21 | α0 = 0.3 - 0.5im 22 | tspan = [0:1.:10;] 23 | 24 | b = FockBasis(N-1) 25 | a = destroy(b) 26 | at = create(b) 27 | n = number(b) 28 | 29 | J = [a] 30 | Jdagger = [at] 31 | rates = [κ] 32 | 33 | Ψ0 = coherentstate(b, α0) 34 | 35 | αt = Float64[] 36 | fout(t, rho) = push!(αt, real(expect(a, rho))) 37 | H(t, n, a, at) = ωc*n + η*(a*exp(1im*ωl*t) + at*exp(-1im*ωl*t)) 38 | HJ(t::Float64, rho::DenseOperator) = (H(t, n, a, at), J, Jdagger) 39 | timeevolution.master_dynamic(tspan, Ψ0, HJ; rates=rates, fout=fout, reltol=1e-6, abstol=1e-8) 40 | αt 41 | end 42 | 43 | println("Benchmarking: ", name) 44 | print("Cutoff: ") 45 | 46 | checks = Dict{Int, Float64}() 47 | results = [] 48 | for N in cutoffs 49 | print(N, " ") 50 | checks[N] = sum(f(N)) 51 | t = @belapsed f($N) samples=samples evals=evals 52 | push!(results, Dict("N"=>N, "t"=>t)) 53 | end 54 | println() 55 | 56 | benchmarkutils.check(name, checks) 57 | benchmarkutils.save(name, results) 58 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_master_timedependent_jaynescummings.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_master_timedependent_jaynescummings" 6 | 7 | samples = 3 8 | evals = 3 9 | cutoffs = [5:5:80;] 10 | 11 | function setup(N) 12 | nothing 13 | end 14 | 15 | function f(N) 16 | ωa = 1 17 | ωc = 0.9 18 | Δ = ωa - ωc 19 | g = 2 20 | κ = 0.5 21 | γ = 0.1 22 | n_th = 0.75 23 | tspan = [0.0:1.0:10.0;] 24 | 25 | b_cavity = FockBasis(N-1) 26 | b_atom = SpinBasis(1//2) 27 | b = b_cavity ⊗ b_atom 28 | 29 | a = destroy(b_cavity) 30 | at = create(b_cavity) 31 | 32 | sm = sigmam(b_atom) 33 | sp = sigmap(b_atom) 34 | 35 | # H = embed(b, 1, ωc*n) + embed(b, 2, ωa*sz/2) + g*(at⊗sm+a⊗sp) 36 | Ha = g*at⊗sm 37 | Hb = g*a⊗sp 38 | rates = [κ*(1+n_th), κ*n_th, γ] 39 | J = [embed(b, 1, a), embed(b, 1, at), embed(b, 2, sm)] 40 | Jdagger = dagger.(J) 41 | ψ₀ = fockstate(b_cavity, 0) ⊗ normalize(spinup(b_atom) + spindown(b_atom)) 42 | 43 | H(t, rho) = (exp(-1im*Δ*t)*Ha + exp(1im*Δ*t)*Hb, J, Jdagger) 44 | asp = a⊗sp 45 | exp_asp = Float64[] 46 | fout(t, ρ) = push!(exp_asp, real(expect(asp, ρ))) 47 | timeevolution.master_dynamic(tspan, ψ₀, H; rates=rates, fout=fout, reltol=1e-6, abstol=1e-8) 48 | exp_asp 49 | end 50 | 51 | println("Benchmarking: ", name) 52 | print("Cutoff: ") 53 | checks = Dict{Int, Float64}() 54 | results = [] 55 | for N in cutoffs 56 | print(N, " ") 57 | checks[N] = sum(f(N)) 58 | t = @belapsed f($N) samples=samples evals=evals 59 | push!(results, Dict("N"=>2*N, "t"=>t)) 60 | end 61 | println() 62 | 63 | benchmarkutils.check(name, checks) 64 | benchmarkutils.save(name, results) 65 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_master_timedependent_particle.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_master_timedependent_particle" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = [5:5:60;] 10 | 11 | function setup(N) 12 | xmin = -5 13 | xmax = 5 14 | x0 = 0.3 15 | p0 = -0.2 16 | sigma0 = 1 17 | bx = PositionBasis(xmin, xmax, N) 18 | x = position(bx) 19 | p = momentum(bx) 20 | Hkin = p^2 21 | Vx = 2*x^2 22 | Ψ0 = gaussianstate(bx, x0, p0, sigma0) 23 | J = [x + 1im*p] 24 | Jdagger = [dagger(J[1])] 25 | Ψ0, Hkin, Vx, J, Jdagger, x 26 | end 27 | 28 | function f(Ψ0, Hkin, Vx, J, Jdagger, x) 29 | T = [0.0:1.0:10;] 30 | exp_x = Float64[] 31 | fout(t, rho) = push!(exp_x, real(expect(x, rho))) 32 | H(t, Hkin, Vx) = Hkin + (1 + cos(t))*Vx 33 | HJ(t, rho) = (H(t, Hkin, Vx), J, Jdagger) 34 | timeevolution.master_dynamic(T, Ψ0, HJ; fout=fout, reltol=1e-6, abstol=1e-8) 35 | exp_x 36 | end 37 | 38 | println("Benchmarking: ", name) 39 | print("Cutoff: ") 40 | checks = Dict{Int, Float64}() 41 | results = [] 42 | for N in cutoffs 43 | print(N, " ") 44 | Ψ0, Hkin, Vx, J, Jdagger, x = setup(N) 45 | checks[N] = sum(f(Ψ0, Hkin, Vx, J, Jdagger, x)) 46 | t = @belapsed f($Ψ0, $Hkin, $Vx, $J, $Jdagger, $x) samples=samples evals=evals 47 | push!(results, Dict("N"=>N, "t"=>t)) 48 | end 49 | println() 50 | 51 | benchmarkutils.check(name, checks) 52 | benchmarkutils.save(name, results) 53 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_mcwf_cavity.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_mcwf_cavity" 6 | 7 | samples = 2 8 | evals = 100 9 | cutoffs = [50:50:500;] 10 | Ncheck = 200 11 | 12 | function setup(N) 13 | nothing 14 | end 15 | 16 | function f(N) 17 | κ = 1. 18 | η = 1.5 19 | ωc = 1.8 20 | ωl = 2. 21 | Δc = ωl - ωc 22 | α0 = 0.3 - 0.5im 23 | tspan = [0:1.:10;] 24 | 25 | b = FockBasis(N-1) 26 | a = destroy(b) 27 | at = create(b) 28 | n = number(b) 29 | 30 | H = Δc*at*a + η*(a + at) 31 | J = [sqrt(κ)*a] 32 | 33 | Ψ₀ = coherentstate(b, α0) 34 | exp_n = Float64[] 35 | fout(t, ψ) = push!(exp_n, real(expect(n, ψ)/norm(ψ)^2)) 36 | timeevolution.mcwf(tspan, Ψ₀, H, J; fout=fout, reltol=1e-6, abstol=1e-8) 37 | exp_n 38 | end 39 | 40 | println("Benchmarking: ", name) 41 | print("Cutoff: ") 42 | checks = Dict{Int, Float64}() 43 | results = [] 44 | for N in cutoffs 45 | print(N, " ") 46 | C = 0. 47 | for i=1:Ncheck 48 | C += sum(f(N)) 49 | end 50 | checks[N] = C/Ncheck 51 | t = @belapsed f($N) samples=samples evals=evals 52 | push!(results, Dict("N"=>N, "t"=>t)) 53 | end 54 | println() 55 | 56 | benchmarkutils.check(name, checks, 0.05) 57 | benchmarkutils.save(name, results) 58 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_mcwf_jaynescummings.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_mcwf_jaynescummings" 6 | 7 | samples = 2 8 | evals = 100 9 | cutoffs = [50:50:500;] 10 | Ncheck = 200 11 | 12 | function setup(N) 13 | nothing 14 | end 15 | 16 | function f(N) 17 | ωa = 1 18 | ωc = 1 19 | g = 2 20 | κ = 0.5 21 | γ = 0.1 22 | n_th = 0.75 23 | tspan = [0.0:1.0:10.0;] 24 | 25 | b_cavity = FockBasis(N-1) 26 | b_atom = SpinBasis(1//2) 27 | b = b_cavity ⊗ b_atom 28 | 29 | a = destroy(b_cavity) 30 | at = create(b_cavity) 31 | n = number(b_cavity) 32 | 33 | sz = sigmaz(b_atom) 34 | sm = sigmam(b_atom) 35 | sp = sigmap(b_atom) 36 | 37 | H = embed(b, 1, ωc*n) + embed(b, 2, ωa*sz/2) + g*(at⊗sm+a⊗sp) 38 | J = [sqrt(κ*(1+n_th))*embed(b, 1, a), 39 | sqrt(κ*n_th)*embed(b, 1, at), 40 | sqrt(γ)*embed(b, 2, sm)] 41 | ψ₀ = fockstate(b_cavity, 0) ⊗ normalize(spinup(b_atom) + spindown(b_atom)) 42 | 43 | exp_n = Float64[] 44 | fout(t, ψ) = push!(exp_n, real(expect(1, n, ψ)/norm(ψ)^2)) 45 | timeevolution.mcwf(tspan, ψ₀, H, J; fout=fout, reltol=1e-6, abstol=1e-8) 46 | exp_n 47 | end 48 | 49 | println("Benchmarking: ", name) 50 | print("Cutoff: ") 51 | checks = Dict{Int, Float64}() 52 | results = [] 53 | for N in cutoffs 54 | print(N, " ") 55 | C = 0. 56 | for i=1:Ncheck 57 | C += sum(f(N)) 58 | end 59 | checks[N] = C/Ncheck 60 | t = @belapsed f($N) samples=samples evals=evals 61 | push!(results, Dict("N"=>2*N, "t"=>t)) 62 | end 63 | println() 64 | 65 | benchmarkutils.check(name, checks, 0.05) 66 | benchmarkutils.save(name, results) 67 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_mcwf_particle.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_mcwf_particle" 6 | 7 | samples = 2 8 | evals = 100 9 | cutoffs = [10:10:100;] 10 | Ncheck = 200 11 | 12 | function setup(N) 13 | xmin = -5 14 | xmax = 5 15 | x0 = 0.3 16 | p0 = -0.2 17 | sigma0 = 1 18 | bx = PositionBasis(xmin, xmax, N) 19 | x = position(bx) 20 | p = momentum(bx) 21 | H = p^2 + 2*x^2 22 | psi0 = gaussianstate(bx, x0, p0, sigma0) 23 | J = [x + 1im*p] 24 | psi0, H, x, J 25 | end 26 | 27 | function f(psi0, H, x, J) 28 | T = [0.0:1.0:10;] 29 | exp_x = Float64[] 30 | fout(t, ψ) = push!(exp_x, real(expect(x, ψ)/norm(ψ)^2)) 31 | timeevolution.mcwf(T, psi0, H, J; fout=fout, reltol=1e-6, abstol=1e-8) 32 | exp_x 33 | end 34 | 35 | println("Benchmarking: ", name) 36 | print("Cutoff: ") 37 | checks = Dict{Int, Float64}() 38 | results = [] 39 | for N in cutoffs 40 | print(N, " ") 41 | psi0, H, x, J = setup(N) 42 | C = 0. 43 | for i=1:Ncheck 44 | C += sum(f(psi0, H, x, J)) 45 | end 46 | checks[N] = C/Ncheck 47 | t = @belapsed f($psi0, $H, $x, $J) samples=samples evals=evals 48 | push!(results, Dict("N"=>N, "t"=>t)) 49 | end 50 | println() 51 | 52 | benchmarkutils.check(name, checks, 0.05) 53 | benchmarkutils.save(name, results) 54 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_schroedinger_cavity.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_schroedinger_cavity" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = [50:50:500;] 10 | 11 | function setup(N) 12 | nothing 13 | end 14 | 15 | function f(N) 16 | η = 1.5 17 | ωc = 1.8 18 | ωl = 2. 19 | Δc = ωl - ωc 20 | α0 = 0.3 - 0.5im 21 | tspan = [0:1.:10;] 22 | 23 | b = FockBasis(N-1) 24 | a = destroy(b) 25 | at = create(b) 26 | n = number(b) 27 | 28 | H = Δc*at*a + η*(a + at) 29 | 30 | Ψ₀ = coherentstate(b, α0) 31 | exp_n = Float64[] 32 | fout(t, ρ) = push!(exp_n, real(expect(n, ρ))) 33 | timeevolution.schroedinger(tspan, Ψ₀, H; fout=fout, reltol=1e-6, abstol=1e-8) 34 | exp_n 35 | end 36 | 37 | println("Benchmarking: ", name) 38 | print("Cutoff: ") 39 | checks = Dict{Int, Float64}() 40 | results = [] 41 | for N in cutoffs 42 | print(N, " ") 43 | checks[N] = abs(sum(f(N))) 44 | t = @belapsed f($N) samples=samples evals=evals 45 | push!(results, Dict("N"=>N, "t"=>t)) 46 | end 47 | println() 48 | 49 | benchmarkutils.check(name, checks) 50 | benchmarkutils.save(name, results) 51 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_schroedinger_jaynescummings.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_schroedinger_jaynescummings" 6 | 7 | samples = 3 8 | evals = 3 9 | cutoffs = [25:25:250;] 10 | 11 | function setup(N) 12 | nothing 13 | end 14 | 15 | function f(N) 16 | ωa = 1 17 | ωc = 1 18 | g = 2 19 | tspan = [0.0:1.0:10.0;] 20 | 21 | b_cavity = FockBasis(N-1) 22 | b_atom = SpinBasis(1//2) 23 | b = b_cavity ⊗ b_atom 24 | 25 | a = destroy(b_cavity) 26 | at = create(b_cavity) 27 | n = number(b_cavity) 28 | 29 | sz = sigmaz(b_atom) 30 | sm = sigmam(b_atom) 31 | sp = sigmap(b_atom) 32 | 33 | H = embed(b, 1, ωc*n) + embed(b, 2, ωa*sz/2) + g*(at⊗sm+a⊗sp) 34 | ψ₀ = fockstate(b_cavity, 0) ⊗ normalize(spinup(b_atom) + spindown(b_atom)) 35 | 36 | exp_n = Float64[] 37 | fout(t, ρ) = push!(exp_n, real(expect(1, n, ρ))) 38 | timeevolution.schroedinger(tspan, ψ₀, H; fout=fout, reltol=1e-6, abstol=1e-8) 39 | exp_n 40 | end 41 | 42 | println("Benchmarking: ", name) 43 | print("Cutoff: ") 44 | checks = Dict{Int, Float64}() 45 | results = [] 46 | for N in cutoffs 47 | print(N, " ") 48 | checks[N] = sum(f(N)) 49 | t = @belapsed f($N) samples=samples evals=evals 50 | push!(results, Dict("N"=>2*N, "t"=>t)) 51 | end 52 | println() 53 | 54 | benchmarkutils.check(name, checks) 55 | benchmarkutils.save(name, results) 56 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_schroedinger_particle.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_schroedinger_particle" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = [25:25:300;] 10 | 11 | function setup(N) 12 | xmin = -5 13 | xmax = 5 14 | x0 = 0.3 15 | p0 = -0.2 16 | sigma0 = 1 17 | bx = PositionBasis(xmin, xmax, N) 18 | x = position(bx) 19 | p = momentum(bx) 20 | H = p^2 + 2*x^2 21 | psi0 = gaussianstate(bx, x0, p0, sigma0) 22 | psi0, H, x 23 | end 24 | 25 | function f(psi0, H, x) 26 | T = [0:1.:10;] 27 | exp_x = Float64[] 28 | fout(t, psi) = push!(exp_x, real(expect(x, psi))) 29 | timeevolution.schroedinger(T, psi0, H; fout=fout, reltol=1e-6, abstol=1e-8) 30 | exp_x 31 | end 32 | 33 | println("Benchmarking: ", name) 34 | print("Cutoff: ") 35 | checks = Dict{Int, Float64}() 36 | results = [] 37 | for N in cutoffs 38 | print(N, " ") 39 | psi0, H, x = setup(N) 40 | checks[N] = sum(f(psi0, H, x)) 41 | t = @belapsed f($psi0, $H, $x) samples=samples evals=evals 42 | push!(results, Dict("N"=>N, "t"=>t)) 43 | end 44 | println() 45 | 46 | benchmarkutils.check(name, checks) 47 | benchmarkutils.save(name, results) 48 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/timeevolution_schroedinger_particle_fft.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "timeevolution_schroedinger_particle[fft]" 6 | 7 | samples = 3 8 | evals = 1 9 | cutoffs = [25:25:300;] 10 | 11 | function setup(N) 12 | xmin = -5 13 | xmax = 5 14 | x0 = 0.3 15 | p0 = -0.2 16 | sigma0 = 1 17 | bx = PositionBasis(xmin, xmax, N) 18 | bp = MomentumBasis(bx) 19 | x = position(bx) 20 | p = momentum(bp) 21 | Tpx = transform(bp, bx) 22 | Txp = dagger(Tpx) 23 | H = LazySum(LazyProduct(Txp, p^2, Tpx), 2*x^2) 24 | psi0 = gaussianstate(bx, x0, p0, sigma0) 25 | psi0, H, x 26 | end 27 | 28 | function f(psi0, H, x) 29 | T = [0:1.:10;] 30 | exp_x = Float64[] 31 | fout(t, psi) = push!(exp_x, real(expect(x, psi))) 32 | timeevolution.schroedinger(T, psi0, H; fout=fout, reltol=1e-6, abstol=1e-8) 33 | exp_x 34 | end 35 | 36 | println("Benchmarking: ", name) 37 | print("Cutoff: ") 38 | checks = Dict{Int, Float64}() 39 | results = [] 40 | for N in cutoffs 41 | print(N, " ") 42 | psi0, H, x = setup(N) 43 | checks[N] = sum(f(psi0, H, x)) 44 | t = @belapsed f($psi0, $H, $x) samples=samples evals=evals 45 | push!(results, Dict("N"=>N, "t"=>t)) 46 | end 47 | println() 48 | 49 | benchmarkutils.check(name, checks) 50 | benchmarkutils.save(name, results) 51 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/variance_operator.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "variance_operator" 6 | 7 | samples = 5 8 | evals = 50 9 | cutoffs = [100:100:2000;] 10 | 11 | function setup(N) 12 | b = FockBasis(N-1) 13 | op = (destroy(b) + create(b)) 14 | psi = Ket(b, ones(ComplexF64, N)/sqrt(N)) 15 | rho = psi ⊗ dagger(psi) 16 | op, rho 17 | end 18 | 19 | function f(op, rho) 20 | variance(op, rho) 21 | end 22 | 23 | println("Benchmarking: ", name) 24 | print("Cutoff: ") 25 | checks = Dict{Int, Float64}() 26 | results = [] 27 | for N in cutoffs 28 | print(N, " ") 29 | op, rho = setup(N) 30 | checks[N] = abs(f(op, rho)) 31 | t = @belapsed f($op, $rho) samples=samples evals=evals 32 | push!(results, Dict("N"=>N, "t"=>t)) 33 | end 34 | println() 35 | 36 | benchmarkutils.check(name, checks) 37 | benchmarkutils.save(name, results) 38 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/variance_state.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "variance_state" 6 | 7 | samples = 5 8 | evals = 100 9 | cutoffs = [5000:5000:100000;] 10 | 11 | function setup(N) 12 | b = FockBasis(N-1) 13 | op = (destroy(b) + create(b)) 14 | psi = Ket(b, ones(ComplexF64, N)/sqrt(N)) 15 | op, psi 16 | end 17 | 18 | function f(op, psi) 19 | variance(op, psi) 20 | end 21 | 22 | println("Benchmarking: ", name) 23 | print("Cutoff: ") 24 | checks = Dict{Int, Float64}() 25 | results = [] 26 | for N in cutoffs 27 | print(N, " ") 28 | op, psi = setup(N) 29 | checks[N] = abs(f(op, psi)) 30 | t = @belapsed f($op, $psi) samples=samples evals=evals 31 | push!(results, Dict("N"=>N, "t"=>t)) 32 | end 33 | println() 34 | 35 | benchmarkutils.check(name, checks) 36 | benchmarkutils.save(name, results) 37 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/wigner_operator.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "wigner_operator" 6 | 7 | samples = 3 8 | evals = 5 9 | cutoffs = [10:10:100;] 10 | 11 | function setup(N) 12 | alpha = 0.7 13 | xvec = collect(range(-50, stop=50, length=100)) 14 | yvec = collect(range(-50, stop=50, length=100)) 15 | b = FockBasis(N-1) 16 | state = coherentstate(b, alpha) 17 | op = state ⊗ dagger(state) 18 | op, xvec, yvec 19 | end 20 | 21 | function f(state, xvec, yvec) 22 | wigner(state, xvec, yvec) 23 | end 24 | 25 | println("Benchmarking: ", name) 26 | print("Cutoff: ") 27 | checks = Dict{Int, Float64}() 28 | results = [] 29 | for N in cutoffs 30 | print(N, " ") 31 | op, xvec, yvec = setup(N) 32 | alpha_check = 0.6 + 0.1im 33 | checks[N] = real(f(op, [real(alpha_check)], [imag(alpha_check)])[1, 1]) 34 | t = @belapsed f($op, $xvec, $yvec) samples=samples evals=evals 35 | push!(results, Dict("N"=>N, "t"=>t)) 36 | end 37 | println() 38 | 39 | benchmarkutils.check(name, checks) 40 | benchmarkutils.save(name, results) 41 | -------------------------------------------------------------------------------- /benchmarks-QuantumOptics.jl/wigner_state.jl: -------------------------------------------------------------------------------- 1 | using QuantumOptics 2 | using BenchmarkTools 3 | include("benchmarkutils.jl") 4 | 5 | name = "wigner_state" 6 | 7 | samples = 3 8 | evals = 5 9 | cutoffs = [10:10:100;] 10 | 11 | function setup(N) 12 | alpha = 0.7 13 | xvec = collect(range(-50, stop=50, length=100)) 14 | yvec = collect(range(-50, stop=50, length=100)) 15 | b = FockBasis(N-1) 16 | state = coherentstate(b, alpha) 17 | state, xvec, yvec 18 | end 19 | 20 | function f(state, xvec, yvec) 21 | wigner(state, xvec, yvec) 22 | end 23 | 24 | println("Benchmarking: ", name) 25 | print("Cutoff: ") 26 | checks = Dict{Int, Float64}() 27 | results = [] 28 | for N in cutoffs 29 | print(N, " ") 30 | state, xvec, yvec = setup(N) 31 | alpha_check = 0.6 + 0.1im 32 | checks[N] = f(state, [real(alpha_check)], [imag(alpha_check)])[1, 1] 33 | t = @belapsed f($state, $xvec, $yvec) samples=samples evals=evals 34 | push!(results, Dict("N"=>N, "t"=>t)) 35 | end 36 | println() 37 | 38 | benchmarkutils.check(name, checks) 39 | benchmarkutils.save(name, results) 40 | -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/bench_expect_operator.m: -------------------------------------------------------------------------------- 1 | 2 | function result = bench_expect_operator() 3 | name = 'expect_operator'; 4 | cutoffs = [100:100:700]; 5 | checks = []; 6 | result = []; 7 | for N = cutoffs 8 | [op, rho] = setup(N); 9 | f_ = @() f(op, rho); 10 | checks = [checks, f_()]; 11 | result = [result, timeit(f_)]; 12 | end 13 | checkbenchmark(name, cutoffs, checks, 1e-5) 14 | savebenchmark(name, cutoffs, result) 15 | end 16 | 17 | function [op, rho] = setup(N) 18 | op = (destroy(N) + create(N)); 19 | psi = qo(ones(N, 1)/(N^(1/2))); 20 | rho = psi*psi'; 21 | end 22 | 23 | function result = f(op, state) 24 | result = expect(op, state); 25 | end 26 | -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/bench_expect_state.m: -------------------------------------------------------------------------------- 1 | 2 | function result = bench_expect_state() 3 | name = 'expect_state'; 4 | cutoffs = [5000:5000:70000]; 5 | checks = []; 6 | result = []; 7 | for N = cutoffs 8 | [op, psi] = setup(N); 9 | f_ = @() f(op, psi); 10 | checks = [checks, f_()]; 11 | result = [result, timeit(f_)]; 12 | end 13 | checkbenchmark(name, cutoffs, checks, 1e-5) 14 | savebenchmark(name, cutoffs, result) 15 | end 16 | 17 | function [op, psi] = setup(N) 18 | op = (destroy(N) + create(N)); 19 | psi = qo(ones(N, 1)/(N^(1/2))); 20 | end 21 | 22 | function result = f(op, state) 23 | result = expect(op, state); 24 | end 25 | -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/bench_multiplication_dense_dense.m: -------------------------------------------------------------------------------- 1 | 2 | function results = bench_multiplication_dense_dense() 3 | name = 'multiplication_dense_dense'; 4 | cutoffs = [50:50:1001]; 5 | results = []; 6 | for N = cutoffs 7 | [op1, op2] = setup(N); 8 | f_ = @() f(op1, op2); 9 | results = [results, timeit(f_)]; 10 | end 11 | savebenchmark(name, cutoffs, results) 12 | end 13 | 14 | function [op1, op2] = setup(N) 15 | op1 = (1.+0.3j)*rand(N, N); 16 | op2 = (1.+0.3j)*rand(N, N); 17 | end 18 | 19 | function result = f(op1, op2) 20 | result = op1*op2; 21 | end 22 | -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/bench_multiplication_dense_sparse.m: -------------------------------------------------------------------------------- 1 | 2 | function results = bench_multiplication_dense_sparse() 3 | basename = 'multiplication_dense_sparse'; 4 | cutoffs = 50:50:1000; 5 | S = [0.1, 0.01, 0.001]; 6 | Nrand = 5; 7 | for s = S 8 | name = [basename, '_', strrep(mat2str(s), '.', '')]; 9 | results = []; 10 | for N = cutoffs 11 | T = 0.; 12 | for i=1:Nrand 13 | [op1, op2] = setup(N, s); 14 | f_ = @() f(op1, op2); 15 | T = T + timeit(f_); 16 | end 17 | results = [results, T/Nrand]; 18 | end 19 | savebenchmark(name, cutoffs, results) 20 | end 21 | end 22 | 23 | function [op1, op2] = setup(N, s) 24 | op1 = (1.+0.3j)*rand(N, N); 25 | op2 = (1.+0.3j)*sprand(N, N, s); 26 | end 27 | 28 | function result = f(op1, op2) 29 | result = op1*op2; 30 | end 31 | -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/bench_multiplication_sparse_dense.m: -------------------------------------------------------------------------------- 1 | 2 | function results = bench_multiplication_sparse_dense() 3 | basename = 'multiplication_sparse_dense'; 4 | cutoffs = 50:50:1000; 5 | S = [0.1, 0.01, 0.001]; 6 | Nrand = 5; 7 | for s = S 8 | name = [basename, '_', strrep(mat2str(s), '.', '')]; 9 | results = []; 10 | for N = cutoffs 11 | T = 0.; 12 | for i=1:Nrand 13 | [op1, op2] = setup(N, s); 14 | f_ = @() f(op1, op2); 15 | T = T + timeit(f_); 16 | end 17 | results = [results, T/Nrand]; 18 | end 19 | savebenchmark(name, cutoffs, results) 20 | end 21 | end 22 | 23 | function [op1, op2] = setup(N, s) 24 | op1 = (1.+0.3j)*sprand(N, N, s); 25 | op2 = (1.+0.3j)*rand(N, N); 26 | end 27 | 28 | function result = f(op1, op2) 29 | result = op1*op2; 30 | end 31 | -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/bench_multiplication_sparse_sparse.m: -------------------------------------------------------------------------------- 1 | 2 | function results = bench_multiplication_sparse_sparse() 3 | basename = 'multiplication_sparse_sparse'; 4 | cutoffs = 50:50:1000; 5 | S = [0.1, 0.01, 0.001]; 6 | Nrand = 5; 7 | for s = S 8 | name = [basename, '_', strrep(mat2str(s), '.', '')]; 9 | results = []; 10 | for N = cutoffs 11 | T = 0.; 12 | for i=1:Nrand 13 | [op1, op2] = setup(N, s); 14 | f_ = @() f(op1, op2); 15 | T = T + timeit(f_); 16 | end 17 | results = [results, T/Nrand]; 18 | end 19 | savebenchmark(name, cutoffs, results) 20 | end 21 | end 22 | 23 | function [op1, op2] = setup(N, s) 24 | op1 = (1.+0.3j)*sprand(N, N, s); 25 | op2 = (1.+0.3j)*sprand(N, N, s); 26 | end 27 | 28 | function result = f(op1, op2) 29 | result = op1*op2; 30 | end 31 | -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/bench_ptrace.m: -------------------------------------------------------------------------------- 1 | 2 | function result = bench_ptrace() 3 | name = 'ptrace'; 4 | cutoffs = [2:9]; 5 | checks = []; 6 | result = []; 7 | for N = cutoffs 8 | op = create_operator(N); 9 | f_ = @() f(op); 10 | y = f_(); 11 | checks = [checks, sumabs(y.data)]; 12 | result = [result, timeit(f_)]; 13 | end 14 | checkbenchmark(name, cutoffs, checks, 1e-5) 15 | savebenchmark(name, 4*cutoffs.^2, result) 16 | end 17 | 18 | function result = f(op) 19 | result = ptrace(op, [2, 3]); 20 | end 21 | 22 | function result = create_operator(Ncutoff) 23 | op1 = create_suboperator(1, 0.2, Ncutoff); 24 | op2 = create_suboperator(-2, 0.3, Ncutoff); 25 | op3 = create_suboperator(3, 0.4, 2); 26 | op4 = create_suboperator(4, 0.5, 2); 27 | result = tensor(op1, op2, op3, op4); 28 | end 29 | 30 | function result = create_suboperator(c0, alpha, N) 31 | x = linspace(0., 1., N^2); 32 | data = reshape(c0 + alpha*x, N, N); 33 | result = qo(data); 34 | end -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/bench_timeevolution_master_cavity.m: -------------------------------------------------------------------------------- 1 | 2 | function result = bench_timeevolution_master_cavity() 3 | name = 'timeevolution_master_cavity'; 4 | cutoffs = 10:10:60; 5 | checks = []; 6 | result = []; 7 | for N = cutoffs 8 | f_ = @() f(N); 9 | checks = [checks, sum(f_())]; 10 | result = [result, timeit(f_)]; 11 | end 12 | checkbenchmark(name, cutoffs, checks, 1e-5) 13 | savebenchmark(name, cutoffs, result) 14 | end 15 | 16 | function result = f(Ncutoff) 17 | kappa = 1.; 18 | eta = 1.5; 19 | wc = 1.8; 20 | wl = 2; 21 | delta_c = wl - wc; 22 | alpha0 = 0.3 - 0.5j; 23 | tspan = 0:1:10; 24 | 25 | a = destroy(Ncutoff); 26 | at = create(Ncutoff); 27 | n = at*a; 28 | 29 | H = delta_c*n + eta*(a + at); 30 | C = sqrt(kappa)*a; 31 | LH = -1i * (spre(H) - spost(H)); 32 | L1 = spre(C)*spost(C')-0.5*spre(C'*C)-0.5*spost(C'*C); 33 | L = LH+L1; 34 | 35 | D = expm(alpha0*at - conj(alpha0)*a); 36 | psi0 = D*basis(Ncutoff, 1); 37 | expect(a, psi0) 38 | rho0 = psi0 * psi0'; 39 | 40 | % Set up options, if required 41 | options.reltol = 1e-6; 42 | options.abstol = 1e-8; 43 | % Write out the data file 44 | ode2file('file1.dat', L, rho0, tspan, options); 45 | % Call the equation solver 46 | odesolve('file1.dat','file2.dat'); 47 | % Read in the output data file 48 | fid = fopen('file2.dat','rb'); 49 | rho = qoread(fid, dims(rho0), size(tspan)); 50 | fclose(fid); 51 | result = real(expect(n, rho)); 52 | end 53 | -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/bench_timeevolution_master_jaynescummings.m: -------------------------------------------------------------------------------- 1 | 2 | function result = bench_timeevolution_master_jaynescummings() 3 | name = 'timeevolution_master_jaynescummings'; 4 | cutoffs = 5:5:60; 5 | checks = []; 6 | result = []; 7 | for N = cutoffs 8 | f_ = @() f(N); 9 | checks = [checks, sum(f_())]; 10 | result = [result, timeit(f_)]; 11 | end 12 | checkbenchmark(name, 2*cutoffs, checks, 1e-5) 13 | savebenchmark(name, 2*cutoffs, result) 14 | end 15 | 16 | function result = f(Ncutoff) 17 | wa = 1; 18 | wc = 1; 19 | g = 2; 20 | kappa = 0.5; 21 | gamma = 0.1; 22 | n_th = 0.75; 23 | tspan = 0:1:10; 24 | 25 | Ia = identity(2); 26 | Ic = identity(Ncutoff); 27 | 28 | a = destroy(Ncutoff); 29 | at = a'; 30 | n = at*a; 31 | 32 | sm = sigmam(); 33 | sp = sigmap(); 34 | sz = sigmaz(); 35 | 36 | H = tensor(n, wc*Ia) + tensor(Ic, wa/2. *sz) + g*(tensor(at, sm) + tensor(a, sp)); 37 | C1 = tensor(sqrt(kappa*(1+n_th))*a, Ia); 38 | C2 = tensor(sqrt(kappa*n_th)*at, Ia); 39 | C3 = tensor(Ic, sqrt(gamma)*sm); 40 | LH = -1i * (spre(H) - spost(H)); 41 | L1 = spre(C1)*spost(C1')-0.5*spre(C1'*C1)-0.5*spost(C1'*C1); 42 | L2 = spre(C2)*spost(C2')-0.5*spre(C2'*C2)-0.5*spost(C2'*C2); 43 | L3 = spre(C3)*spost(C3')-0.5*spre(C3'*C3)-0.5*spost(C3'*C3); 44 | L = LH + L1 + L2 + L3; 45 | 46 | psi0 = tensor(basis(Ncutoff, 1), (basis(2, 1) + basis(2, 2))/sqrt(2)); 47 | rho0 = psi0 * psi0'; 48 | 49 | % Set up options, if required 50 | options.reltol = 1e-6; 51 | options.abstol = 1e-8; 52 | % Write out the data file 53 | ode2file('file1.dat', L, rho0, tspan, options); 54 | % Call the equation solver 55 | odesolve('file1.dat','file2.dat'); 56 | % Read in the output data file 57 | fid = fopen('file2.dat','rb'); 58 | rho = qoread(fid, dims(rho0), size(tspan)); 59 | fclose(fid); 60 | result = real(expect(tensor(n, Ia), rho)); 61 | end 62 | -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/bench_timeevolution_master_particle.m: -------------------------------------------------------------------------------- 1 | 2 | function result = bench_timeevolution_master_particle() 3 | name = 'timeevolution_master_particle'; 4 | cutoffs = 5:5:30; 5 | checks = []; 6 | result = []; 7 | for N = cutoffs 8 | [rho0, L, x] = setup(N); 9 | f_ = @() f(rho0, L, x); 10 | checks = [checks, sum(f_())]; 11 | result = [result, timeit(f_)]; 12 | end 13 | checkbenchmark(name, cutoffs, checks, 1e-5) 14 | savebenchmark(name, cutoffs, result) 15 | end 16 | 17 | function [rho0, L, x] = setup(N) 18 | xmin = -5; 19 | xmax = 5; 20 | x0 = 0.3; 21 | p0 = -0.2; 22 | sigma0 = 1; 23 | dx = (xmax - xmin)/N; 24 | pmin = -pi/dx; 25 | pmax = pi/dx; 26 | dp = (pmax - pmin)/N; 27 | tmp = linspace(xmin, xmax, N+1); 28 | samplepoints_x = tmp(1:end-1); 29 | tmp = linspace(pmin, pmax, N+1); 30 | samplepoints_p = tmp(1:end-1); 31 | 32 | x = qo(diag(samplepoints_x)); 33 | 34 | % Create momentum operator 35 | row0 = zeros(1, N); 36 | for i=1:N 37 | dxji = samplepoints_x(i) - xmin; 38 | for j=1:N 39 | p = samplepoints_p(j); 40 | row0(i) = row0(i) + p*exp(-1j*p*dxji)*dp*dx/(2*pi); 41 | end 42 | end 43 | col0 = conj(row0); 44 | a = zeros(N, N); 45 | for i=1:N 46 | a(i, i:end) = row0(1:N-i+1); 47 | a(i:end, i) = col0(1:N-i+1); 48 | end 49 | p = qo(a); 50 | 51 | H = p^2 + 2*x^2; 52 | 53 | % Create gaussian state 54 | alpha = 1./(pi^(1/4)*sqrt(sigma0))*sqrt(dx); 55 | data = alpha*exp(1j*p0*(samplepoints_x-x0/2) - (samplepoints_x-x0).^2/(2*sigma0^2)); 56 | psi0 = qo(data.'); 57 | C = (x + 1j*p); 58 | LH = -1i * (spre(H) - spost(H)); 59 | L1 = spre(C)*spost(C')-0.5*spre(C'*C)-0.5*spost(C'*C); 60 | L = LH+L1; 61 | 62 | rho0 = psi0 * psi0'; 63 | end 64 | 65 | function result = f(rho0, L, x) 66 | % Set up options, if required 67 | options.reltol = 1e-6; 68 | options.abstol = 1e-8; 69 | tlist = linspace(0, 10, 11); 70 | ode2file('file1.dat', L, rho0, tlist, options); 71 | % Call the equation solver 72 | odesolve('file1.dat','file2.dat'); 73 | % Read in the output data file 74 | fid = fopen('file2.dat','rb'); 75 | rho = qoread(fid, dims(rho0), size(tlist)); 76 | fclose(fid); 77 | result = real(expect(x, rho)); 78 | end 79 | -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/checkbenchmark.m: -------------------------------------------------------------------------------- 1 | function checkbenchmark(name, cutoffs, results, eps) 2 | [cutoffs_f, results_f] = loadjson(name); 3 | for i=1:length(cutoffs) 4 | Ncutoff = cutoffs(i); 5 | index = find(cutoffs_f==Ncutoff, 1); 6 | if isempty(index) 7 | warning(['Cutoff of ', num2str(Ncutoff), ' not found in check file.']) 8 | else 9 | r1 = results_f(index); 10 | r2 = results(i); 11 | abs(r1-r2); 12 | if (abs(r1-r2)/abs(r1) > eps) 13 | warning(['Result may be incorrect: ', num2str(r2), ' instead of ', num2str(r1)]) 14 | end 15 | end 16 | end 17 | end 18 | 19 | function [cutoffs, results] = loadjson(name) 20 | fid = fopen(['../checks/', name, '.json'], 'r'); 21 | data = fscanf(fid, '%c'); 22 | data = data(2:end-1); 23 | fclose(fid); 24 | results = []; 25 | cutoffs = []; 26 | for item=strsplit(data, ',') 27 | x = strsplit(cell2mat(item), ':'); 28 | N = cell2mat(x(1)); 29 | check = cell2mat(x(2)); 30 | N = N(2:end-1); 31 | cutoffs = [cutoffs; str2num(N)]; 32 | results = [results; str2num(check)]; 33 | end 34 | [cutoffs, I] = sort(cutoffs); 35 | results = results(I); 36 | end 37 | -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/runall.m: -------------------------------------------------------------------------------- 1 | bench_ptrace(); 2 | bench_expect_state(); 3 | bench_expect_operator(); 4 | bench_multiplication_sparse_sparse(); 5 | bench_multiplication_sparse_dense(); 6 | bench_multiplication_dense_sparse(); 7 | bench_multiplication_dense_dense(); 8 | bench_timeevolution_master_cavity(); 9 | bench_timeevolution_master_jaynescummings(); 10 | bench_timeevolution_master_particle(); -------------------------------------------------------------------------------- /benchmarks-QuantumOpticsToolbox/savebenchmark.m: -------------------------------------------------------------------------------- 1 | function savebenchmark(name, Ncutoff, T) 2 | results = '['; 3 | for i = 1:length(Ncutoff) 4 | results = [results, '{"N": ', mat2str(Ncutoff(i)), ', "t": ', mat2str(T(i)), '}']; 5 | if i == length(Ncutoff) 6 | results = [results, ']']; 7 | else 8 | results = [results, ', ']; 9 | end 10 | end 11 | fid = fopen(['../results/results-QuantumOpticsToolbox-', name, '.json'], 'wt'); 12 | fprintf(fid, results); 13 | fclose(fid); 14 | end -------------------------------------------------------------------------------- /checks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qojulia/QuantumOptics.jl-benchmarks/c3e7a1fdb60457fd21508cf8b04598420cc9d548/checks/.keep -------------------------------------------------------------------------------- /clear.sh: -------------------------------------------------------------------------------- 1 | rm results/*.json 2 | rm results-collected/*.json 3 | rm checks/*.json 4 | rm sourcecode/* 5 | -------------------------------------------------------------------------------- /collect_results.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | names = [ 5 | "addition_sparse_sparse_01", 6 | "addition_sparse_sparse_001", 7 | "addition_sparse_sparse_0001", 8 | "addition_sparse_dense_01", 9 | "addition_sparse_dense_001", 10 | "addition_sparse_dense_0001", 11 | "addition_dense_sparse_01", 12 | "addition_dense_sparse_001", 13 | "addition_dense_sparse_0001", 14 | "addition_dense_dense", 15 | "multiplication_sparse_sparse_01", 16 | "multiplication_sparse_sparse_001", 17 | "multiplication_sparse_sparse_0001", 18 | "multiplication_sparse_dense_01", 19 | "multiplication_sparse_dense_001", 20 | "multiplication_sparse_dense_0001", 21 | "multiplication_dense_sparse_01", 22 | "multiplication_dense_sparse_001", 23 | "multiplication_dense_sparse_0001", 24 | "multiplication_dense_dense", 25 | "multiplication_dense_ket", 26 | "multiplication_sparse_ket_01", 27 | "multiplication_sparse_ket_001", 28 | "multiplication_sparse_ket_0001", 29 | "multiplication_bra_dense", 30 | "multiplication_bra_sparse_01", 31 | "multiplication_bra_sparse_001", 32 | "multiplication_bra_sparse_0001", 33 | "coherentstate", 34 | "displace", 35 | "expect_operator", 36 | "expect_state", 37 | "variance_operator", 38 | "variance_state", 39 | "ptrace_operator", 40 | "ptrace_state", 41 | "qfunc_operator", 42 | "qfunc_state", 43 | "wigner_operator", 44 | "wigner_state", 45 | "timeevolution_master_cavity", 46 | "timeevolution_master_jaynescummings", 47 | "timeevolution_master_particle", 48 | "timeevolution_master_timedependent_cavity", 49 | "timeevolution_master_timedependent_jaynescummings", 50 | "timeevolution_master_timedependent_particle", 51 | "timeevolution_mcwf_cavity", 52 | "timeevolution_mcwf_jaynescummings", 53 | "timeevolution_mcwf_particle", 54 | "timeevolution_schroedinger_cavity", 55 | "timeevolution_schroedinger_jaynescummings", 56 | "timeevolution_schroedinger_particle", 57 | ] 58 | 59 | filenames = os.listdir("results") 60 | 61 | def extract_version(filename, testname): 62 | name, _ = os.path.splitext(filename) 63 | if name.endswith("]"): # For example timeevolution_particle[fft] 64 | name, variant = name.rsplit("[", 1) 65 | variant = "/" + variant[:-1] 66 | else: 67 | variant = "" 68 | assert name.startswith("results-"), name 69 | assert name.endswith("-" + testname), name 70 | return name[len("results-"):-len("-" + testname)] + variant 71 | 72 | def cutdigits(x): 73 | return float('%.3g' % (x)) 74 | 75 | for testname in names: 76 | print("Loading: ", testname) 77 | matches = filter(lambda x: testname in x, filenames) 78 | d = {} 79 | for filename in matches: 80 | version = extract_version(filename, testname) 81 | f = open("results/" + filename) 82 | # version_escaped = version.replace(".", "_") 83 | data = json.load(f) 84 | for point in data: 85 | point["t"] = cutdigits(point["t"]) 86 | d[version] = data 87 | f.close() 88 | path = "results-collected/" + testname + ".json" 89 | f = open(path, "w") 90 | json.dump(d, f) 91 | f.close() 92 | -------------------------------------------------------------------------------- /extract_code.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import subprocess 4 | 5 | matlabbenchmarks = "benchmarks-QuantumOpticsToolbox" 6 | juliabenchmarks = "benchmarks-QuantumOptics.jl" 7 | pythonbenchmarks = "benchmarks-QuTiP" 8 | 9 | outputdir = "sourcecode" 10 | 11 | if not os.path.exists(outputdir): 12 | os.makedirs(outputdir) 13 | 14 | template = """\ 15 | 16 | # ---------- 17 | # Setup code 18 | # ---------- 19 | N = 2 # Hilbert space cutoff parameter 20 | s = 0.1 # sparseness 21 | {setupcode} 22 | 23 | # -------------- 24 | # Benchmark code 25 | # -------------- 26 | {benchmarkcode} 27 | """ 28 | 29 | template_julia = """\ 30 | using QuantumOptics 31 | """ + template 32 | 33 | template_python = """\ 34 | {imports} 35 | """ + template 36 | 37 | def read(path): 38 | f = open(path) 39 | text = f.read() 40 | f.close() 41 | return text 42 | 43 | def write(name, text): 44 | outputpath = os.path.join(outputdir, name) 45 | f = open(outputpath, "w") 46 | f.write(text) 47 | f.close() 48 | 49 | def extract_julia_function(text, name): 50 | start = text.find("\n", text.find("function " + name)) 51 | end = text.find("\nend\n", start) 52 | code = text[start:end].replace("\n ", "\n")[1:] 53 | return code 54 | 55 | def extract_julia(path): 56 | text = read(path) 57 | return template_julia.format( 58 | setupcode = extract_julia_function(text, "setup").rsplit("\n", 1)[0], 59 | benchmarkcode = extract_julia_function(text, "f")) 60 | 61 | def extract_python_function(text, name): 62 | start = text.find("\n", text.find("def " + name)) 63 | end = text.find("\n", text.find("\n return", start)+1) 64 | code = text[start:end].replace("\n ", "\n")[1:] 65 | return code 66 | 67 | def extract_python_imports(text): 68 | return list(filter(lambda x: x.startswith("import") and not "benchmarkutils" in x, 69 | text.split("\n"))) 70 | 71 | 72 | def extract_python(path): 73 | text = read(path) 74 | imports = extract_python_imports(text) 75 | benchmarkcode = extract_python_function(text, "f") 76 | parts = benchmarkcode.rsplit("\n", 1) 77 | if len(parts) == 1: 78 | a = "" 79 | b = parts[0] 80 | else: 81 | a, b = parts 82 | a = a + "\n" 83 | benchmarkcode = a + b.replace("return ", "") 84 | return template_python.format( 85 | imports="\n".join(imports), 86 | setupcode=extract_python_function(text, "setup").rsplit("\n", 1)[0], 87 | benchmarkcode=benchmarkcode) 88 | 89 | def testjulia(name): 90 | outputpath = os.path.join(outputdir, name) 91 | subprocess.run(["julia", outputpath], check=True) 92 | 93 | def testpython(name): 94 | outputpath = os.path.join(outputdir, name) 95 | subprocess.run(["python3", outputpath], check=True) 96 | 97 | # Extract QuantumOptics.jl source code 98 | filenames = os.listdir(juliabenchmarks) 99 | for name in filenames: 100 | if "benchmarkutils" in name or not name.endswith(".jl"): 101 | continue 102 | print("Extract: ", name) 103 | sourcecode = extract_julia(os.path.join(juliabenchmarks, name)) 104 | write(name, sourcecode) 105 | print("Warning: Extracted julia code is not testd!") 106 | # testjulia(name) 107 | 108 | 109 | # Extract QuTiP source code 110 | filenames = os.listdir(pythonbenchmarks) 111 | for name in filenames: 112 | if "benchmarkutils" in name or not name.endswith(".py") or name=="__init__.py": 113 | continue 114 | print("Extract: ", name) 115 | sourcecode = extract_python(os.path.join(pythonbenchmarks, name)) 116 | write(name, sourcecode) 117 | print("Warning: Extracted python code is not testd!") 118 | # testpython(name) 119 | -------------------------------------------------------------------------------- /hardware_specs.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import json 3 | import sys 4 | 5 | output_path = "results/specs.json" 6 | 7 | specs = {} 8 | 9 | print("Running lspcu ...") 10 | data = subprocess.check_output(["lscpu"]) 11 | cpuinfo = data.decode(sys.getdefaultencoding()) 12 | cpuspecs = [] 13 | specs["cpu"] = cpuspecs 14 | 15 | for line in cpuinfo.split("\n"): 16 | if line: 17 | key, value = line.split(":") 18 | cpuspecs.append((key, value.strip())) 19 | 20 | 21 | print("Getting julia specs ...") 22 | data = subprocess.check_output(["julia", "-e", "import InteractiveUtils; InteractiveUtils.versioninfo()"]) 23 | juliainfo = data.decode(sys.getdefaultencoding()) 24 | juliaspecs = [] 25 | specs["julia"] = juliaspecs 26 | 27 | for line in juliainfo.split("\n"): 28 | if line: 29 | juliaspecs.append(line.strip()) 30 | 31 | print("Getting qutip specs ...") 32 | data = subprocess.check_output(["python3", "-c", "import qutip; qutip.about()"]) 33 | qutipinfo = data.decode(sys.getdefaultencoding()) 34 | qutipspecs = [] 35 | specs["qutip"] = qutipspecs 36 | 37 | for line in qutipinfo.split("\n")[4:]: 38 | if line: 39 | qutipspecs.append(line.strip()) 40 | 41 | 42 | f = open(output_path, "w") 43 | f.write(json.dumps(specs)) 44 | f.close() 45 | -------------------------------------------------------------------------------- /make.jl: -------------------------------------------------------------------------------- 1 | website = "../QuantumOptics.jl-website" 2 | @assert isdir(website) 3 | 4 | run(`python3 collect_results.py`) 5 | run(`python3 extract_code.py`) 6 | 7 | sourcecode_in = "sourcecode" 8 | sourcecode_out = joinpath(website, "src/_benchmarks-sourcecode/") 9 | data_in = "results-collected" 10 | data_out = joinpath(website, "src/benchmark-data/") 11 | 12 | cp(sourcecode_in, sourcecode_out; remove_destination=true) 13 | cp(data_in, data_out; remove_destination=true) 14 | -------------------------------------------------------------------------------- /plot_results.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import pylab 4 | 5 | sourcedir = "results-collected" 6 | 7 | 8 | def transform_version(points): 9 | Nvec = [] 10 | tvec = [] 11 | for x in points: 12 | Nvec.append(x["N"]) 13 | tvec.append(x["t"]) 14 | return Nvec, tvec 15 | 16 | 17 | def transform_json(d): 18 | data = [] 19 | for name, points in d.items(): 20 | data.append((name, transform_version(points))) 21 | data.sort(key=lambda x: x[0]) 22 | return data 23 | 24 | 25 | testnames = os.listdir(sourcedir) 26 | for testname in testnames: 27 | if testname.startswith("."): 28 | continue 29 | # if not "ptrace" in testname: 30 | # continue 31 | print("Open ", testname) 32 | f = open(os.path.join(sourcedir, testname)) 33 | d = json.load(f) 34 | f.close() 35 | data = transform_json(d) 36 | pylab.figure() 37 | for name, points in data: 38 | pylab.title(testname) 39 | pylab.plot(points[0], points[1], label=name) 40 | pylab.plot(points[0], points[1], "ok", alpha=0.4) 41 | pylab.legend() 42 | pylab.show() 43 | 44 | 45 | -------------------------------------------------------------------------------- /results-collected/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qojulia/QuantumOptics.jl-benchmarks/c3e7a1fdb60457fd21508cf8b04598420cc9d548/results-collected/.keep -------------------------------------------------------------------------------- /results/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qojulia/QuantumOptics.jl-benchmarks/c3e7a1fdb60457fd21508cf8b04598420cc9d548/results/.keep -------------------------------------------------------------------------------- /runall.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | 4 | matlabbenchmarks = "benchmarks-QuantumOpticsToolbox" 5 | juliabenchmarks = "benchmarks-QuantumOptics.jl" 6 | pythonbenchmarks = "benchmarks-QuTiP" 7 | 8 | subprocess.run(["python3", "hardware_specs.py"], check=True) 9 | 10 | os.chdir(juliabenchmarks) 11 | filenames = os.listdir(".") 12 | for name in filenames: 13 | if "benchmarkutils" in name or not name.endswith(".jl"): 14 | continue 15 | subprocess.run(["julia", name], check=True) 16 | os.chdir("..") 17 | # 18 | # os.chdir(pythonbenchmarks) 19 | # filenames = os.listdir(".") 20 | # for name in filenames: 21 | # if "benchmarkutils" in name or not name.endswith(".py"): 22 | # continue 23 | # subprocess.run(["python3", name], check=True) 24 | # os.chdir("..") 25 | # 26 | # os.chdir(matlabbenchmarks) 27 | # subprocess.run(["matlab", "-nodisplay", "-nosplash", "-nodesktop", "-r", 'run runall.m; quit;'], check=True) 28 | # os.chdir("..") 29 | --------------------------------------------------------------------------------