Scan your whole stack
From OX Research Newsroom
Are you using optican?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v0.1.0
optican was last scanned on 23 Nov 2026 at version 0.1.0. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 0.1.0 LATEST | 23 Nov 2026 | No rules fired |
Findings for v0.1.0. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 0.1.0; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
OptiCan is a lightweight, framework-agnostic hyperparameter optimization library. It searches continuous, integer, categorical, Boolean, and fixed parameter spaces with adaptive elite-guided refinement.
OptiCan does not require PyTorch, TensorFlow, scikit-learn, NumPy, or another machine-learning framework. You provide an objective function that trains and validates your model. OptiCan searches the configuration values passed to that function.
The current release is 0.1.0. The API may change before the first stable release. The search is a heuristic and does not guarantee a global optimum.
install it with:
pip install optican
For local development:
python -m pip install -e ".[dev]"
pytest
An objective receives a configuration dictionary and optionally a seed. It returns one numeric validation metric. The default direction is "min", which is useful for loss and error metrics.
from optican import OptiCan, Float, Int, Choice, Bool
def objective(config, seed):
validation_loss = train_and_validate(
learning_rate=config["learning_rate"],
batch_size=config["batch_size"],
weight_decay=config["weight_decay"],
optimizer=config["optimizer"],
use_scheduler=config["use_scheduler"],
seed=seed,
)
return validation_loss
search = OptiCan(
objective=objective,
config={
"learning_rate": Float(1e-5, 1e-2, log=True),
"batch_size": Choice([32, 64, 128, 256]),
"weight_decay": Float(1e-7, 1e-2, log=True, allow_zero=True),
"optimizer": Choice(["AdamW", "Adam", "SGD"]),
"use_scheduler": Bool(),
},
rounds=3,
ubest=False,
)
last_round_config = search.optimize()
print(last_round_config)
ubest=False returns the best configuration from the latest completed round that produced a successful trial. This is useful when you want to inspect what the newest refinement round found.
ubest=True returns a TuningResult. Its best_config, best_trial, and best_score refer to the best result across all rounds.
The full result is available as search.result in both modes. It keeps the global best and the latest successful round best:
print(search.result.best_config)
print(search.result.best_score)
print(search.result.last_round_best_config)
print(search.result.last_round_best_score)
print(search.result.summary())
for trial in search.result.trials:
print(trial.config, trial.mean_score, trial.std_score, trial.error)
If the latest round has no successful trials, OptiCan uses the best result from the latest earlier round that had a successful trial. A fixed-only search or an empty configuration is evaluated once.
Use helper classes for explicit search spaces:
| Type | Example | Behavior |
|---|---|---|
| Float | Float(1e-5, 1e-2) |
Samples a continuous range |
| Log float | Float(1e-5, 1e-2, log=True) |
Samples uniformly in log10 space |
| Zero-capable float | Float(1e-7, 1e-2, log=True, allow_zero=True) |
Adds exact zero as a separate option |
| Integer | Int(16, 256, step=16) |
Samples integer values on a stepped range |
| Categorical | Choice(["Adam", "AdamW"]) |
Learns category probabilities |
| Boolean | Bool() |
Learns probabilities for True and False |
| Fixed | Fixed("gelu") |
Keeps a value unchanged |
A list or tuple is treated as a categorical choice. Any other scalar is treated as a fixed value. An empty config={} is valid and evaluates the objective once with an empty configuration.
Compact dictionary definitions are also supported:
config = {
"learning_rate": {
"type": "float",
"low": 1e-5,
"high": 1e-2,
"log": True,
},
"depth": {"type": "int", "low": 2, "high": 12},
"optimizer": {"type": "choice", "values": ["Adam", "AdamW"]},
"use_dropout": {"type": "bool"},
"activation": ["relu", "gelu", "silu"],
"device": "cuda",
}
| Option | Default | Meaning |
|---|---|---|
rounds |
3 |
Total search rounds, including the initial round |
initial_candidates |
24 |
Configurations sampled in the first round |
candidates_per_round |
12 |
New configurations in each later round |
elite_size |
20 |
Top configurations used to guide refinement |
seeds |
1 |
Number of shared seeds used per configuration |
seed |
42 |
Base seed, later seeds increase by one |
direction |
"min" |
Use "max" for metrics such as accuracy or F1 |
stability_penalty |
0.25 |
Penalty for score variation across seeds |
mutation_rate |
0.70 |
Chance of mutating each parameter in a child |
exploration_mix |
0.20 |
Fraction sampled independently of elite parents |
categorical_exploration |
0.15 |
Keeps category sampling from collapsing too early |
shrink_fraction |
0.20 |
Fraction of the active numeric range contracted per round |
min_range_fraction |
0.05 |
Minimum range width relative to its initial width |
max_trials |
None |
Optional cap on evaluated configurations |
patience_rounds |
0 |
Stop after this many stagnant rounds, zero disables it |
min_delta |
0.0 |
Minimum improvement needed to reset patience |
ubest |
False |
Selects the latest-round config or returns the full global result |
verbose |
True |
Prints progress while evaluating candidates |
catch_exceptions |
True |
Records failed evaluations and continues |
Use seeds=1 for faster tests. Increase it to 3 or 5 for more stable comparisons. The same seed set is used for every configuration.
OptiCan evaluates candidates sequentially by default. This avoids global random-seed interference and unexpected GPU memory use across different frameworks. Reduce candidate counts, use max_trials, or add early stopping inside the objective to reduce evaluation time.
A separate metric="t/a" option is not needed. The objective function already provides a flexible way to calculate any metric. Compute the values your formula needs and return the result.
def objective(config, seed):
predictions = train_and_predict(config, seed)
t = count_true_predictions(predictions)
a = count_all_predictions(predictions)
return t / max(a, 1)
The objective can calculate a single metric, combine several metrics, or call an existing scoring function. OptiCan only needs the final numeric result. Set direction="max" when higher values are better.
OptiCan does not create or manage models itself. Put model creation, training, early stopping, and validation inside the objective. Replace Model and the data variables with your own objects.
import random
import numpy as np
import torch
import torch.nn as nn
from torch.utils.data import DataLoader, TensorDataset
from optican import OptiCan, Float, Choice, Bool
def objective(config, seed):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(seed)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = Model().to(device)
optimizer_class = getattr(torch.optim, config["optimizer"])
optimizer = optimizer_class(
model.parameters(),
lr=config["learning_rate"],
weight_decay=config["weight_decay"],
)
loss_fn = nn.CrossEntropyLoss()
scheduler = None
if config["use_scheduler"]:
scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=20)
loader = DataLoader(
TensorDataset(X_train, y_train),
batch_size=config["batch_size"],
shuffle=True,
)
best_val_loss = float("inf")
for _ in range(20):
model.train()
for x, y in loader:
x, y = x.to(device), y.to(device)
optimizer.zero_grad(set_to_none=True)
loss = loss_fn(model(x), y)
loss.backward()
optimizer.step()
model.eval()
with torch.no_grad():
val_loss = loss_fn(
model(X_valid.to(device)),
y_valid.to(device),
).item()
best_val_loss = min(best_val_loss, val_loss)
if scheduler is not None:
scheduler.step()
return best_val_loss
search = OptiCan(
objective,
config={
"learning_rate": Float(1e-5, 3e-3, log=True),
"weight_decay": Float(1e-7, 1e-2, log=True, allow_zero=True),
"batch_size": Choice([32, 64, 128, 256]),
"optimizer": Choice(["AdamW", "Adam"]),
"use_scheduler": Bool(),
},
rounds=3,
seeds=3,
ubest=True,
)
result = search.optimize()
print(result.best_config)
print(result.best_score)
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
from optican import OptiCan, Int, Choice
def objective(config, seed):
estimator = RandomForestClassifier(
n_estimators=config["n_estimators"],
max_depth=config["max_depth"],
criterion=config["criterion"],
random_state=seed,
n_jobs=-1,
)
return cross_val_score(
estimator, X, y, cv=5, scoring="accuracy", n_jobs=-1
).mean()
search = OptiCan(
objective,
config={
"n_estimators": Int(100, 600, step=50),
"max_depth": Choice([None, 5, 10, 20, 30]),
"criterion": Choice(["gini", "entropy", "log_loss"]),
},
direction="max",
rounds=3,
)
best_config = search.optimize()
This is an adaptive heuristic. It can miss a global optimum, especially with narrow ranges, noisy objectives, strong parameter interactions, or too few evaluations. Use a suitable evaluation budget and validation split.
python -m pip install -e ".[dev]"
pytest
ruff check src tests examples
python -m build
python -m twine check dist/*
MIT. See LICENSE.
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.