本文主要是介绍搭建Tensorflow Quantum编程环境(Jupyter Notebook),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
搭建Tensorflow Quantum编译环境
- python包之间的版本冲突:
tensorflow-quantum依赖于cirq,而两个包对 protobuf 包的版本有要求(cirq需要protobuf版本为3.8.0,tensorflow-2.2.0最低要求是protobuf-3.8.0,更高版本的tensorflow要求更高版本的protobuf,会造成版本冲突):
cirq-0.8.0 <- - protobuf-3.8.0
tenforflow-2.2.0 (protobuf >= 3.8.0)
#20231214
tensorflow==2.6.0
tensorflow-quantum==0.6.1
tensorboard==2.8.0
protobuf==3.17.3
- 环境搭建步骤(打开anaconda prompt,输入指令):
- 在anaconda中创建新的环境(python 3.6 或 3.7 都可以)
conda create --name tensorflowq python=3.7
- 安装tensorflow和tensorflow-quantum包
conda activate tensorflowq
pip install tensorflow==2.2.0
pip install tensorflow-quantum
- 将环境配置到jupyter notebook
pip install ipykernel
python -m ipykernel install --user --name tensorflowq#jupyter kernelspec remove kernelname #如不使用了,可使用该语句删除kernel
- 在 jupyter notebook 中测试环境
import cirq
import tensorflow_quantum as tfq
编译通过即配置成功!
这篇关于搭建Tensorflow Quantum编程环境(Jupyter Notebook)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!