scikit_quri.qnn package

Contents

scikit_quri.qnn package#

Submodules#

scikit_quri.qnn.classifier module#

class scikit_quri.qnn.classifier.QNNClassifier(ansatz, num_class, estimator, gradient_estimator, optimizer, operator=<factory>, x_norm_range=1.0, y_norm_range=0.7, do_x_scale=True, do_y_scale=True, n_outputs=1, y_exp_ratio=2.2, trained_param=None, predict_inner_cache=<factory>)[source]#

Bases: object

Class to solve classification problems by quantum neural networks. The prediction is made by making a vector which predicts one-hot encoding of labels. The prediction is made by 1. taking expectation values of Pauli Z operator of each qubit <Z_i>, 2. taking softmax function of the vector (<Z_0>, <Z_1>, ..., <Z_{n-1}>).

Parameters:

Example

>>> from scikit_quri.qnn.classifier import QNNClassifier
>>> from scikit_quri.circuit import create_qcl_ansatz
>>> from quri_parts.core.estimator.gradient import (
>>>     create_numerical_gradient_estimator,
>>> )
>>> from quri_parts.qulacs.estimator import (
>>>     create_qulacs_vector_concurrent_estimator,
>>>     create_qulacs_vector_concurrent_parametric_estimator,
>>> )
>>> from quri_parts.algo.optimizer import Adam
>>> num_class = 3
>>> nqubit = 5
>>> c_depth = 3
>>> time_step = 0.5
>>> circuit = create_qcl_ansatz(nqubit, c_depth, time_step, 0)
>>> adam = Adam()
>>> estimator = create_qulacs_vector_concurrent_estimator()
>>> gradient_estimator = create_numerical_gradient_estimator(
>>>    create_qulacs_vector_concurrent_parametric_estimator(), delta=1e-10
>>> )
>>> qnn = QNNClassifier(circuit, num_class, estimator, gradient_estimator, adam)
>>> qnn.fit(x_train, y_train, maxiter)
>>> y_pred = qnn.predict(x_test).argmax(axis=1)
ansatz: LearningCircuit#
num_class: int#
estimator: BaseEstimator#
gradient_estimator: Callable[[Union[Operator, PauliLabel], _ParametricStateT, Sequence[float]], Estimates[complex]]#
optimizer: Optimizer#
operator: List[Union[Operator, PauliLabel]]#
x_norm_range: float = 1.0#
y_norm_range: float = 0.7#
do_x_scale: bool = True#
do_y_scale: bool = True#
n_outputs: int = 1#
y_exp_ratio: float = 2.2#
trained_param: Optional[npt.NDArray[np.float64]] = None#
n_qubit: int#
predict_inner_cache: Dict[Tuple[bytes, bytes], ndarray[tuple[int, ...], dtype[float64]]]#
fit(x_train, y_train, maxiter=100)[source]#
Parameters:
  • x_train (ndarray[tuple[int, ...], dtype[float64]]) – List of training data inputs whose shape is (n_samples, n_features).

  • y_train (ndarray[tuple[int, ...], dtype[int64]]) – List of labels to fit. Labels must be represented as integers. Shape is (n_samples,).

  • maxiter (int) – The number of maximum iterations for the optimizer.

Returns:

None

predict(x_test)[source]#

Predict outcome for each input data in x_test. This method returns the predicted outcome as a vector of probabilities for each class. :param x_test: Input data whose shape is (n_samples, n_features).

Returns:

Predicted outcome whose shape is (n_samples, num_class).

Return type:

y_pred

Parameters:

x_test (ndarray[tuple[int, ...], dtype[float64]]) –

cost_func(x_scaled, y_train, params)[source]#
Parameters:
Return type:

float

cost_func_grad(x_scaled, y_train, params)[source]#
Parameters:
Return type:

ndarray[tuple[int, …], dtype[float64]]

scikit_quri.qnn.generation module#

class scikit_quri.qnn.generation.QNNGenerator(circuit, solver, kernel_type, gauss_sigma, fitting_qubit)[source]#

Bases: object

Class to generation problems by quantum neural networks. This class is only working with a simulator. depending on qulacs. It is not working with real quantum computers.

Parameters:
  • circuit (LearningCircuit) – The learning circuit to be used.

  • solver (Optimizer) – The optimizer to be used for training.

  • kernel_type (Literal['gauss', 'exp_hamming', 'same']) – The type of kernel to be used. exp_hamming is not implemented yet.

  • gauss_sigma (float) – The sigma value for Gaussian kernel.

  • fitting_qubit (int) – The number of qubits to be used for fitting.

fit(train_data, maxiter=100)[source]#
Params:

train_data: The training data to be used for fitting. maxiter: The maximum number of iterations for the optimizer. Default is 100.

Parameters:
fit_direct_distribution(train_scaled, maxiter)[source]#
Parameters:
Return type:

Tuple[float, List[float]]

predict()[source]#
Return type:

ndarray[tuple[int, …], dtype[float64]]

conving(data_diff)[source]#
Parameters:

data_diff (ndarray[tuple[int, ...], dtype[float64]]) –

Return type:

ndarray[tuple[int, …], dtype[float64]]

cost_func(theta, train_scaled)[source]#
Parameters:
Return type:

ndarray[tuple[int, …], dtype[float64]]

scikit_quri.qnn.kernel_tsne module#

class scikit_quri.qnn.kernel_tsne.pqc_f_helper(pqs_f)[source]#

Bases: object

Helper class that evaluates and caches quantum states for input data.

Parameters:

pqs_f (Callable[[ndarray[tuple[int, ...], dtype[float64]]], GeneralCircuitQuantumState]) –

get(input)[source]#

Return the cached quantum state for the given input, computing it if not yet cached.

Parameters:

input (ndarray[tuple[int, ...], dtype[float64]]) – Input data array.

Returns:

Quantum state corresponding to the input.

Return type:

GeneralCircuitQuantumState

class scikit_quri.qnn.kernel_tsne.overlap_estimator(states)[source]#

Bases: object

Alternative implementation of quri-parts’ overlap estimator using qulacs directly. Approximately 60x faster than the quri-parts implementation for n_data=500.

Parameters:

states (List[GeneralCircuitQuantumState]) –

calc_all_qula_states()[source]#

Pre-compute and cache all qulacs states for later use in estimate().

estimate(i, j)[source]#

Compute the squared overlap |⟨φi|φj⟩|² between the i-th and j-th states.

Parameters:
  • i (int) – Index of the ket state.

  • j (int) – Index of the bra state.

Returns:

Estimated value of |⟨φi|φj⟩|².

class scikit_quri.qnn.kernel_tsne.TSNE(perplexity=30)[source]#

Bases: object

Basic t-SNE implementation for computing p and q probability matrices.

calc_probabilities_p(X_train)[source]#

Compute the t-SNE joint probability matrix P from Euclidean distances.

Parameters:

X_train (ndarray[tuple[int, ...], dtype[float64]]) – Input data of shape (n_samples, n_features).

Returns:

Symmetric joint probability matrix P of shape (n_samples, n_samples).

Return type:

ndarray[tuple[int, …], dtype[float64]]

calc_probabilities_p_state(X_train_state)[source]#

Compute the t-SNE joint probability matrix P from quantum state overlaps. Uses 1 - |⟨φi|φj⟩|² as the distance metric between quantum states.

Parameters:

X_train_state (List[GeneralCircuitQuantumState]) – List of quantum states corresponding to the training inputs.

Returns:

Symmetric joint probability matrix P of shape (n_samples, n_samples).

Return type:

ndarray[tuple[int, …], dtype[float64]]

calc_probabilities_q(c_data)[source]#

Compute the t-SNE joint probability matrix Q from the low-dimensional embedding. Uses the Student’s t-distribution as the similarity kernel.

Parameters:

c_data (ndarray[tuple[int, ...], dtype[float64]]) – Low-dimensional embedding (called y in the original paper), of shape (n_samples, n_components).

Returns:

Symmetric joint probability matrix Q of shape (n_samples, n_samples).

Return type:

ndarray[tuple[int, …], dtype[float64]]

joint_probabilities(sq_distance, perplexity)[source]#

Compute the symmetric joint probability matrix from pairwise distances.

Parameters:
  • sq_distance (ndarray[tuple[int, ...], dtype[float64]]) – Pairwise distance matrix of shape (n_samples, n_samples).

  • perplexity (int) – Target perplexity for the conditional distributions.

Returns:

Symmetric joint probability matrix of shape (n_samples, n_samples).

binary_search_perplexity(sq_distance, perplexity)[source]#

Find the Gaussian kernel bandwidth for each point via binary search so that the perplexity of the conditional distribution matches the target.

Parameters:
kldiv(p_probs, q_probs)[source]#

Compute the KL divergence KL(P || Q).

Parameters:
  • p_probs – Reference probability matrix P.

  • q_probs – Approximate probability matrix Q.

Returns:

Scalar KL divergence value.

cdist(X, X_tr)[source]#

Compute pairwise Euclidean distances between rows of X and X_tr.

Parameters:
Returns:

Distance matrix of shape (n_samples, m_samples).

class scikit_quri.qnn.kernel_tsne.quantum_kernel_tsne(perplexity=30, max_iter=400)[source]#

Bases: object

t-SNE using a quantum kernel as the similarity measure in the high-dimensional space.

init(pqc_f, theta)[source]#

Set up the parametric quantum circuit used to encode input data.

Parameters:
Return type:

None

calc_loss(p_prob, q_prob)[source]#

Compute the KL divergence loss KL(P || Q) used as the optimization objective.

Parameters:
Returns:

Scalar KL divergence loss value.

calc_grad(alpha, p_prob, fidelity)[source]#

Compute the numerical gradient of the loss with respect to alpha using central differences.

Parameters:
  • alpha (ndarray[tuple[int, ...], dtype[float64]]) – Flattened embedding coefficients of shape (n_samples * 2,).

  • p_prob (ndarray[tuple[int, ...], dtype[float64]]) – High-dimensional joint probability matrix P.

  • fidelity (ndarray[tuple[int, ...], dtype[float64]]) – Pairwise fidelity matrix of shape (n_samples, n_samples).

Returns:

Gradient array of the same shape as alpha.

cost_f(alpha, p_prob, fidelity)[source]#

Cost function passed to the optimizer.

Parameters:
  • alpha (ndarray[tuple[int, ...], dtype[float64]]) – Flattened embedding coefficients of shape (n_samples * 2,). The optimizer passes a 1-D array; it is reshaped to (n_samples, 2) internally.

  • p_prob (ndarray[tuple[int, ...], dtype[float64]]) – High-dimensional joint probability matrix P.

  • fidelity (ndarray[tuple[int, ...], dtype[float64]]) – Pairwise fidelity matrix of shape (n_samples, n_samples).

Returns:

Scalar KL divergence loss value.

generate_X_train_state(X_train)[source]#

Generate quantum states for all training inputs using the cached circuit evaluator.

Parameters:

X_train (ndarray[tuple[int, ...], dtype[float64]]) – Training input array of shape (n_samples, n_features).

Returns:

Array of GeneralCircuitQuantumState objects of shape (n_samples,).

train(X_train, y_label, method='Powell')[source]#

Fit the quantum kernel t-SNE embedding.

Parameters:
  • X_train (ndarray[tuple[int, ...], dtype[float64]]) – Training input array of shape (n_samples, n_features).

  • y_label (ndarray[tuple[int, ...], dtype[int8]]) – Class labels of shape (n_samples,). Used only for plotting.

  • method – Optimization method. One of "adam", "COBYLA", or "Powell". Defaults to "Powell".

transform(X_test)[source]#

Compute the low-dimensional embedding for test data using the trained alpha.

Parameters:

X_test (ndarray[tuple[int, ...], dtype[float64]]) – Test input array of shape (n_samples, n_features).

Returns:

Low-dimensional embedding of shape (n_samples, 2).

Return type:

ndarray[tuple[int, …], dtype[float64]]

calc_y(fidelity, alpha)[source]#

Compute the low-dimensional embedding y = fidelity @ alpha.

Parameters:
  • fidelity (ndarray[tuple[int, ...], dtype[float64]]) – Pairwise fidelity matrix |⟨φi|φj⟩|² of shape (n_data, n_data).

  • alpha (ndarray[tuple[int, ...], dtype[float64]]) – Embedding coefficients of shape (n_data, 2).

Returns:

Low-dimensional embedding of shape (n_data, 2).

Return type:

ndarray[tuple[int, …], dtype[float64]]

input_quantum_state(input, pqc_f, theta)[source]#

Compute the quantum state |φ(input, θ)⟩ for the given input and circuit parameters.

Parameters:
Returns:

Bound quantum state corresponding to the input and parameters.

Return type:

GeneralCircuitQuantumState

calc_fidelity(data, data_tr, pqs_f_helper)[source]#

Compute the full symmetric fidelity matrix when data == data_tr.

Parameters:
  • data – Input array.

  • data_tr – Must be identical to data.

  • pqs_f_helper (pqc_f_helper) – Cached quantum state evaluator.

Returns:

Symmetric fidelity matrix of shape (n_data, n_data).

Raises:

ValueError – If data and data_tr are not identical.

calc_fidelity_all(data, data_tr, pqs_f_helper)[source]#

Compute the fidelity matrix when data != data_tr (e.g. train vs test).

Parameters:
  • data – Query data array of shape (n_data, n_features).

  • data_tr – Reference data array of shape (n_data_tr, n_features).

  • pqs_f_helper (pqc_f_helper) – Cached quantum state evaluator.

Returns:

Fidelity matrix of shape (n_data, n_data_tr).

plot(y, y_label, title)[source]#

Plot the 2-D embedding with class labels.

Parameters:

scikit_quri.qnn.regressor module#

scikit_quri.qnn.regressor.mean_squared_error(y_true, y_pred)[source]#

Calculate the mean squared error between true and predicted values.

Parameters:
Returns:

Mean squared error.

Return type:

mse

class scikit_quri.qnn.regressor.QNNRegressor(ansatz, estimator, gradient_estimator, optimizer, operator=<factory>, x_norm_range=1.0, y_norm_range=0.7, do_x_scale=True, do_y_scale=True, n_outputs=1, y_exp_ratio=2.2, trained_param=None)[source]#

Bases: object

Class to solve regression problems with quantum neural networks. The out is taken as expectation values of Pauli Z operators acting on the first qubit. i.e., output is <Z_0>.

Parameters:

Example

>>> from quri_parts.qulacs.estimator import (
>>>     create_qulacs_vector_concurrent_estimator,
>>>     create_qulacs_vector_concurrent_parametric_estimator,
>>> )
>>> from quri_parts.core.estimator.gradient import (
>>>     create_numerical_gradient_estimator,
>>> )
>>> n_qubit = 3
>>> depth = 3
>>> time_step = 0.5
>>> estimator = create_qulacs_vector_concurrent_estimator()
>>> gradient_estimator = create_numerical_gradient_estimator(
>>>     create_qulacs_vector_concurrent_parametric_estimator()
>>> )
>>> circuit = create_qcl_ansatz(n_qubit, depth, time_step, 0)
>>> circuit = create_qcl_ansatz(n_qubit, depth, time_step, 0)
>>> qnn = QNNRegressor(n_qubit, circuit, estimator, gradient_estimator, solver)
>>> qnn.fit(x_train, y_train, maxiter)
>>> y_pred = qnn.predict(x_test)
ansatz: LearningCircuit#
estimator: BaseEstimator#
gradient_estimator: Callable[[Union[Operator, PauliLabel], _ParametricStateT, Sequence[float]], Estimates[complex]]#
optimizer: Optimizer#
operator: List[Union[Operator, PauliLabel]]#
x_norm_range: float = 1.0#
y_norm_range: float = 0.7#
n_qubit: int#
do_x_scale: bool = True#
do_y_scale: bool = True#
n_outputs: int = 1#
y_exp_ratio: float = 2.2#
trained_param: Optional[npt.NDArray[np.float64]] = None#
fit(x_train, y_train, maxiter=20)[source]#

Fit the model to the training data.

Parameters:
  • x_train (ndarray[tuple[int, ...], dtype[float64]]) – Input data whose shape is (n_samples, n_features).

  • y_train (ndarray[tuple[int, ...], dtype[float64]]) – Output data whose shape is (n_samples, n_outputs).

  • batch_size – The number of samples in each batch.

Return type:

None

cost_fn(x_scaled, y_scaled, params)[source]#

Calculate the cost function for solver.

Parameters:
  • x_batched – Input data whose shape is (batch_size, n_features).

  • y_batched – Output data whose shape is (batch_size, n_outputs).

  • params (npt.NDArray[np.float64]) – Parameters for the quantum circuit.

  • x_scaled (ndarray[tuple[int, ...], dtype[float64]]) –

  • y_scaled (ndarray[tuple[int, ...], dtype[float64]]) –

Returns:

Cost function value.

Return type:

cost

predict(x_test)[source]#

Predict outcome for each input data in x_test.

Parameters:

x_test (ndarray[tuple[int, ...], dtype[float64]]) – Input data whose shape is (batch_size, n_features).

Returns:

Predicted outcome.

Return type:

y_pred

grad_fn(x_scaled, y_scaled, params)[source]#

Calculate the gradient of the cost function for solver.

Parameters:
  • x_batched – Input data whose shape is (batch_size, n_features).

  • y_batched – Output data whose shape is (batch_size, n_outputs).

  • params (npt.NDArray[np.float64]) – Parameters for the quantum circuit.

  • x_scaled (ndarray[tuple[int, ...], dtype[float64]]) –

  • y_scaled (ndarray[tuple[int, ...], dtype[float64]]) –

Returns:

Gradient of the cost function.

Return type:

grads

Module contents#

class scikit_quri.qnn.QNNClassifier(ansatz, num_class, estimator, gradient_estimator, optimizer, operator=<factory>, x_norm_range=1.0, y_norm_range=0.7, do_x_scale=True, do_y_scale=True, n_outputs=1, y_exp_ratio=2.2, trained_param=None, predict_inner_cache=<factory>)[source]#

Bases: object

Class to solve classification problems by quantum neural networks. The prediction is made by making a vector which predicts one-hot encoding of labels. The prediction is made by 1. taking expectation values of Pauli Z operator of each qubit <Z_i>, 2. taking softmax function of the vector (<Z_0>, <Z_1>, ..., <Z_{n-1}>).

Parameters:

Example

>>> from scikit_quri.qnn.classifier import QNNClassifier
>>> from scikit_quri.circuit import create_qcl_ansatz
>>> from quri_parts.core.estimator.gradient import (
>>>     create_numerical_gradient_estimator,
>>> )
>>> from quri_parts.qulacs.estimator import (
>>>     create_qulacs_vector_concurrent_estimator,
>>>     create_qulacs_vector_concurrent_parametric_estimator,
>>> )
>>> from quri_parts.algo.optimizer import Adam
>>> num_class = 3
>>> nqubit = 5
>>> c_depth = 3
>>> time_step = 0.5
>>> circuit = create_qcl_ansatz(nqubit, c_depth, time_step, 0)
>>> adam = Adam()
>>> estimator = create_qulacs_vector_concurrent_estimator()
>>> gradient_estimator = create_numerical_gradient_estimator(
>>>    create_qulacs_vector_concurrent_parametric_estimator(), delta=1e-10
>>> )
>>> qnn = QNNClassifier(circuit, num_class, estimator, gradient_estimator, adam)
>>> qnn.fit(x_train, y_train, maxiter)
>>> y_pred = qnn.predict(x_test).argmax(axis=1)
ansatz: LearningCircuit#
num_class: int#
estimator: BaseEstimator#
gradient_estimator: Callable[[Union[Operator, PauliLabel], _ParametricStateT, Sequence[float]], Estimates[complex]]#
optimizer: Optimizer#
operator: List[Union[Operator, PauliLabel]]#
x_norm_range: float = 1.0#
y_norm_range: float = 0.7#
do_x_scale: bool = True#
do_y_scale: bool = True#
n_outputs: int = 1#
y_exp_ratio: float = 2.2#
trained_param: Optional[npt.NDArray[np.float64]] = None#
n_qubit: int#
predict_inner_cache: Dict[Tuple[bytes, bytes], ndarray[tuple[int, ...], dtype[float64]]]#
fit(x_train, y_train, maxiter=100)[source]#
Parameters:
  • x_train (ndarray[tuple[int, ...], dtype[float64]]) – List of training data inputs whose shape is (n_samples, n_features).

  • y_train (ndarray[tuple[int, ...], dtype[int64]]) – List of labels to fit. Labels must be represented as integers. Shape is (n_samples,).

  • maxiter (int) – The number of maximum iterations for the optimizer.

Returns:

None

predict(x_test)[source]#

Predict outcome for each input data in x_test. This method returns the predicted outcome as a vector of probabilities for each class. :param x_test: Input data whose shape is (n_samples, n_features).

Returns:

Predicted outcome whose shape is (n_samples, num_class).

Return type:

y_pred

Parameters:

x_test (ndarray[tuple[int, ...], dtype[float64]]) –

cost_func(x_scaled, y_train, params)[source]#
Parameters:
Return type:

float

cost_func_grad(x_scaled, y_train, params)[source]#
Parameters:
Return type:

ndarray[tuple[int, …], dtype[float64]]

class scikit_quri.qnn.QNNRegressor(ansatz, estimator, gradient_estimator, optimizer, operator=<factory>, x_norm_range=1.0, y_norm_range=0.7, do_x_scale=True, do_y_scale=True, n_outputs=1, y_exp_ratio=2.2, trained_param=None)[source]#

Bases: object

Class to solve regression problems with quantum neural networks. The out is taken as expectation values of Pauli Z operators acting on the first qubit. i.e., output is <Z_0>.

Parameters:

Example

>>> from quri_parts.qulacs.estimator import (
>>>     create_qulacs_vector_concurrent_estimator,
>>>     create_qulacs_vector_concurrent_parametric_estimator,
>>> )
>>> from quri_parts.core.estimator.gradient import (
>>>     create_numerical_gradient_estimator,
>>> )
>>> n_qubit = 3
>>> depth = 3
>>> time_step = 0.5
>>> estimator = create_qulacs_vector_concurrent_estimator()
>>> gradient_estimator = create_numerical_gradient_estimator(
>>>     create_qulacs_vector_concurrent_parametric_estimator()
>>> )
>>> circuit = create_qcl_ansatz(n_qubit, depth, time_step, 0)
>>> circuit = create_qcl_ansatz(n_qubit, depth, time_step, 0)
>>> qnn = QNNRegressor(n_qubit, circuit, estimator, gradient_estimator, solver)
>>> qnn.fit(x_train, y_train, maxiter)
>>> y_pred = qnn.predict(x_test)
ansatz: LearningCircuit#
estimator: BaseEstimator#
gradient_estimator: Callable[[Union[Operator, PauliLabel], _ParametricStateT, Sequence[float]], Estimates[complex]]#
optimizer: Optimizer#
operator: List[Union[Operator, PauliLabel]]#
x_norm_range: float = 1.0#
y_norm_range: float = 0.7#
n_qubit: int#
do_x_scale: bool = True#
do_y_scale: bool = True#
n_outputs: int = 1#
y_exp_ratio: float = 2.2#
trained_param: Optional[npt.NDArray[np.float64]] = None#
fit(x_train, y_train, maxiter=20)[source]#

Fit the model to the training data.

Parameters:
  • x_train (ndarray[tuple[int, ...], dtype[float64]]) – Input data whose shape is (n_samples, n_features).

  • y_train (ndarray[tuple[int, ...], dtype[float64]]) – Output data whose shape is (n_samples, n_outputs).

  • batch_size – The number of samples in each batch.

Return type:

None

cost_fn(x_scaled, y_scaled, params)[source]#

Calculate the cost function for solver.

Parameters:
  • x_batched – Input data whose shape is (batch_size, n_features).

  • y_batched – Output data whose shape is (batch_size, n_outputs).

  • params (npt.NDArray[np.float64]) – Parameters for the quantum circuit.

  • x_scaled (ndarray[tuple[int, ...], dtype[float64]]) –

  • y_scaled (ndarray[tuple[int, ...], dtype[float64]]) –

Returns:

Cost function value.

Return type:

cost

predict(x_test)[source]#

Predict outcome for each input data in x_test.

Parameters:

x_test (ndarray[tuple[int, ...], dtype[float64]]) – Input data whose shape is (batch_size, n_features).

Returns:

Predicted outcome.

Return type:

y_pred

grad_fn(x_scaled, y_scaled, params)[source]#

Calculate the gradient of the cost function for solver.

Parameters:
  • x_batched – Input data whose shape is (batch_size, n_features).

  • y_batched – Output data whose shape is (batch_size, n_outputs).

  • params (npt.NDArray[np.float64]) – Parameters for the quantum circuit.

  • x_scaled (ndarray[tuple[int, ...], dtype[float64]]) –

  • y_scaled (ndarray[tuple[int, ...], dtype[float64]]) –

Returns:

Gradient of the cost function.

Return type:

grads

class scikit_quri.qnn.QNNGenerator(circuit, solver, kernel_type, gauss_sigma, fitting_qubit)[source]#

Bases: object

Class to generation problems by quantum neural networks. This class is only working with a simulator. depending on qulacs. It is not working with real quantum computers.

Parameters:
  • circuit (LearningCircuit) – The learning circuit to be used.

  • solver (Optimizer) – The optimizer to be used for training.

  • kernel_type (Literal['gauss', 'exp_hamming', 'same']) – The type of kernel to be used. exp_hamming is not implemented yet.

  • gauss_sigma (float) – The sigma value for Gaussian kernel.

  • fitting_qubit (int) – The number of qubits to be used for fitting.

fit(train_data, maxiter=100)[source]#
Params:

train_data: The training data to be used for fitting. maxiter: The maximum number of iterations for the optimizer. Default is 100.

Parameters:
fit_direct_distribution(train_scaled, maxiter)[source]#
Parameters:
Return type:

Tuple[float, List[float]]

predict()[source]#
Return type:

ndarray[tuple[int, …], dtype[float64]]

conving(data_diff)[source]#
Parameters:

data_diff (ndarray[tuple[int, ...], dtype[float64]]) –

Return type:

ndarray[tuple[int, …], dtype[float64]]

cost_func(theta, train_scaled)[source]#
Parameters:
Return type:

ndarray[tuple[int, …], dtype[float64]]