From f8d737dec21333cdc3228d2f51b022b3f4d8e125 Mon Sep 17 00:00:00 2001 From: Eric Giguere Date: Thu, 9 Jan 2025 13:49:24 -0500 Subject: [PATCH 1/4] Add a tridiagonal matrix to the benchmarks --- qutip_benchmark/benchmarks/bench_linear_algebra.py | 5 ++++- qutip_benchmark/benchmarks/bench_qobjevo.py | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/qutip_benchmark/benchmarks/bench_linear_algebra.py b/qutip_benchmark/benchmarks/bench_linear_algebra.py index 01b10a798..cddbb9e07 100644 --- a/qutip_benchmark/benchmarks/bench_linear_algebra.py +++ b/qutip_benchmark/benchmarks/bench_linear_algebra.py @@ -19,7 +19,7 @@ def size(request): return request.param -@pytest.fixture(params=["dense", "sparse"]) +@pytest.fixture(params=["dense", "sparse", "tridiag"]) def density(request): return request.param @@ -34,6 +34,9 @@ def left_oper(size, density, dtype): res = qutip.rand_herm(size, density=1 / size) elif density == "dense": res = qutip.rand_herm(size, density=1) + elif density == "tridiag": + a = qutip.destroy(size) + res = a + a.dag() + a*a.dag() if dtype == "numpy": return res.full() diff --git a/qutip_benchmark/benchmarks/bench_qobjevo.py b/qutip_benchmark/benchmarks/bench_qobjevo.py index 261ba3d52..667221a54 100644 --- a/qutip_benchmark/benchmarks/bench_qobjevo.py +++ b/qutip_benchmark/benchmarks/bench_qobjevo.py @@ -9,7 +9,7 @@ def size(request): return request.param -@pytest.fixture(params=["dense", "sparse"]) +@pytest.fixture(params=["dense", "sparse", "tridiag"]) def density(request): return request.param @@ -35,6 +35,10 @@ def left_QobjEvo(size, density, coeftype): elif density == "dense": q_obj = qutip.rand_herm(size, density=1) + elif density == "tridiag": + a = qutip.destroy(size) + res = a + a.dag() + a*a.dag() + # Creating coefficients tlist = None if coeftype == "function": From 0349b7c72243c729d4c202d9e2f01ee1dbfecee5 Mon Sep 17 00:00:00 2001 From: Eric Giguere Date: Fri, 10 Jan 2025 15:59:45 -0500 Subject: [PATCH 2/4] black modified files --- qutip_benchmark/benchmarks/bench_linear_algebra.py | 3 ++- qutip_benchmark/benchmarks/bench_qobjevo.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/qutip_benchmark/benchmarks/bench_linear_algebra.py b/qutip_benchmark/benchmarks/bench_linear_algebra.py index cddbb9e07..838ed7602 100644 --- a/qutip_benchmark/benchmarks/bench_linear_algebra.py +++ b/qutip_benchmark/benchmarks/bench_linear_algebra.py @@ -1,4 +1,5 @@ """This file contains the benchmarks that are run the benchmark.py script.""" + import pytest import qutip import scipy @@ -36,7 +37,7 @@ def left_oper(size, density, dtype): res = qutip.rand_herm(size, density=1) elif density == "tridiag": a = qutip.destroy(size) - res = a + a.dag() + a*a.dag() + res = a + a.dag() + a * a.dag() if dtype == "numpy": return res.full() diff --git a/qutip_benchmark/benchmarks/bench_qobjevo.py b/qutip_benchmark/benchmarks/bench_qobjevo.py index 667221a54..fe07fe47a 100644 --- a/qutip_benchmark/benchmarks/bench_qobjevo.py +++ b/qutip_benchmark/benchmarks/bench_qobjevo.py @@ -1,4 +1,5 @@ """This file contains the benchmarks that are run the benchmark.py script.""" + import pytest import qutip import numpy as np @@ -37,7 +38,7 @@ def left_QobjEvo(size, density, coeftype): elif density == "tridiag": a = qutip.destroy(size) - res = a + a.dag() + a*a.dag() + res = a + a.dag() + a * a.dag() # Creating coefficients tlist = None From cf4d7b987bbe0cb421a335dc83f5413495635589 Mon Sep 17 00:00:00 2001 From: Eric Giguere Date: Fri, 10 Jan 2025 16:01:55 -0500 Subject: [PATCH 3/4] Fix flake8 issue --- qutip_benchmark/benchmarks/bench_qobjevo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutip_benchmark/benchmarks/bench_qobjevo.py b/qutip_benchmark/benchmarks/bench_qobjevo.py index fe07fe47a..884a71a4c 100644 --- a/qutip_benchmark/benchmarks/bench_qobjevo.py +++ b/qutip_benchmark/benchmarks/bench_qobjevo.py @@ -38,7 +38,7 @@ def left_QobjEvo(size, density, coeftype): elif density == "tridiag": a = qutip.destroy(size) - res = a + a.dag() + a * a.dag() + q_obj = a + a.dag() + a * a.dag() # Creating coefficients tlist = None From 5f250f1dd8cf80b4323278894a0059735740f047 Mon Sep 17 00:00:00 2001 From: Eric Giguere Date: Fri, 10 Jan 2025 16:28:07 -0500 Subject: [PATCH 4/4] Do not try to use tridiag kets --- .../benchmarks/bench_linear_algebra.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/qutip_benchmark/benchmarks/bench_linear_algebra.py b/qutip_benchmark/benchmarks/bench_linear_algebra.py index 838ed7602..c9c5a2029 100644 --- a/qutip_benchmark/benchmarks/bench_linear_algebra.py +++ b/qutip_benchmark/benchmarks/bench_linear_algebra.py @@ -21,12 +21,17 @@ def size(request): @pytest.fixture(params=["dense", "sparse", "tridiag"]) -def density(request): +def density_oper(request): + return request.param + + +@pytest.fixture(params=["dense", "sparse"]) +def density_ket(request): return request.param @pytest.fixture() -def left_oper(size, density, dtype): +def left_oper(size, density_oper, dtype): """Return a random matrix of size `sizexsize'. Density is either 'dense' or 'sparse' and returns a fully dense or a sparse matrix respectively. The matrices are Hermitian.""" @@ -53,7 +58,7 @@ def left_oper(size, density, dtype): @pytest.fixture() -def right_oper(size, density, dtype): +def right_oper(size, density_oper, dtype): """Return a random matrix of size `sizexsize'. Density is either 'dense' or 'sparse' and returns a fully dense or a sparse matrix respectively. The matrices are Hermitian.""" @@ -62,6 +67,9 @@ def right_oper(size, density, dtype): res = qutip.rand_herm(size, density=1 / size) elif density == "dense": res = qutip.rand_herm(size, density=1) + elif density == "tridiag": + a = qutip.destroy(size) + res = a + a.dag() + a * a.dag() if dtype == "numpy": return res.full() @@ -77,7 +85,7 @@ def right_oper(size, density, dtype): @pytest.fixture() -def right_ket(size, density, dtype): +def right_ket(size, density_ket, dtype): if density == "sparse": res = qutip.rand_ket(size, density=0.3) else: