This is the official repository for the paper: "Quantum Variational Activation Functions Empower Kolmogorov-Arnold Networks"
📖 Documentation: https://qkan.jimq.cc/
We provide a PyTorch implementation of QKAN with:
- Pre- and post-activation processing support
- Grouped QVAFs for efficient training
- Plot the nodes and pruning unnecessary nodes
- Layer extension for more complex features
- and more ...
A basic PennyLane version of the quantum circuit is also included for demonstration, but not optimized for performance.
You can install QKAN using pip:
pip install qkan
If you want to install the latest development version, you can use:
pip install git+https://github.com/Jim137/qkan.git
To install QKAN from source, you can use the following command:
git clone https://github.com/Jim137/qkan.git && cd qkan
pip install -e .
It is recommended to use a virtual environment to avoid conflicts with other packages.
python -m venv qkan-env
source qkan-env/bin/activate # On Windows: qkan-env\Scripts\activate
pip install qkan
Here's a minimal working example for function fitting using QKAN:
import torch
from qkan import QKAN, create_dataset
device = "cuda" if torch.cuda.is_available() else "cpu"
f = lambda x: torch.sin(20*x)/x/20 # J_0(20x)
dataset = create_dataset(f, n_var=1, ranges=[0,1], device=device, train_num=1000, test_num=1000, seed=0)
qkan = QKAN(
[1, 1],
reps=3,
device=device,
seed=0,
preact_trainable=True,
postact_weight_trainable=True,
postact_bias_trainable=True,
ba_trainable=True,
save_act=True, # enable to plot from saved activation
)
optimizer = torch.optim.LBFGS(qkan.parameters(), lr=5e-2)
qkan.train_(
dataset,
steps=100,
optimizer=optimizer,
reg_metric="edge_forward_dr_n",
)
qkan.plot(from_acts=True, metric=None)
You can find more examples in the examples for different tasks, such as function fitting, classification, and generative modeling.
We are very welcome to all kinds of contributions, including but not limited to bug reports, documentation improvements, and code contributions.
To start contributing, please fork the repository and create a new branch for your feature or bug fix. Then, submit a pull request with a clear description of your changes.
In your environment, you can install the development dependencies with:
pip install .[dev] # install development dependencies
pip install .[doc] # install documentation dependencies
pip install .[all] # install all optional dependencies
@article{jiang2025qkan,
title={Quantum Variational Activation Functions Empower Kolmogorov-Arnold Networks},
author={Jiang, Jiun-Cheng and Huang, Yu-Chao and Chen, Tianlong and Goan, Hsi-Sheng},
journal={arXiv preprint arXiv:2509.14026},
year={2025},
url={https://arxiv.org/abs/2509.14026}
}