Files
faiss/benchs/bench_fw_range.py
T
Tia Lim 0f0f728166 Format faiss Python files with black (line length 80) (#5349)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5349

# this is a no-op change

Ran `black -l 80` over all tracked Python files under `fbcode/faiss/`, using line length 80 to match faiss's documented coding style (`CONTRIBUTING.md`: "80 character line length (both for C++ and Python)"). 172 files were reformatted; 28 were already compliant.

This is a pure-formatting change. `black` runs its AST-equivalence safety check on every file, so no identifiers, string/numeric values, operators, or control flow were altered — only whitespace, indentation, line wrapping, blank lines, trailing commas, and string-quote normalization (single to double quotes).

`fbcode/faiss/` is intentionally excluded from Meta's standard Python autoformatter (`arc f` / `arc lint -a` report no formatter for these paths) because it mirrors to public GitHub, so the Python had drifted out of any consistent style. The C++ is already clang-format-clean (0 of 807 files change), so this effort is Python-only. This diff brings the Python to canonical `black` formatting.

Excluded `demos/index_pq_flat_separate_codes_from_codebook.py`: it contains a Jupyter `!rm` shell-magic line and is not valid Python, so `black` cannot parse it.

This is the base of a 3-diff stack: (1) this black reformat; (2) `.flake8` alignment (max-line-length 80 + black-compatible ignores E203/W503); (3) genuine lint fixes (F401/F403/F841/B011).

Reviewed By: mnorris11

Differential Revision: D109736099

fbshipit-source-id: 9a054635766ed11aa3760a788395babd3d198abf
2026-06-29 17:29:05 -07:00

96 lines
2.7 KiB
Python

# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import logging
import os
from faiss.benchs.bench_fw.benchmark import Benchmark
from faiss.benchs.bench_fw.benchmark_io import BenchmarkIO
from faiss.benchs.bench_fw.descriptors import (
DatasetDescriptor,
IndexDescriptorClassic,
)
logging.basicConfig(level=logging.INFO)
def ssnpp(bio):
benchmark = Benchmark(
num_threads=32,
training_vectors=DatasetDescriptor(
tablename="training.npy",
),
database_vectors=DatasetDescriptor(
tablename="database.npy",
),
query_vectors=DatasetDescriptor(tablename="query.npy"),
index_descs=[
IndexDescriptorClassic(
factory="Flat",
range_metrics={
"weighted": [
[0.05, 0.971],
[0.1, 0.956],
[0.15, 0.923],
[0.2, 0.887],
[0.25, 0.801],
[0.3, 0.729],
[0.35, 0.651],
[0.4, 0.55],
[0.45, 0.459],
[0.5, 0.372],
[0.55, 0.283],
[0.6, 0.189],
[0.65, 0.143],
[0.7, 0.106],
[0.75, 0.116],
[0.8, 0.088],
[0.85, 0.064],
[0.9, 0.05],
[0.95, 0.04],
[1.0, 0.028],
[1.05, 0.02],
[1.1, 0.013],
[1.15, 0.007],
[1.2, 0.004],
[1.3, 0],
]
},
),
IndexDescriptorClassic(
factory="IVF262144(PQ256x4fs),PQ32",
),
],
k=10,
distance_metric="L2",
range_ref_index_desc="Flat",
)
benchmark.set_io(bio)
benchmark.benchmark(
"result.json",
local=False,
train=True,
reconstruct=False,
knn=False,
range=True,
)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("experiment")
parser.add_argument("path")
args = parser.parse_args()
assert os.path.exists(args.path)
path = os.path.join(args.path, args.experiment)
if not os.path.exists(path):
os.mkdir(path)
bio = BenchmarkIO(
path=path,
)
if args.experiment == "ssnpp":
ssnpp(bio)