Files
zeekay e037e8f7ea torus: one name for the package, and it is ours
The distribution called itself torus-ml while shipping a package directory
named concrete, so the name a user installs and the name they import disagreed
— and most of the tree already said torus.ml, which could not resolve against
src/concrete. Moved src/concrete to src/torus and pointed the include at it.

The dependency was Zama's concrete-python from their index. It is torus-fhe
from ours, which is what luxfhe/torus already ships: that frontend declares
torus-fhe and ships a torus/fhe module, so every 'from torus.fhe' in this tree
was already naming our compiler and only the dependency lagged.

Two distributions share one namespace, which is the shape the upstream this
forked from used and the reason the split works: torus-fhe gives torus.fhe,
torus-ml gives torus.ml.

Swept every other spelling — identifiers, enum members, workflow variables,
filenames, notebooks. LICENSE and NOTICE keep the upstream attribution a fork
owes; the figures carry the old name in JPEG metadata a text sweep cannot
reach.
2026-08-27 13:20:50 -07:00

54 lines
2.1 KiB
Python

import pickle
from pathlib import Path
import federated_utils
import numpy
from torus.ml.sklearn import LogisticRegression
if __name__ == "__main__":
# Load scikit-learn model
path_to_model = Path("./model.pkl")
if not path_to_model.exists() or not path_to_model.is_file():
raise ValueError(
"Couldn't find file 'model.pkl'.\n"
"Please run 'run.sh' to train the model with federated learning."
)
with path_to_model.open("rb") as file:
sklearn_model = pickle.load(file)
# Compile model without data since the server doesn't have access to it
# Indeed in this scenario the users have the data but the server doesn't.
# We then have to compile the model using random input sampled with the same
# low and high bounds as the real data, in this context [0, 255].
number_of_compile_samples = 1000
compile_set = numpy.random.randint(0, 255, (number_of_compile_samples, 784)).astype(float)
sklearn_model.classes_ = sklearn_model.classes_.astype(int)
model = LogisticRegression.from_sklearn_model(sklearn_model, compile_set)
model.compile(compile_set)
# Evaluate the model
# Load MNIST dataset from https://www.openml.org/d/554
(_, _), (X_test, y_test) = federated_utils.load_mnist()
torus_predictions = model.predict(X_test)
sklearn_predictions = sklearn_model.predict(X_test)
simulation_predictions = model.predict(X_test, fhe="simulate")
print(
(torus_predictions == sklearn_predictions).sum() / len(y_test),
"quantized vs scikit-learn",
)
print(
(torus_predictions == simulation_predictions).sum() / len(y_test),
"quantized vs simulation",
)
print(
(simulation_predictions == sklearn_predictions).sum() / len(y_test),
"simulation vs scikit-learn",
)
print((torus_predictions == y_test).sum() / len(y_test), "quantized accuracy")
print((sklearn_predictions == y_test).sum() / len(y_test), "scikit-learn accuracy")
print((simulation_predictions == y_test).sum() / len(y_test), "simulation accuracy")