"Looking in indexes: https://mirrors.bfsu.edu.cn/pypi/web/simple\n",
"Requirement already satisfied: paddle-quantum in /Users/wangzihe/temp/baidu/QPlatform/PaddleQu (2.2.1)\n",
"Requirement already satisfied: paddlepaddle<=2.3.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (2.3.0)\n",
"Requirement already satisfied: scipy in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (1.7.1)\n",
"Collecting protobuf<=3.20.1\n",
" Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/92/0e/b8a60441178c8725fb3afa648e80c312a77feab31e7831d69c672b3c18cc/protobuf-3.20.1-cp37-cp37m-macosx_10_9_x86_64.whl (961 kB)\n",
"Requirement already satisfied: networkx>=2.5 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (2.6.3)\n",
"Requirement already satisfied: qcompute in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (3.0.0)\n",
"Requirement already satisfied: matplotlib>=3.3.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (3.5.2)\n",
"Requirement already satisfied: tqdm in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (4.64.0)\n",
"Requirement already satisfied: openfermion in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (1.5.1)\n",
"Requirement already satisfied: opencv-python in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (4.6.0.66)\n",
"Requirement already satisfied: scikit-learn in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (1.0.2)\n",
"Requirement already satisfied: fastdtw in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (0.3.4)\n",
"Requirement already satisfied: cvxpy in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (1.2.2)\n",
"Requirement already satisfied: rich in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (12.0.1)\n",
"Requirement already satisfied: pyscf in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddle-quantum) (2.1.1)\n",
"Requirement already satisfied: pillow>=6.2.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (9.3.0)\n",
"Requirement already satisfied: pyparsing>=2.2.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (3.0.9)\n",
"Requirement already satisfied: python-dateutil>=2.7 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (2.8.2)\n",
"Requirement already satisfied: packaging>=20.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (21.3)\n",
"Requirement already satisfied: cycler>=0.10 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (0.11.0)\n",
"Requirement already satisfied: numpy>=1.17 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (1.21.3)\n",
"Requirement already satisfied: fonttools>=4.22.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (4.38.0)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from matplotlib>=3.3.0->paddle-quantum) (1.4.4)\n",
"Requirement already satisfied: paddle-bfloat==0.1.2 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (0.1.2)\n",
"Requirement already satisfied: astor in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (0.8.1)\n",
"Requirement already satisfied: requests>=2.20.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (2.28.0)\n",
"Requirement already satisfied: six in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (1.16.0)\n",
"Requirement already satisfied: decorator in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (5.1.1)\n",
"Requirement already satisfied: opt-einsum==3.3.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from paddlepaddle<=2.3.0->paddle-quantum) (3.3.0)\n",
"Requirement already satisfied: scs>=1.1.6 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cvxpy->paddle-quantum) (3.2.2)\n",
"Requirement already satisfied: osqp>=0.4.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cvxpy->paddle-quantum) (0.6.2.post5)\n",
"Requirement already satisfied: ecos>=2 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cvxpy->paddle-quantum) (2.0.10)\n",
"Requirement already satisfied: cirq-google>=0.15.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (1.0.0)\n",
"Requirement already satisfied: sympy in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (1.10.1)\n",
"Requirement already satisfied: deprecation in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (2.1.0)\n",
"Requirement already satisfied: cirq-core>=0.15.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (1.0.0)\n",
"Requirement already satisfied: pubchempy in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (1.0.4)\n",
"Requirement already satisfied: h5py>=2.8 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from openfermion->paddle-quantum) (3.7.0)\n",
"Collecting scipy\n",
" Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/4c/4a/440cc9703938bbc86636ff6b9e17810f3d0f06e9b41891c5433dc4cd9091/scipy-1.1.0-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (16.7 MB)\n",
"Collecting qcompute\n",
" Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/f6/57/823a3f3e3fd6e327453c4d028751fee7292784e1f2447ae6b7c0f3cc6565/qcompute-2.0.6-py3-none-any.whl (172 kB)\n",
" Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/8e/03/0a64ec2b7e6395fa53688ad3e489163218c45f36f0c96b448e0279391538/qcompute-2.0.4-py3-none-any.whl (96 kB)\n",
"Requirement already satisfied: bidict in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from qcompute->paddle-quantum) (0.22.0)\n",
"Requirement already satisfied: pyprimes in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from qcompute->paddle-quantum) (0.1)\n",
"Requirement already satisfied: bce-python-sdk in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from qcompute->paddle-quantum) (0.8.73)\n",
"Requirement already satisfied: commonmark<0.10.0,>=0.9.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from rich->paddle-quantum) (0.9.1)\n",
"Requirement already satisfied: pygments<3.0.0,>=2.6.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from rich->paddle-quantum) (2.13.0)\n",
"Requirement already satisfied: typing-extensions<5.0,>=3.7.4 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from rich->paddle-quantum) (4.3.0)\n",
"Requirement already satisfied: joblib>=0.11 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from scikit-learn->paddle-quantum) (1.2.0)\n",
"Requirement already satisfied: threadpoolctl>=2.0.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from scikit-learn->paddle-quantum) (3.1.0)\n",
"Requirement already satisfied: backports.cached-property~=1.0.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-core>=0.15.0->openfermion->paddle-quantum) (1.0.2)\n",
"Requirement already satisfied: duet~=0.2.7 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-core>=0.15.0->openfermion->paddle-quantum) (0.2.7)\n",
"Requirement already satisfied: pandas in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-core>=0.15.0->openfermion->paddle-quantum) (1.3.5)\n",
"Requirement already satisfied: sortedcontainers~=2.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-core>=0.15.0->openfermion->paddle-quantum) (2.4.0)\n",
"Requirement already satisfied: google-api-core[grpc]<2.0.0dev,>=1.14.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-google>=0.15.0->openfermion->paddle-quantum) (1.33.2)\n",
"Requirement already satisfied: proto-plus>=1.20.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from cirq-google>=0.15.0->openfermion->paddle-quantum) (1.22.1)\n",
"Requirement already satisfied: qdldl in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from osqp>=0.4.1->cvxpy->paddle-quantum) (0.1.5.post2)\n",
"Requirement already satisfied: charset-normalizer~=2.0.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle<=2.3.0->paddle-quantum) (2.0.12)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle<=2.3.0->paddle-quantum) (2022.9.24)\n",
"Requirement already satisfied: idna<4,>=2.5 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle<=2.3.0->paddle-quantum) (3.4)\n",
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle<=2.3.0->paddle-quantum) (1.26.12)\n",
"Requirement already satisfied: future>=0.6.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from bce-python-sdk->qcompute->paddle-quantum) (0.18.2)\n",
"Requirement already satisfied: pycryptodome>=3.8.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from bce-python-sdk->qcompute->paddle-quantum) (3.15.0)\n",
"Requirement already satisfied: mpmath>=0.19 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from sympy->openfermion->paddle-quantum) (1.2.1)\n",
"Collecting typing-extensions<5.0,>=3.7.4\n",
" Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/2e/35/6c4fff5ab443b57116cb1aad46421fb719bed2825664e8fe77d66d99bcbc/typing_extensions-3.10.0.0-py3-none-any.whl (26 kB)\n",
"Collecting protobuf<=3.20.1\n",
" Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/ea/fe/82cf68917308b208731487f986db209e56903c30e324499b6bf0cc6a6203/protobuf-3.19.6-cp37-cp37m-macosx_10_9_x86_64.whl (979 kB)\n",
"Requirement already satisfied: google-auth<3.0dev,>=1.25.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (2.14.1)\n",
"Requirement already satisfied: googleapis-common-protos<2.0dev,>=1.56.2 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (1.57.0)\n",
"Requirement already satisfied: grpcio<2.0dev,>=1.33.2 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (1.50.0)\n",
"Requirement already satisfied: grpcio-status<2.0dev,>=1.33.2 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (1.48.2)\n",
"Requirement already satisfied: pytz>=2017.3 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from pandas->cirq-core>=0.15.0->openfermion->paddle-quantum) (2022.6)\n",
"Requirement already satisfied: pyasn1-modules>=0.2.1 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-auth<3.0dev,>=1.25.0->google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (0.2.8)\n",
"Requirement already satisfied: cachetools<6.0,>=2.0.0 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-auth<3.0dev,>=1.25.0->google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (5.2.0)\n",
"Requirement already satisfied: rsa<5,>=3.1.4 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from google-auth<3.0dev,>=1.25.0->google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (4.9)\n",
"Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages (from pyasn1-modules>=0.2.1->google-auth<3.0dev,>=1.25.0->google-api-core[grpc]<2.0.0dev,>=1.14.0->cirq-google>=0.15.0->openfermion->paddle-quantum) (0.4.8)\n",
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/linalg/__init__.py:212: DeprecationWarning: The module numpy.dual is deprecated. Instead of using dual, use the functions directly from numpy or scipy.\n",
" from numpy.dual import register_func\n",
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/sparse/sputils.py:16: DeprecationWarning: `np.typeDict` is a deprecated alias for `np.sctypeDict`.\n",
" supported_dtypes = [np.typeDict[x] for x in supported_dtypes]\n",
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/special/orthogonal.py:81: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" from numpy import (exp, inf, pi, sqrt, floor, sin, cos, around, int,\n",
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/io/matlab/mio5.py:98: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. \n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" if data.dtype == np.object:\n",
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/paddle/fluid/framework.py:1104: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
"Variational Shadow Quantum Learning (VSQL) is a hybird quantum-classical framework for supervised quantum learning, which utilizes parameterized quantum circuits and classical shadows. Unlike commonly used variational quantum algorithms, the VSQL method extracts \"local\" features from the subspace instead of the whole Hilbert space."
"Variational Shadow Quantum Learning (VSQL) is a hybrid quantum-classical framework for supervised quantum learning, which utilizes parameterized quantum circuits and classical shadows. Unlike commonly used variational quantum algorithms, the VSQL method extracts \"local\" features from the subspace instead of the whole Hilbert space."
"The circuit layer in the dashed box is repeated for $D$ times to increase the expressive power of the quantum circuit. The structure of the circuit is not unique. You can try to design your own circuit."
"The circuit layer in the dashed box is repeated for $D$ times to increase the expressive power of the quantum circuit. The structure of the circuit is not unique. You can try to design your own circuit.\n"
"After installing Paddle Quantum successfully, let's load the VSQL model and the images to be predicted."
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 2,
"execution_count": 2,
"id": "86d4405c",
"id": "7d88445e",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [],
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/linalg/__init__.py:212: DeprecationWarning: The module numpy.dual is deprecated. Instead of using dual, use the functions directly from numpy or scipy.\n",
" from numpy.dual import register_func\n",
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/sparse/sputils.py:16: DeprecationWarning: `np.typeDict` is a deprecated alias for `np.sctypeDict`.\n",
" supported_dtypes = [np.typeDict[x] for x in supported_dtypes]\n",
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/special/orthogonal.py:81: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" from numpy import (exp, inf, pi, sqrt, floor, sin, cos, around, int,\n",
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/io/matlab/mio5.py:98: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
"# The overall configuration file of the model.\n",
"# Enter the current task, which can be 'train' or 'test', representing training and prediction respectively. Here we use test, indicating that we want to make a prediction.\n",
"task = 'test'\n",
"# The file path of the image to be predicted.\n",
"image_path = 'data_0.png'\n",
"# Whether the image path above is a folder or not. For folder paths, we will predict all image files inside the folder. This way you can test multiple images at once.\n",
"is_dir = false\n",
"# The file path of the trained model parameter file.\n",
"model_path = 'vsql.pdparams'\n",
"# The number of qubits that the quantum circuit contains.\n",
"num_qubits = 10\n",
"# The number of qubits that the shadow circuit contains.\n",
"num_shadow = 2\n",
"# Circuit depth.\n",
"depth = 1\n",
"# The class to be predicted by the model. Here, 0 and 1 are classified.\n",
"classes = [0, 1]\n",
"\"\"\""
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "35514ce7",
"metadata": {},
"source": [
"Then, we use the VSQL model to make predictions."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "ca32fb07",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"For the input image, the model has 89.22% confidence that it is 0, and 10.78% confidence that it is 1.\n"
]
}
],
"source": [
"config = toml.loads(test_toml)\n",
"task = config.pop('task')\n",
"prediction, prob = inference(**config)\n",
"prob = prob[0]\n",
"msg = 'For the input image, the model has'\n",
"for idx, item in enumerate(prob):\n",
" if idx == len(prob) - 1:\n",
" msg += 'and'\n",
" label = config['classes'][idx]\n",
" msg += f' {item:3.2%} confidence that it is {label:d}'\n",
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. \n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" if data.dtype == np.object:\n",
"/Users/wangzihe/opt/anaconda3/envs/py37/lib/python3.7/site-packages/paddle/fluid/framework.py:1104: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" elif dtype == np.bool:\n"
]
},
{
{
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"output_type": "stream",
"text": [
"text": [
"For handwritten digits 0, the model has 89.22% confidence that it is 0 and 10.78% confidence that it is 1.\n",
"For the input image, the model has 18.29% confidence that it is 0, and 81.71% confidence that it is 1.\n"
"For handwritten digits 1, the model has 18.29% confidence that it is 0 and 81.71% confidence that it is 1.\n"
"# The overall configuration file of the model.\n",
"test_data = [np.pad(datum, pad_width=(0, 2 ** num_qubits - datum.size)) for datum in test_data]\n",
"# Enter the current task, which can be 'train' or 'test', representing training and prediction respectively. Here we use test, indicating that we want to make a prediction.\n",
"test_data = [paddle.to_tensor(datum / np.linalg.norm(datum), dtype=pq.get_dtype()) for datum in test_data]\n",
"task = 'test'\n",
"# Use the model to make predictions and get the corresponding probability\n",
"# The file path of the image to be predicted.\n",
"# Whether the image path above is a folder or not. For folder paths, we will predict all image files inside the folder. This way you can test multiple images at once.\n",
"print(\n",
"is_dir = false\n",
" f\"For handwritten digits 0, \"\n",
"# The file path of the trained model parameter file.\n",
" f\"the model has {test_prob[0][0].item():3.2%} confidence that it is 0 \"\n",
"model_path = 'vsql.pdparams'\n",
" f\"and {test_prob[0][1].item():3.2%} confidence that it is 1.\"\n",
"# The number of qubits that the quantum circuit contains.\n",
")\n",
"num_qubits = 10\n",
"print(\n",
"# The number of qubits that the shadow circuit contains.\n",
" f\"For handwritten digits 1, \"\n",
"num_shadow = 2\n",
" f\"the model has {test_prob[1][0].item():3.2%} confidence that it is 0 \"\n",
"# Circuit depth.\n",
" f\"and {test_prob[1][1].item():3.2%} confidence that it is 1.\"\n",
"depth = 1\n",
")"
"# The class to be predicted by the model. Here, 0 and 1 are classified.\n",
"classes = [0, 1]\n",
"\"\"\"\n",
"\n",
"config = toml.loads(test_toml)\n",
"task = config.pop('task')\n",
"prediction, prob = inference(**config)\n",
"prob = prob[0]\n",
"msg = 'For the input image, the model has'\n",
"for idx, item in enumerate(prob):\n",
" if idx == len(prob) - 1:\n",
" msg += 'and'\n",
" label = config['classes'][idx]\n",
" msg += f' {item:3.2%} confidence that it is {label:d}'\n",
"The model we provide is a binary classification model that can only be used to distinguish handwritten digits 0 and 1. For other classification tasks, it needs to be retrained."
"The model we provide is a binary classification model that can only be used to distinguish handwritten digits 0 and 1. For other classification tasks, it needs to be retrained.\n",
"\n",
"A more detailed description of the use can be found at https://github.com/PaddlePaddle/Quantum/blob/master/applications/handwritten_digits_classification/introduction_en.ipynb .\n",
"\n",
"A detailed description of the VSQL model can be found at https://github.com/PaddlePaddle/Quantum/blob/master/tutorials/machine_learning/VSQL_EN.ipynb ."
]
]
},
},
{
{
...
@@ -374,7 +413,7 @@
...
@@ -374,7 +413,7 @@
],
],
"metadata": {
"metadata": {
"kernelspec": {
"kernelspec": {
"display_name": "Python 3.7.15 ('py37')",
"display_name": "pq-dev",
"language": "python",
"language": "python",
"name": "python3"
"name": "python3"
},
},
...
@@ -388,7 +427,7 @@
...
@@ -388,7 +427,7 @@
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.7.15"
"version": "3.8.15 (default, Nov 10 2022, 13:17:42) \n[Clang 14.0.6 ]"