From 39bba19e9b5b905b6d8d19b3f77606b47b4d0dd4 Mon Sep 17 00:00:00 2001 From: "Kevin J. Sung" Date: Tue, 9 Apr 2024 04:16:10 -0400 Subject: [PATCH] remove asv benchmarks (#132) --- asv.conf.json | 31 -------- benchmarks/__init__.py | 9 --- benchmarks/fermion_operator.py | 40 ---------- benchmarks/gates.py | 132 --------------------------------- benchmarks/rust.py | 106 -------------------------- pyproject.toml | 1 - 6 files changed, 319 deletions(-) delete mode 100644 asv.conf.json delete mode 100644 benchmarks/__init__.py delete mode 100644 benchmarks/fermion_operator.py delete mode 100644 benchmarks/gates.py delete mode 100644 benchmarks/rust.py diff --git a/asv.conf.json b/asv.conf.json deleted file mode 100644 index bc69f317c..000000000 --- a/asv.conf.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "version": 1, - "project": "ffsim", - "project_url": "https://github.com/qiskit-community/ffsim", - "repo": ".", - "build_command": [ - "python -m pip install build maturin", - "python -m build", - "PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}" - ], - "branches": [ - "main" - ], - "dvcs": "git", - "environment_type": "virtualenv", - "show_commit_url": "http://github.com/qiskit-community/ffsim/commit/", - "pythons": [ - "3.10" - ], - "matrix": { - "env_nobuild": { - "RAYON_NUM_THREADS": "1", - "OMP_NUM_THREADS": "1", - "OPENBLAS_NUM_THREADS": "1", - "MKL_NUM_THREADS": "1" - } - }, - "env_dir": ".asv/env", - "results_dir": ".asv/results", - "html_dir": ".asv/html" -} \ No newline at end of file diff --git a/benchmarks/__init__.py b/benchmarks/__init__.py deleted file mode 100644 index 8b593392d..000000000 --- a/benchmarks/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -# (C) Copyright IBM 2023. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. diff --git a/benchmarks/fermion_operator.py b/benchmarks/fermion_operator.py deleted file mode 100644 index 35eff6d9a..000000000 --- a/benchmarks/fermion_operator.py +++ /dev/null @@ -1,40 +0,0 @@ -# (C) Copyright IBM 2023. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - -import numpy as np - -from ffsim import FermionOperator - - -class FermionOperatorBenchmark: - """Benchmark FermionOperator.""" - - def setup(self): - norb = 50 - n_terms = 100 - rng = np.random.default_rng() - - coeffs = {} - for _ in range(n_terms): - term_length = int(rng.integers(1, norb + 1)) - actions = [bool(i) for i in rng.integers(2, size=term_length)] - spins = [bool(i) for i in rng.integers(2, size=term_length)] - indices = [int(i) for i in rng.integers(norb, size=term_length)] - coeff = rng.standard_normal() + 1j * rng.standard_normal() - fermion_action = tuple(zip(actions, spins, indices)) - if fermion_action in coeffs: - coeffs[fermion_action] += coeff - else: - coeffs[fermion_action] = coeff - - self.op = FermionOperator(coeffs) - - def time_normal_order(self): - self.op.normal_ordered() diff --git a/benchmarks/gates.py b/benchmarks/gates.py deleted file mode 100644 index 8cca24195..000000000 --- a/benchmarks/gates.py +++ /dev/null @@ -1,132 +0,0 @@ -# (C) Copyright IBM 2023. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - -import numpy as np - -import ffsim - - -class GatesBenchmark: - """Benchmark gates.""" - - param_names = [ - "norb", - "filling_fraction", - ] - params = [ - (4, 8, 12), - (0.25, 0.5), - ] - - def setup(self, norb: int, filling_fraction: float): - self.norb = norb - nocc = int(norb * filling_fraction) - self.nelec = (nocc, nocc) - - rng = np.random.default_rng() - - self.vec = ffsim.random.random_statevector( - ffsim.dim(self.norb, self.nelec), seed=rng - ) - self.orbital_rotation = ffsim.random.random_unitary(self.norb, seed=rng) - self.orbital_energies = rng.uniform(-1.0, 1.0, size=self.norb) - self.diag_coulomb_mat = ffsim.random.random_real_symmetric_matrix( - self.norb, seed=rng - ) - ffsim.init_cache(self.norb, self.nelec) - - def time_apply_orbital_rotation_givens(self, *_): - ffsim.apply_orbital_rotation( - self.vec, - self.orbital_rotation, - norb=self.norb, - nelec=self.nelec, - copy=False, - ) - - def time_apply_orbital_rotation_lu(self, *_): - ffsim.apply_orbital_rotation( - self.vec, - self.orbital_rotation, - norb=self.norb, - nelec=self.nelec, - allow_col_permutation=True, - copy=False, - ) - - def time_apply_num_op_sum_evolution(self, *_): - ffsim.apply_num_op_sum_evolution( - self.vec, - self.orbital_energies, - time=1.0, - norb=self.norb, - nelec=self.nelec, - copy=False, - ) - - def time_apply_diag_coulomb_evolution(self, *_): - ffsim.apply_diag_coulomb_evolution( - self.vec, - self.diag_coulomb_mat, - time=1.0, - norb=self.norb, - nelec=self.nelec, - copy=False, - ) - - def time_apply_givens_rotation(self, *_): - ffsim.apply_givens_rotation( - self.vec, - theta=1.0, - target_orbs=(0, 2), - norb=self.norb, - nelec=self.nelec, - copy=False, - ) - - def time_apply_num_interaction(self, *_): - ffsim.apply_num_interaction( - self.vec, - theta=1.0, - target_orb=1, - norb=self.norb, - nelec=self.nelec, - copy=False, - ) - - def time_apply_num_num_interaction(self, *_): - ffsim.apply_num_num_interaction( - self.vec, - theta=1.0, - target_orbs=(0, 1), - norb=self.norb, - nelec=self.nelec, - copy=False, - ) - - def time_apply_num_op_prod_interaction(self, *_): - ffsim.apply_num_op_prod_interaction( - self.vec, - theta=1.0, - target_orbs=([1], [0]), - norb=self.norb, - nelec=self.nelec, - copy=False, - ) - - def time_apply_tunneling_interaction(self, *_): - ffsim.apply_tunneling_interaction( - self.vec, - theta=1.0, - target_orbs=(0, 2), - norb=self.norb, - nelec=self.nelec, - copy=False, - ) diff --git a/benchmarks/rust.py b/benchmarks/rust.py deleted file mode 100644 index fa336b1ba..000000000 --- a/benchmarks/rust.py +++ /dev/null @@ -1,106 +0,0 @@ -# (C) Copyright IBM 2023. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - -import numpy as np -import scipy.linalg - -import ffsim -from ffsim._lib import ( - apply_givens_rotation_in_place, - apply_single_column_transformation_in_place, -) -from ffsim._slow.gates.orbital_rotation import ( - apply_givens_rotation_in_place_slow, - apply_single_column_transformation_in_place_slow, -) -from ffsim.gates.orbital_rotation import ( - _zero_one_subspace_indices, - gen_orbital_rotation_index, -) - - -class RustBenchmark: - """Benchmark Rust functions.""" - - param_names = [ - "norb", - "filling_fraction", - ] - params = [ - (4, 8, 12), - (0.25, 0.5), - ] - - def setup(self, norb: int, filling_fraction: float): - self.norb = norb - nocc = int(norb * filling_fraction) - self.nelec = (nocc, nocc) - - rng = np.random.default_rng() - - self.vec = ffsim.random.random_statevector( - ffsim.dim(self.norb, self.nelec), seed=rng - ) - dim_a, dim_b = ffsim.dims(self.norb, self.nelec) - self.vec_as_mat = self.vec.reshape((dim_a, dim_b)) - - indices = _zero_one_subspace_indices(self.norb, self.nelec[0], (1, 2)) - self.slice1 = indices[: len(indices) // 2] - self.slice2 = indices[len(indices) // 2 :] - - orbital_rotation = ffsim.random.random_unitary(self.norb, seed=rng) - _, lower, upper = scipy.linalg.lu(orbital_rotation.T.conj()) - eye = np.eye(norb, dtype=complex) - self.transformation_mat = ( - eye - lower + scipy.linalg.solve_triangular(upper, eye) - ) - ( - self.diag_strings, - self.off_diag_strings, - self.off_diag_index, - ) = gen_orbital_rotation_index(self.norb, nocc) - - def time_apply_givens_rotation_in_place_python(self, *_): - apply_givens_rotation_in_place_slow( - self.vec_as_mat, - c=0.5, - s=(1j) ** 0.5 * np.sqrt(0.75), - slice1=self.slice1, - slice2=self.slice2, - ) - - def time_apply_givens_rotation_in_place_rust(self, *_): - apply_givens_rotation_in_place( - self.vec_as_mat, - c=0.5, - s=(1j) ** 0.5 * np.sqrt(0.75), - slice1=self.slice1, - slice2=self.slice2, - ) - - def time_apply_single_column_transformation_in_place_python(self, *_): - apply_single_column_transformation_in_place_slow( - self.vec_as_mat, - self.transformation_mat[:, 0], - diag_val=self.transformation_mat[0, 0], - diag_strings=self.diag_strings[0], - off_diag_strings=self.off_diag_strings[0], - off_diag_index=self.off_diag_index[0], - ) - - def time_apply_single_column_transformation_in_place_rust(self, *_): - apply_single_column_transformation_in_place( - self.vec_as_mat, - self.transformation_mat[:, 0], - diag_val=self.transformation_mat[0, 0], - diag_strings=self.diag_strings[0], - off_diag_strings=self.off_diag_strings[0], - off_diag_index=self.off_diag_index[0], - ) diff --git a/pyproject.toml b/pyproject.toml index ac9701187..7c95d4c5e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,6 @@ Documentation = "https://qiskit-community.github.io/ffsim/" [project.optional-dependencies] dev = [ - "asv", "coverage", "furo", "maturin",