paddle_quantum.dataset
The source file of the dataset.
- class paddle_quantum.dataset.Dataset
 Bases:
objectBase class for all datasets, integrating multiple quantum encoding methods.
- data2circuit(classical_data, encoding, num_qubits, can_describe_dimension, split_circuit, return_state, is_image=False)
 Encode the input
classical datainto quantum states usingencoding, where the classical data is truncated or filled with zero.- Parameters:
 classical_data (list) – vectors needed to encode, which have been already truncated or filled with zero to the length
can_describe_dimensionFor example, amplitude encoding can describe2 ** ndimension vectors.encoding (str) – The encoding method.
num_qubits (int) – The number of qubits.
can_describe_dimension (int) – The dimension which the circuit can describe by
encoding.split_circuit (bool) – Whether to split the circuit.
return_state (bool) – Whether to return quantum state.
is_image (bool | None) – Whether it is a picture, if it is a picture, the normalization method is not quite the same. Defaults to
False.
- Raises:
 Exception – Not support to return circuit in amplitude encoding.
- Returns:
 If
return_state == True, return encoded quantum state, otherwise return encoding circuits.- Return type:
 list
- filter_class(x, y, classes, data_num, need_relabel, seed=0)
 Select
data_numsamples fromx,y, whose label is inclasses.- Parameters:
 x (list | ndarray) – Training features.
y (list | ndarray) – Training labels.
classes (list) – Classes needed to select.
data_num (int) – The number of data needed to select.
need_relabel (bool) – Whether we need to relabel the labels to 0,1,2 for binary classification. For example
[1,2]will be relabeled to[0,1].seed (int | None) – Random seed. Defaults to
0.
- Returns:
 contains elements
new_x: selected features.
new_y: selected labels corresponded to
new_x.
- Return type:
 Tuple[list]
- class paddle_quantum.dataset.VisionDataset(figure_size)
 Bases:
DatasetVisionDatasetis the base class of all image datasets. By inheritingVisionDataset, users can easily generate their own quantum data.- Parameters:
 figure_size (int) – The size of the figure.
- encode(feature, encoding, num_qubits, split_circuit=False, downscaling_method='resize', target_dimension=-1, return_state=True, full_return=False)
 Encode
featureintonum_qubitsqubits usingencodingafter downscaling totarget_dimension.featureis one-dimension image vectors.- Parameters:
 feature (list | ndarray) – One-dimension image vectors which can be list or ndarray.
encoding (str) –
angle_encodingdenotes angle encoding, and one qubit encodes one number with a Ry gate.amplitude_encodingdenotes amplitude encoding;pauli_rotation_encodingdenotes using SU(3) rotation gate.linear_entanglement_encoding,real_entanglement_encoding,complex_entanglement_encodingandIQP_encodingencoding methods.num_qubits (int) – Qubit number.
split_circuit (bool | None) – Whether to split the circuits. If true, every layer of the encoding circuit will be split into a list. Defaults to
False.downscaling_method (str | None) – Including
PCAandresize. Defaults toresize.target_dimension (int | None) – The dimension after downscaling.
target_dimensionis not allowed to surpass the figure size. Defaults to-1.return_state (bool | None) – Whether to return quantum states. If it is
False, return quantum circuits. Defaults toTrue.full_return (bool | None) – Whether to return
quantum_image_states,quantum_image_circuits,original_imagesandclassical_image_vectors. Defaults toFalse.
- Raises:
 Exception – PCA dimension should be less than figure size.
Exception – Resize dimension should be a square.
Exception – Downscaling methods can only be resize and PCA.
Exception – Invalid encoding methods
- Returns:
 contain these elements
quantum_image_states: Quantum states, only
full_return==Trueorreturn_state==Truewill return.quantum_image_circuits: A list of circuits generating quantum states, only
full_return==Trueorreturn_state==Truewill return.original_images: One-dimension original vectors without any processing, only
return_state==Truewill return.classical_image_vectors: One-dimension original vectors after filling with zero, which are encoded to quantum states. only
return_state==Truewill return.
- Return type:
 Tuple[Tensor, list, ndarray, ndarray]
- class paddle_quantum.dataset.SimpleDataset(dimension)
 Bases:
DatasetFor simple dataset that does not require dimension reduction. You can inherit
SimpleDatasetto generate quantum states from your classical datasets.- Parameters:
 dimension (int) – Dimension of encoding data.
- encode(feature, encoding, num_qubits, return_state=True, full_return=False)
 Encode
featurewithnum_qubitsqubits byencoding.- Parameters:
 feature (list | ndarray) – Features needed to encode.
encoding (str) – Encoding methods.
num_qubits (int) – Qubit number.
return_state (bool | None) – Whether to return quantum states. Defaults to
True.full_return (bool | None) – Whether to return quantum_states, quantum_circuits, origin_feature and feature. Defaults to
False.
- Raises:
 Exception – Invalid type of feature.
Exception – Invalid encoding methods.
Exception – The qubit number is not enough to encode the features.
- Returns:
 contain these element
quantum_states: Quantum states, only
full_return==Trueorreturn_state==Truewill return;quantum_circuits: A list of circuits generating quantum states, only
full_return==Trueorreturn_state==Truewill return;origin_feature: One-dimension original vectors without any processing, only
return_state==Truewill returnfeature: One-dimension original vectors after filling with zero, which are encoded to quantum states. only
return_state==Truewill return.
- Return type:
 Tuple[ndarray, list, ndarray, ndarray]
- class paddle_quantum.dataset.MNIST(mode, encoding, num_qubits, classes, data_num=-1, split_circuit=False, downscaling_method='resize', target_dimension=-1, need_cropping=True, need_relabel=True, return_state=True, seed=0)
 Bases:
VisionDatasetMNIST quantum dataset. It inherits
VisionDataset.- Parameters:
 mode (str) – Data mode including
trainandtest.encoding (str) –
angle_encodingdenotes angle encoding, and one qubit encodes one number with a Ry gate.amplitude_encodingdenotes amplitude encoding;pauli_rotation_encodingdenotes using SU(3) rotation gate.linear_entanglement_encoding,real_entanglement_encoding,complex_entanglement_encodingandIQP_encodingencoding methods.num_qubits (int) – Qubit number.
classes (list) – Classes needed to classify, categories are indicated by numeric labels.
data_num (int | None) – Data number returned. Defaults to
-1.split_circuit (bool | None) – Whether to split the circuits. If True, every layer of the encoding circuit will be split into a list. Defaults to
False.downscaling_method (str | None) – Including
PCAandresize. Defaults toresize.target_dimension (int | None) – The dimension after downscaling, which is not allowed to surpass the figure size. Defaults to
-1.need_cropping (bool | None) – Whether needed to crop, If
True,image[0:27][0:27]will be cropped toimage[4:24][4:24]. Defaults toTrue.need_relabel (bool | None) – Whether we need to relabel the labels to 0,1,2… for binary classification.For example [1,2] will be relabeled to [0,1] Defaults to
True.return_state (bool | None) – Whether to return quantum states. Defaults to
True.seed (int | None) – Select random seed. Defaults to
0.
- Raises:
 Exception – Data mode can only be train and test.
- class paddle_quantum.dataset.FashionMNIST(mode, encoding, num_qubits, classes, data_num=-1, split_circuit=False, downscaling_method='resize', target_dimension=-1, need_relabel=True, return_state=True, seed=0)
 Bases:
VisionDatasetFashionMNIST quantum dataset. It inherits
VisionDataset.- Parameters:
 mode (str) – Data mode including
trainandtest.encoding (str) –
angle_encodingdenotes angle encoding, and one qubit encodes one number with a Ry gate.amplitude_encodingdenotes amplitude encoding;pauli_rotation_encodingdenotes using SU(3) rotation gate.linear_entanglement_encoding,real_entanglement_encoding,complex_entanglement_encodingandIQP_encodingencoding methods.num_qubits (int) – Qubit number.
classes (list) – Classes needed to classify, categories are indicated by numeric labels.
data_num (int | None) – Data number returned. Defaults to
-1.split_circuit (bool | None) – Whether to split the circuits. If True, every layer of the encoding circuit will be split into a list. Defaults to
False.downscaling_method (str | None) – Including
PCAandresize. Defaults toresize.target_dimension (int | None) – The dimension after downscaling, which is not allowed to surpass the figure size. Defaults to
-1.need_cropping – Whether needed to crop, If
True,image[0:27][0:27]will be cropped toimage[4:24][4:24]. Defaults toTrue.need_relabel (bool | None) – Whether we need to relabel the labels to 0,1,2… for binary classification.For example [1,2] will be relabeled to [0,1] Defaults to
True.return_state (bool | None) – Whether to return quantum states. Defaults to
True.seed (int | None) – Select random seed. Defaults to
0.
- Raises:
 Exception – Data mode can only be train and test.
- class paddle_quantum.dataset.Iris(encoding, num_qubits, classes, test_rate=0.2, need_relabel=True, return_state=True, seed=0)
 Bases:
SimpleDatasetIris dataset
- Parameters:
 encoding (str) –
angle_encodingdenotes angle encoding, and one qubit encodes one number with a Ry gate.amplitude_encodingdenotes amplitude encoding;pauli_rotation_encodingdenotes using SU(3) rotation gate.linear_entanglement_encoding,real_entanglement_encoding,complex_entanglement_encodingandIQP_encodingencoding methods.num_qubits (int) – Qubit number.
classes (list) – Classes needed to classify, categories are indicated by numeric labels.
test_rate (float | None) – The proportion of the testing dataset. Defaults to
0.2.need_relabel (bool | None) – Whether we need to relabel the labels to 0,1,2… for binary classification.For example [1,2] will be relabeled to [0,1]. Defaults to
True.return_state (bool | None) – Whether to return quantum states. Defaults to
True.seed (int | None) – Select random seed. Defaults to
0.
- class paddle_quantum.dataset.BreastCancer(encoding, num_qubits, test_rate=0.2, return_state=True, seed=0)
 Bases:
SimpleDatasetBreastCancer quantum dataset.
- Parameters:
 encoding (str) –
angle_encodingdenotes angle encoding, and one qubit encodes one number with a Ry gate.amplitude_encodingdenotes amplitude encoding;pauli_rotation_encodingdenotes using SU(3) rotation gate.linear_entanglement_encoding,real_entanglement_encoding,complex_entanglement_encodingandIQP_encodingencoding methods.num_qubits (int) – Qubit number.
test_rate (float | None) – The proportion of the testing dataset. Defaults to
0.2.return_state (bool | None) – Whether to return quantum states. Defaults to
True.seed (int | None) – Select random seed. Defaults to
0.