renom_q.ml ¶
renom_q.ml.qaa ¶
-
class
renom_q.ml.qaa.
QAA
¶ -
Bases:
object
Quantum Adiabatic Algorithm
-
rx
( qci , theta , q ) ¶ -
rx gate { Exp**(j * theta * X) }
-
rz
( qci , phi , q ) ¶ -
rz gate { Exp**(j * theta * Z) }
-
rzz
( qci , phi , q1 , q2 ) ¶ -
rzz gate { Exp**(j * theta * ZZ) }
-
qaa
( J , hz=None , hx=-1.0 , tm=10 , dt=0.1 , shots=1024 , maxcut_mode=False , ae_mode=False , convolution=False , cqae_list=None , cqae_spin=None , set_qasm=False ) ¶ -
The optimization algorithm by quantum adiabatic calcutation
- Args:
-
- J (int, float, array or list):
- A Matrix of coupling coefficients applied to spins of Ising model.
- hz (list):
- A List of longitudinal magnetic field coefficients applied to each spin of Ising model. Defaults to None.
- hx (int or float):
- A transverse field coefficient uniformly applied to spins of Ising model. Defaults to -1.0.
- tm (int or float):
- A evolution time in the Hamiltonian Schrodinger equation of Ising model. The number of steps in QAA is tm/dt. Defaults to 10.
- dt (int or float):
- A time interval of time evolution in the Hamiltonian Schrodinger equation of the Ising model. The number of steps in QAA is tm/dt. Defaults to 0.1.
- shots (int):
- The number of excutions of quantum circuit mesurement. Defaults to 1024.
- maxcut_mode (boolean):
- If it is True, the sign of J is inverted during calculation. Defaults to False.
- ae_mode (boolean):
- If it is true, each spin in the Ising model is affected only by the 4 adjacent spins. Defaults to False.
- convolution (boolean):
- If it is true, it is calculated with a convolution filter composed of 9 qubits in the quantum autoencoder algorithm. Defaults to False.
- cqae_list (list):
- A list to use when boolean convolution is True. Defaults to None.
- cqae_spin (int):
- A number of qubit to use when boolean convolution is True. Defaults to None.
- set_qasm (boolean):
- If it is true, qasm code is added to the calculation result. Defaults to False.
- Returns:
-
- result (dict):
- A dict of the calculation result and each parameter of adiabatic quantum calculation.
- Example:
-
>>> import renom_q.ml.qaa >>> qaa = renom_q.ml.qaa.QAA() >>> J = -1 >>> hz = [-1, 1] >>> qaa.qaa(J, hz) {'solution': array([0, 1]), 'result': {'00': 280, '01': 510, '11': 234}, 'J': -1, 'hz': [-1, 1], 'hx': -1.0, 'shots': 1024, 'qasm': None}
-
renom_q.ml.qae ¶
-
class
renom_q.ml.qae.
QAE
( set_qasm=False ) ¶ -
Bases:
renom_q.ml.qaa.QAA
Quantum AutoEncoder
- Args:
-
- set_qasm (boolean):
- If it is true, qasm code is added to the calculation result. Defaults to False.
- Example:
-
>>> import renom_q.ml.qae >>> qae = renom_q.ml.qae.QAE(True)
-
ising
( matrix ) ¶ -
Convert qubit state to spin state of ising model [0, 1, 0, 1] => [-1, 1, -1, 1]
- Args:
-
- matrix (array or list):
- A list of the each qubit state. A qubit has two states of 0 and 1.
- Returns:
-
- (array):
- A list of the each spin state of ising model. The state of up spin is expressed as 1 and The state of down spin is expressed as -1.
- Example:
-
>>> import renom_q.ml.qae >>> qae = renom_q.ml.qae.QAE() >>> spin = [0, 1, 0, 1, 0] >>> qae.ising(spin) array([-1, 1, -1, 1, -1])
-
qubo
( matrix ) ¶ -
Convert spin state of ising model to qubit state [-1, 1, -1, 1] => [0, 1, 0, 1]
- Args:
-
- matrix (array or list):
- A list of the each spin state of ising model. The state of up spin is expressed as 1 and The state of down spin is expressed as -1.
- Returns:
-
- (array):
- A list of the each qubit state. A qubit has two states of 0 and 1.
- Example:
-
>>> import renom_q.ml.qae >>> qae = renom_q.ml.qae.QAE() >>> spin = [-1, 1, -1, 1, -1] >>> qae.qubo(spin) array([0., 1., 0., 1., 0.])
-
draw_image
( spin_list , grid=True ) ¶ -
Draw an image in a quantum autoencoder algorithm
- Args:
-
- spin_list (list):
- A list of the each spin state of ising model. The state of up spin is expressed as 1 and The state of down spin is expressed as -1.
- grid (boolean):
- If it is true, add grid lines to the drawing image. Defaults to True.
- Returns:
-
- matplotlib.figure:
- A matplotlib figure object of an image in a quantum autoencoder algorithm.
- Example:
-
>>> import renom_q.ml.qae >>> qae = renom_q.ml.qae.QAE() >>> ising = [-1, 1, -1, -1, 1, -1, -1, 1, -1] >>> qae.draw_image(ising)
-
original
( number=3 , mark=[] ) ¶ -
Setting a original image using quantum autoencoder algorithm
- Args:
-
- number (int or list or array):
- If ‘number’ type is int or float, the image is a square whose side is the number specified by ‘number’. The minimum size is 3x3 images. If ‘number’ type is list or array (matrix), the image is visualized by scalar data of matrix ‘number’. Defaults to 3.
- mark (list or array):
- A list specifying the grid numbers to make the color black. Specify either one-dimensional array or two-dimensional array. Defaults to empty list.
- Example:
-
>>> import renom_q.ml.qae >>> qae = renom_q.ml.qae.QAE() >>> qae.original(4, [1, 5, 15])
-
add_noise
( noise_rate=0.1 ) ¶ -
Add noise the original image
- Args:
-
- noise_rate (float):
- A number of percentages of noise to be mixed into the original image. This can be specified from 0 to 1. Defaults to 0.1.
- Example:
-
>>> import renom_q.ml.qae >>> qae = renom_q.ml.qae.QAE() >>> qae.original(4, [1, 5, 15]) >>> qae.add_noise(0.3)
-
decode
( plot_filter=False ) ¶ -
Add noise the original image
- Args:
-
- plot_filter (boolean):
- If it is true, the denoised image at each filter in the convolutional quantum self-coder is drawn. This can only be specified for images larger than 3x3. Defaults to False.
- Example:
-
>>> import renom_q.ml.qae >>> qae = renom_q.ml.qae.QAE() >>> qae.original(4, [1, 5, 15]) >>> qae.add_noise(0.3) >>> qae.decode(True)
-
renom_q.ml.qae.
random
( ) → x in the interval [0, 1). ¶
renom_q.ml.qclustering ¶
-
class
renom_q.ml.qclustering.
QClustering
( set_qasm=False ) ¶ -
Bases:
renom_q.ml.qaa.QAA
Quantum Clustering
- Args:
-
- set_qasm (boolean):
- If it is true, qasm code is added to the calculation result. Defaults to False.
- Example:
-
>>> import renom_q.ml.qclustering >>> qcl = renom_q.ml.qclustering.QClustering(True)
-
plot_graph
( array , label=None ) ¶ -
Draw a graph of data used in quantum clustering algorithm
- Args:
-
- array (array or list):
- A array of data used in quantum clustering algorithm.
- label (array or list):
- A list of labels for data after clustering. Defaults to None.
- Returns:
-
- matplotlib.figure:
- A matplotlib figure object of a graph of data used in quantum clustering algorithm.
- Example:
-
>>> import renom_q.ml.qclustering >>> qcl = renom_q.ml.qclustering.QClustering() >>> data = [[5, 4], [6, 6], [4, 9], [8, 1]] >>> qcl.plot_graph(data)
-
qclustering
( array , mode='euclidean' ) ¶ -
Cluster input data into two classes
- Args:
-
- array (array or list):
- A array of input data used in quantum clustering algorithm.
- mode (str):
- A name of distance between each data point. Defaults to ‘euclidean’.
- Returns:
-
- label (array or list):
- A list of labels for data after clustering.
- Example:
-
>>> import renom_q.ml.qclustering >>> qcl = renom_q.ml.qclustering.QClustering() >>> data = [[5, 4], [6, 6], [4, 9], [8, 1]] >>> qcl.qclustering(data, mode='mahalanobis') Mahalanobis' Distance [1, -1, -1, 1]
renom_q.ml.qpca ¶
-
class
renom_q.ml.qpca.
QPCA
( n_components=None ) ¶ -
Bases:
object
Quantum Principle Component Analysis
- Args:
-
- n_components (int):
- A number of principal components to calculate by quantum PCA algorithm. Defaults to None.
- Example:
-
>>> import renom_q.ml.qpca >>> qpca = renom_q.ml.qpca.QPCA(2)
-
vqe_circuit
( theta , qubit_number , depth ) ¶ -
The circuit using quantum PCA algorithm
-
get_covariance
( ) ¶ -
Calculate the covariance matrix of the input matrix used in principal component analysis
- Returns:
-
- cov (array):
- A array of the covariance matrix of the input matrix used in principal component analysis.
- Example:
-
>>> import renom_q.ml.qpca >>> qpca = renom_q.ml.qpca.QPCA(2) >>> matrix = [[0.5, 0.8], [0.8, 0.5]] >>> qpca.fit(matrix, method='Nelder-Mead') >>> qpca.get_covariance() array([[ 0.045, -0.045], [-0.045, 0.045]])
-
transform
( matrix ) ¶ -
Calculate inner product of input matrix and its principal component vector
- Args:
-
- matrix (list):
- The input matrix used in principal component analysis.
- Returns:
-
- vec (array):
- A array of inner product of input matrix and its principal component vector.
- Example:
-
>>> import renom_q.ml.qpca >>> qpca = renom_q.ml.qpca.QPCA(2) >>> matrix = [[0.5, 0.8], [0.8, 0.5]] >>> qpca.fit(matrix, method='Nelder-Mead') >>> qpca.transform(matrix) array([[ 0.21213203, -0.15 ], [-0.21213203, 0.15 ]])
-
fit
( matrix , depth=None , method='Nelder-Mead' , n_particle=100 , steps=50 ) ¶ -
Perform principal component analysis of data
- Args:
-
- matrix (array or list):
- A matrix to perform principal component analysis.
- depth (boolean):
- A number of circuit depths used in the quantum PCA algorithm. Defaults to None.
- method (str):
- A name of optimization algorithm used in quantum PCA algorithm. Available method is Nelder-Mead and QPSO. Defaults to ‘Nelder-Mead’.
- n_particle (int):
- A number of particles using QPSO method. Defaults to 100.
- steps (int):
- A number of optimal solution searches. Defaults to 50.
- Example:
-
>>> import renom_q.ml.qpca >>> qpca = renom_q.ml.qpca.QPCA(2) >>> matrix = [[0.5, 0.8], [0.8, 0.5]] >>> qpca.fit(matrix, method='QPSO', 80, 20)
renom_q.ml.qsvm ¶
-
class
renom_q.ml.qsvm.
QSVM
( set_qasm=False ) ¶ -
Bases:
renom_q.ml.qaa.QAA
Quantum Support Vector Machine
- Args:
-
- set_qasm (boolean):
- If it is true, qasm code is added to the calculation result. Defaults to False.
- Example:
-
>>> import renom_q.ml.qsvm >>> qsvm = renom_q.ml.qsvm.QSVM(True)
-
plot_graph
( x_train=None , y_train=None , x_test=None , y_pred=None ) ¶ -
Draw a graph of data used in quantum SVM algorithm
- Args:
-
- x_train (array or list):
- A array of train data. Defaults to None.
- y_train (array or list):
- A list of labels of train data. Defaults to None.
- x_test (array or list):
- A array of test data. Defaults to None.
- y_pred (array or list):
- A list of labels of test data. Defaults to None.
- Returns:
-
- matplotlib.figure:
- A matplotlib figure object of a graph of data used in quantum SVM algorithm.
- Example:
-
>>> import renom_q.ml.qsvm >>> qsvm = renom_q.ml.qsvm.QSVM() >>> x_train = [[5, 4], [6, 6], [4, 9], [8, 1]] >>> y_train = [1, -1, 1, -1] >>> qsvm.plot_graph(x_train, y_train)
-
fit
( train_data , train_label ) ¶ -
Setting training data used in quantum SVM algorithm
- Args:
-
- train_data (array or list):
- A array of train data.
- train_label (array or list):
- A list of labels of train data.
- Example:
-
>>> import renom_q.ml.qsvm >>> qsvm = renom_q.ml.qsvm.QSVM() >>> x_train = [[5, 4], [6, 6], [4, 9], [8, 1]] >>> y_train = [1, -1, 1, -1] >>> qsvm.fit(x_train, y_train)
-
predict
( test_data ) ¶ -
Predict labels of test data using training data
- Args:
-
- test_data (array or list):
- A array of test data.
- Returns:
-
- y_pred (list):
- A list of labels of test data.
- Example:
-
>>> import renom_q.ml.qsvm >>> qsvm = renom_q.ml.qsvm.QSVM() >>> x_train = [[5, 4], [6, 6], [4, 9], [8, 1]] >>> y_train = [1, -1, 1, -1] >>> qsvm.fit(x_train, y_train) >>> x_test = [[3, 2], [7, 1], [5, 2], [1, 3]] >>> qsvm.predict(x_test) [1, -1, 1, 1]