API Reference
This page contains the complete API reference for QKAN.
Core Module
- class qkan.DARUAN(dim, reps, device='cpu', solver='exact', ansatz='pz_encoding', preact_trainable=False, postact_weight_trainable=False, postact_bias_trainable=False, seed=0)[source]
Bases:
Module- forward(x)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class qkan.KAN(layers_hidden, grid_size=5, spline_order=3, scale_noise=0.1, scale_base=1.0, scale_spline=1.0, base_activation=<class 'torch.nn.modules.activation.SiLU'>, grid_eps=0.02, grid_range=[-1, 1], device='cpu', seed=0, **kwargs)[source]
Bases:
ModuleKAN (Kolmogorov-Arnold Network) model. This is an efficient implementation of the KAN model, which is a neural network that uses B-spline as the learnable variational activation function.
It can be used for regression tasks and can be initialized from a QKAN model.
- forward(x, update_grid=False)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class qkan.QKAN(width, reps=3, group=-1, is_map=False, is_batchnorm=False, hidden=0, device='cpu', solver='exact', qml_device='default.qubit', ansatz='pz_encoding', theta_size=None, norm_out=0, preact_trainable=False, preact_init=False, postact_weight_trainable=False, postact_bias_trainable=False, base_activation=SiLU(), ba_trainable=False, fast_measure=True, save_act=False, c_dtype=torch.complex64, p_dtype=torch.float32, seed=None, solver_kwargs=None, **kwargs)[source]
Bases:
ModuleQuantum-inspired Kolmogorov Arnold Network (QKAN) Class
A quantum-inspired neural network that uses DatA Re-Uploading ActivatioN (DARUAN) as its learnable variation activation function.
References
Quantum Variational Activation Functions Empower Kolmogorov-Arnold Networks: https://arxiv.org/abs/2509.14026
- device
Device to use
- Type:
Literal[“cpu”, “cuda”]
- solver
Solver to use, currently supports “qml”, “exact”, “flash”, “cutn” or custom callable
- Type:
Union[str, Callable]
- layers
List of layers
- Type:
QKANModuleList
- base_activation
Base activation function
- Type:
torch.nn.Module or lambda function
- fast_measure
Enable to use fast measurement in exact solver. Which would be quantum-inspired method. When False, the exact solver simulates the exact measurement process of quantum circuit.
- Type:
- to(*args, **kwargs)[source]
Move the model to the specified device.
- Parameters:
device (str | torch.device) – Device to move the model to, default: “cpu”
- property param_size
- forward(x)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- initialize_from_another_model(another_model)[source]
Initialize from another model. Used for layer extension to refine the model.
- Parameters:
another_model (QKAN) – Another model to initialize from
- refine(new_reps)[source]
Refine the model by layer extension, increasing the number of repetitions of quantum layers.
- layer_extension(new_reps)[source]
Refine the model by layer extension, increasing the number of repetitions of quantum layers.
- get_reg(reg_metric, lamb_l1, lamb_entropy, lamb_coef, lamb_coefdiff)[source]
Get regularization from the model.
Adapted from “pykan”.
- Parameters:
reg_metric (str) – Regularization metric. ‘edge_forward_dr_n’, ‘edge_forward_dr_u’, ‘edge_forward_sum’, ‘edge_backward’, ‘node_backward’
lamb_l1 (float) – L1 Regularization parameter
lamb_entropy (float) – Entropy Regularization parameter
lamb_coef (float) – Coefficient Regularization parameter
lamb_coefdiff (float) – Coefficient Smoothness Regularization parameter
- Returns:
torch.Tensor
- attribute(l=None, i=None, out_score=None, plot=True)[source]
Get attribution scores
Adapted from “pykan”.
- train_(dataset, optimizer=None, closure=None, scheduler=None, steps=10, log=1, loss_fn=None, batch=-1, lamb=0.0, lamb_l1=1.0, lamb_entropy=2.0, lamb_coef=0.0, lamb_coefdiff=0.0, reg_metric='edge_forward_dr_n', verbose=True)[source]
Train the model
- Parameters:
dataset (dict) – Dictionary containing train_input, train_label, test_input, test_label
optimizer (torch.optim.Optimizer | None) – Optimizer to use, default: None
closure (Callable | None) – Closure function for optimizer, default: None
scheduler (torch.optim.lr_scheduler | None) – Scheduler to use, default: None
steps (int) – Number of steps, default: 10
log (int) – Logging frequency, default: 1
loss_fn (torch.nn.Module | Callable |None) – Loss function to use, default: None
batch (int) – batch size, if -1 then full., default: -1
lamb (float) – L1 Regularization parameter. If 0, no regularization.
lamb_l1 (float) – L1 Regularization parameter
lamb_entropy (float) – Entropy Regularization parameter
lamb_coef (float) – Coefficient Regularization parameter
lamb_coefdiff (float) – Coefficient Smoothness Regularization parameter
reg_metric (str) – Regularization metric. ‘edge_forward_dr_n’, ‘edge_forward_dr_u’, ‘edge_forward_sum’, ‘edge_backward’, ‘node_backward’
verbose (bool) – Verbose mode, default: True
- Returns:
- dict
Dictionary containing train_loss and test_loss
- plot(x0=None, sampling=1000, from_acts=False, scale=0.5, beta=3, metric='forward_n', mask=False, in_vars=None, out_vars=None, title=None)[source]
Plot the model.
Adapted from “pykan”.
- Parameters:
x0 (torch.Tensor | None) – Input tensor to plot, if None, plot from saved activations
sampling (int) – Sampling frequency
from_acts (bool) – Plot from saved activations
scale (float) – Scale of the plot
beta (float) – Beta value
metric (str) – Metric to use. ‘forward_n’, ‘forward_u’, ‘backward’
title (str | None) – Title of the plot
- prune_node(threshold=0.01, mode='auto', active_neurons_id=None)[source]
Pruning nodes.
Adapted from “pykan”.
- Parameters:
- Returns:
- QKAN
pruned network
- prune_edge(threshold=0.03)[source]
Pruning edges.
Adapted from “pykan”.
- Parameters:
threshold (
float) – float if the attribution score of an edge is below the threshold, it is considered dead and will be set to zero.
- remove_edge(layer_idx, in_idx, out_idx)[source]
Remove activtion phi(layer_idx, in_idx, out_idx) (set its mask to zero)
- remove_node(layer_idx, in_idx, mode='all')[source]
remove neuron (layer_idx, in_idx) (set the masks of all incoming and outgoing activation functions to zero)
- static clear_ckpts(folder='./model_ckpt')[source]
Clear all checkpoints.
- Parameters:
folder (str) – Folder containing checkpoints, default: “./model_ckpt”
- class qkan.QKANLayer(in_dim, out_dim, reps=3, group=-1, device='cpu', solver='exact', qml_device='default.qubit', ansatz='pz_encoding', theta_size=None, preact_trainable=False, preact_init=False, postact_weight_trainable=False, postact_bias_trainable=False, base_activation=SiLU(), ba_trainable=True, is_batchnorm=False, fast_measure=True, c_dtype=torch.complex64, p_dtype=torch.float32, seed=None, solver_kwargs=None)[source]
Bases:
ModuleQKANLayer Class
- device
Device to use
- solver
Solver to use, currently supports “qml”, “exact”, “flash”, “cutn” or custom callable
- Type:
Union[str, Callable]
- ansatz
Ansatz to use, “pz_encoding”, “px_encoding”, “rpz_encoding” or custom
- Type:
Union[str, Callable]
- theta
Learnable parameter of quantum circuit
- Type:
nn.Parameter
- base_weight
Learnable parameter of base activation
- Type:
nn.Parameter
- preacts_weight
Learnable parameter of preact weights
- Type:
nn.Parameter
- preacts_bias
Learnable parameter of preact bias
- Type:
nn.Parameter
- postact_weights
Learnable parameter of postact weights
- Type:
nn.Parameter
- postact_bias
Learnable parameter of postact bias
- Type:
nn.Parameter
- mask
Mask for pruning
- Type:
nn.Parameter
- fast_measure
Enable to use fast measurement in exact solver. Which would be quantum-inspired method. When False, the exact solver simulates the exact measurement process of quantum circuit.
- Type:
- c_dtype
Compute dtype for quantum simulation. Supported values:
torch.complex64/torch.float32: full-precision f32 (default)torch.bfloat16: mixed-precision bf16 I/O, f32 compute, bf16 state checkpointstorch.float8_e4m3fn: bf16 I/O, f32 compute, fp8 prescaled state checkpoints
- Type:
torch.dtype
- p_dtype
Parameter dtype (
torch.float32ortorch.bfloat16). Usetorch.bfloat16with bf16/fp8c_dtypefor full mixed-precision pipeline.- Type:
torch.dtype
- _x0
Leave for ResQKANLayer
- Type:
Optional[torch.Tensor]
- init_parameters()[source]
Create all learnable parameters.
Called once from
__init__to allocatenn.Parameterobjects. Reads configuration fromself.*attributes. Ifself.seedis set, the RNG is seeded for reproducibility.Calls
xavier_init()at the end to apply Xavier normal initialization to theta (and preacts whenpreact_initis set).
- xavier_init()[source]
Apply Xavier normal initialization to theta and preacts.
Applies
nn.init.xavier_normal_in-place toself.theta. Whenself.preact_initis set, also applies it toself.preacts_weightandself.preacts_bias.
- to(*args, **kwargs)[source]
Move the layer to the specified device.
- Parameters:
device (str | torch.device) – Device to move the layer to, default: “cpu”
- property param_size
- property x0
- forward(x)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class qkan.StateVector(batch_size, out_dim, in_dim, device='cpu', dtype=torch.complex64)[source]
Bases:
object1-qubit state vector.
StateVector.state: torch.Tensor, shape: (batch_size, out_dim, in_dim, 2)
- state: Tensor
- measure_z(fast_measure=True)[source]
Measure the state vector in the Z basis.
- Return type:
Tensor
:type : fast_measure: bool, default: True. If True, for state |ψ⟩ = α|0⟩ + β|1⟩, return |α| - |β|;
return: torch.Tensor, shape: (batch_size, out_dim, in_dim)
- measure_x(fast_measure=True)[source]
Measure the state vector in the X basis.
- Return type:
Tensor
:type : fast_measure: bool, default: True. If True, for state |ψ⟩ = α|0⟩ + β|1⟩, return |α| - |β|;
return: torch.Tensor, shape: (batch_size, out_dim, in_dim)
- measure_y(fast_measure=True)[source]
Measure the state vector in the Y basis.
- Return type:
Tensor
:type : fast_measure: bool, default: True. If True, for state |ψ⟩ = α|0⟩ + β|1⟩, return |α| - |β|;
return: torch.Tensor, shape: (batch_size, out_dim, in_dim)
- s(is_dagger=False)[source]
Apply Phase gate (or S gate) to the state vector.
:param : :type : is_dagger: bool, default: False
- h(is_dagger=False)[source]
Apply Hadamard gate to the state vector.
:param : :type : is_dagger: bool, default: False
- rx(theta, is_dagger=False)[source]
Apply Rotation-X gate to the state vector.
:param : :type : theta: torch.Tensor, shape: (out_dim, in_dim) :param : :type : is_dagger: bool, default: False
- class qkan.TorchGates[source]
Bases:
object- static identity_gate(shape)[source]
shape: (out_dim, in_dim)
return: torch.Tensor, shape: (2, 2, out_dim, in_dim)
- Return type:
Tensor
- static i_gate(shape)[source]
shape: (out_dim, in_dim)
return: torch.Tensor, shape: (2, 2, out_dim, in_dim)
- Return type:
Tensor
- static rx_gate(theta, dtype=torch.complex64)[source]
theta: torch.Tensor, shape: (out_dim, in_dim)
return: torch.Tensor, shape: (2, 2, out_dim, in_dim)
- Return type:
Tensor
- static ry_gate(theta, dtype=torch.complex64)[source]
theta: torch.Tensor, shape: (out_dim, in_dim)
return: torch.Tensor, shape: (2, 2, out_dim, in_dim)
- Return type:
Tensor
- static rz_gate(theta, dtype=torch.complex64)[source]
theta: torch.Tensor, shape: (out_dim, in_dim)
return: torch.Tensor, shape: (2, 2, out_dim, in_dim)
- Return type:
Tensor
- static h_gate(shape, device, dtype=torch.complex64)[source]
shape: (out_dim, in_dim)
return: torch.Tensor, shape: (2, 2, out_dim, in_dim)
- Return type:
Tensor
- static s_gate(shape)[source]
shape: (out_dim, in_dim)
return: torch.Tensor, shape: (2, 2, out_dim, in_dim)
- Return type:
Tensor
- static acrx_gate(theta, dtype=torch.complex64)[source]
Complex extension of RX(acos(theta)) gate. Note: Physically unrealizable.
theta: torch.Tensor, shape: (out_dim, in_dim)
return: torch.Tensor, shape: (2, 2, out_dim, in_dim)
- Return type:
Tensor
- static tensor_product(gate, another_gate, dtype=None)[source]
Compute tensor product of two gates.
:param : :type : gate: torch.Tensor, shape: (2, 2, out_dim, in_dim) :param : :type : another_gate: torch.Tensor, shape: (2, 2, out_dim, in_dim) :param : Both gates should have the same dtype. :type : dtype: torch dtype, optional. If None, uses the dtype of the input gate.
return: torch.Tensor, shape: (4, 4, out_dim, in_dim)
- qkan.create_dataset(f, n_var=2, f_mode='col', ranges=[-1, 1], train_num=1000, test_num=1000, normalize_input=False, normalize_label=False, device='cpu', seed=0)[source]
Create dataset
- Parameters:
f – function the symbolic formula used to create the synthetic dataset
ranges – list or np.array; shape (2,) or (n_var, 2) the range of input variables. Default: [-1,1].
train_num – int the number of training samples. Default: 1000.
test_num – int the number of test samples. Default: 1000.
normalize_input – bool If True, apply normalization to inputs. Default: False.
normalize_label – bool If True, apply normalization to labels. Default: False.
device – str device. Default: ‘cpu’.
seed – int random seed. Default: 0.
- Returns:
- dict
Train/test inputs/labels are dataset[‘train_input’], dataset[‘train_label’], dataset[‘test_input’], dataset[‘test_label’]
- Return type:
dataset
Solver Module
QKAN solver backends.
Each solver is implemented in its own module: - torch_exact: Pure PyTorch reference implementation - flash: Triton fused kernels - cutile: cuTile (NVIDIA Tile Language) fused kernels - cutn: cuQuantum tensor network contraction - qml: PennyLane quantum circuits - qiskit_solver: IBM Quantum backends via Qiskit Runtime - cudaq_solver: NVIDIA CUDA-Q backends (GPU-accelerated simulation or QPU)
- qkan.solver.cudaq_solver(x, theta, preacts_weight, preacts_bias, reps, **kwargs)[source]
Execute QKAN circuits via NVIDIA CUDA-Q.
Drop-in replacement for torch_exact_solver using CUDA-Q’s GPU-accelerated quantum simulation or QPU backends. Circuits are built as CUDA-Q kernels and expectation values are computed via cudaq.observe().
Supports training via the parameter-shift rule when gradients are needed.
- Parameters:
x (torch.Tensor) – shape: (batch_size, in_dim)
theta (torch.Tensor) – shape: (*group, reps+1, n_params) or (*group, reps, 1) for real
preacts_weight (torch.Tensor) – shape: (*group, reps)
preacts_bias (torch.Tensor) – shape: (*group, reps)
reps (int)
ansatz (str) – “pz_encoding”, “pz”, “rpz_encoding”, “rpz”, or “real”
preacts_trainable (bool)
out_dim (int)
target (str, optional) – CUDA-Q target (e.g., “nvidia”, “nvidia-mqpu”, “qpp-cpu”). Set before calling via cudaq.set_target().
shots (int, optional) – Number of shots. None for exact statevector expectation.
- Return type:
Tensor- Returns:
- torch.Tensor
shape: (batch_size, out_dim, in_dim)
- qkan.solver.cutile_flash_exact_solver(x, theta, preacts_weight, preacts_bias, reps, **kwargs)[source]
cuTile-accelerated exact solver. Drop-in replacement for flash_exact_solver.
Uses fused cuTile kernels for pz_encoding, rpz_encoding, and real ansatzes. Falls back to torch_exact_solver for unsupported ansatzes.
- Parameters:
torch_exact_solver. (Same as)
- Returns:
(batch_size, out_dim, in_dim)
- Return type:
torch.Tensor, shape
- qkan.solver.cutn_solver(x, theta, preacts_weight, preacts_bias, reps, **kwargs)[source]
Tensor network contraction solver using optimal contraction paths.
Expresses the entire quantum circuit as a single tensor network and contracts it using an optimal path from cuQuantum or opt_einsum. The contraction plan is precompiled and cached so repeated forward calls pay no path-finding overhead.
Supports
pz_encoding(pz),rpz_encoding(rpz), andrealansatzes. Falls back to torch_exact_solver for unsupported ansatzes or reps > 11.- Parameters:
x (torch.Tensor) – shape: (batch_size, in_dim)
theta (torch.Tensor) – shape: (*group, reps+1, n_params_per_gate)
preacts_weight (torch.Tensor) – shape: (*group, reps)
preacts_bias (torch.Tensor) – shape: (*group, reps)
reps (int)
ansatz (str) – options: “pz_encoding”, “pz”, “rpz_encoding”, “rpz”, “real”
preacts_trainable (bool)
fast_measure (bool)
out_dim (int)
dtype (torch.dtype)
- Return type:
Tensor- Returns:
- torch.Tensor
shape: (batch_size, out_dim, in_dim)
- qkan.solver.flash_exact_solver(x, theta, preacts_weight, preacts_bias, reps, **kwargs)[source]
Triton-accelerated exact solver. Drop-in replacement for torch_exact_solver.
Uses fused Triton kernels for pz_encoding, rpz_encoding, and real ansatzes. Falls back to torch_exact_solver for unsupported ansatzes.
- Parameters:
torch_exact_solver. (Same as)
- Returns:
(batch_size, out_dim, in_dim)
- Return type:
torch.Tensor, shape
- qkan.solver.qiskit_solver(x, theta, preacts_weight, preacts_bias, reps, **kwargs)[source]
Execute QKAN circuits on IBM Quantum backends via Qiskit Runtime.
Drop-in replacement for torch_exact_solver. Circuits are built to match the exact gate sequences of each ansatz, then executed on the specified backend using Qiskit’s Estimator primitive.
Supports training via the parameter-shift rule when gradients are needed.
- Parameters:
x (torch.Tensor) – shape: (batch_size, in_dim)
theta (torch.Tensor) – shape: (*group, reps+1, n_params) or (*group, reps, 1) for real
preacts_weight (torch.Tensor) – shape: (*group, reps)
preacts_bias (torch.Tensor) – shape: (*group, reps)
reps (int)
ansatz (str) – “pz_encoding”, “pz”, “rpz_encoding”, “rpz”, or “real”
preacts_trainable (bool)
out_dim (int)
backend (qiskit Backend) – Qiskit backend instance (e.g., AerSimulator(), or from QiskitRuntimeService)
shots (int, optional) – Number of shots per circuit. None for exact expectation (statevector).
optimization_level (int) – Transpiler optimization level (0-3), default: 1
- Return type:
Tensor- Returns:
- torch.Tensor
shape: (batch_size, out_dim, in_dim)
- qkan.solver.qml_solver(x, theta, reps, **kwargs)[source]
Single-qubit data reuploading circuit using PennyLane.
- qkan.solver.torch_exact_solver(x, theta, preacts_weight, preacts_bias, reps, **kwargs)[source]
Single-qubit data reuploading circuit.
- Parameters:
x (torch.Tensor) – shape: (batch_size, in_dim)
theta (torch.Tensor) – shape: (*group, reps, 2)
preacts_weight (torch.Tensor) – shape: (*group, reps)
preacts_bias (torch.Tensor) – shape: (*group, reps)
reps (int)
ansatz (str) – options: [“pz_encoding”, “px_encoding”], default: “pz_encoding”
n_group (int) – number of neurons in a group, default: in_dim of x
- Return type:
Tensor- Returns:
- torch.Tensor
shape: (batch_size, out_dim, in_dim)
Qiskit Solver
- qkan.solver.qiskit_solver(x, theta, preacts_weight, preacts_bias, reps, **kwargs)[source]
Execute QKAN circuits on IBM Quantum backends via Qiskit Runtime.
Drop-in replacement for torch_exact_solver. Circuits are built to match the exact gate sequences of each ansatz, then executed on the specified backend using Qiskit’s Estimator primitive.
Supports training via the parameter-shift rule when gradients are needed.
- Parameters:
x (torch.Tensor) – shape: (batch_size, in_dim)
theta (torch.Tensor) – shape: (*group, reps+1, n_params) or (*group, reps, 1) for real
preacts_weight (torch.Tensor) – shape: (*group, reps)
preacts_bias (torch.Tensor) – shape: (*group, reps)
reps (int)
ansatz (str) – “pz_encoding”, “pz”, “rpz_encoding”, “rpz”, or “real”
preacts_trainable (bool)
out_dim (int)
backend (qiskit Backend) – Qiskit backend instance (e.g., AerSimulator(), or from QiskitRuntimeService)
shots (int, optional) – Number of shots per circuit. None for exact expectation (statevector).
optimization_level (int) – Transpiler optimization level (0-3), default: 1
- Return type:
Tensor- Returns:
- torch.Tensor
shape: (batch_size, out_dim, in_dim)
CUDA-Q Solver
- qkan.solver.cudaq_solver(x, theta, preacts_weight, preacts_bias, reps, **kwargs)[source]
Execute QKAN circuits via NVIDIA CUDA-Q.
Drop-in replacement for torch_exact_solver using CUDA-Q’s GPU-accelerated quantum simulation or QPU backends. Circuits are built as CUDA-Q kernels and expectation values are computed via cudaq.observe().
Supports training via the parameter-shift rule when gradients are needed.
- Parameters:
x (torch.Tensor) – shape: (batch_size, in_dim)
theta (torch.Tensor) – shape: (*group, reps+1, n_params) or (*group, reps, 1) for real
preacts_weight (torch.Tensor) – shape: (*group, reps)
preacts_bias (torch.Tensor) – shape: (*group, reps)
reps (int)
ansatz (str) – “pz_encoding”, “pz”, “rpz_encoding”, “rpz”, or “real”
preacts_trainable (bool)
out_dim (int)
target (str, optional) – CUDA-Q target (e.g., “nvidia”, “nvidia-mqpu”, “qpp-cpu”). Set before calling via cudaq.set_target().
shots (int, optional) – Number of shots. None for exact statevector expectation.
- Return type:
Tensor- Returns:
- torch.Tensor
shape: (batch_size, out_dim, in_dim)
Error Mitigation
- qkan.solver._mitigation._richardson_extrapolate(scale_factors, values)[source]
Lagrange interpolation at x=0 for Zero-Noise Extrapolation.
Given expectation values measured at different noise scale factors, extrapolate to the zero-noise limit.
- qkan.solver._mitigation._clip_expvals(expvals)[source]
Clamp expectation values to [-1, 1] (valid range for <Z>).
- Return type:
Utils Module
Create dataset for regression task.
Adapted from [KindXiaoming/pykan@GitHub 91a2f63](https://github.com/KindXiaoming/pykan/tree/91a2f633be2d435b081ef0ef52a7205c7e7bea9e)
- qkan.utils.f_inv(x, y_th)
- qkan.utils.f_inv2(x, y_th)
- qkan.utils.f_inv3(x, y_th)
- qkan.utils.f_inv4(x, y_th)
- qkan.utils.f_inv5(x, y_th)
- qkan.utils.f_sqrt(x, y_th)
- qkan.utils.f_power1d5(x, y_th)
- qkan.utils.f_invsqrt(x, y_th)
- qkan.utils.f_log(x, y_th)
- qkan.utils.f_tan(x, y_th)
- qkan.utils.f_arctanh(x, y_th)
- qkan.utils.f_arcsin(x, y_th)
- qkan.utils.f_arccos(x, y_th)
- qkan.utils.f_exp(x, y_th)
- qkan.utils.create_dataset(f, n_var=2, f_mode='col', ranges=[-1, 1], train_num=1000, test_num=1000, normalize_input=False, normalize_label=False, device='cpu', seed=0)[source]
Create dataset
- Parameters:
f – function the symbolic formula used to create the synthetic dataset
ranges – list or np.array; shape (2,) or (n_var, 2) the range of input variables. Default: [-1,1].
train_num – int the number of training samples. Default: 1000.
test_num – int the number of test samples. Default: 1000.
normalize_input – bool If True, apply normalization to inputs. Default: False.
normalize_label – bool If True, apply normalization to labels. Default: False.
device – str device. Default: ‘cpu’.
seed – int random seed. Default: 0.
- Returns:
- dict
Train/test inputs/labels are dataset[‘train_input’], dataset[‘train_label’], dataset[‘test_input’], dataset[‘test_label’]
- Return type:
dataset