Skip to content

Files

Latest commit

 

History

History
123 lines (64 loc) · 3.32 KB

development_MacM1.rst

File metadata and controls

123 lines (64 loc) · 3.32 KB

Run TensorCircuit on TensorlowBackend with Apple M1

Contributed by (Yuqin Chen)

Warning

This page is deprecated. Please visit the update tutorial for the latest information.

Why We Can't Run TensorCircuit on TensorlowBackend with Apple M1

TensorCircuit requires Tensorflow to support TensorflowBackend. However for Apple M1, Tensorflow package cannot be properly installed by a usual method like "pip install tensorflow". As well, the TensorCircuit package cannot be properly installed by a usual method "pip install tensorcircuit" All we need is to properly install tensorflow on Apple M1 Pro and then download the TensorCircuit package to the local and install it.

Install tensorflow on Apple M1

According to the instructions below or the installation manual on Apple's official website tensorflow-metal PluggableDevice, you can install tensorflow step by step.

Step1: Environment setup

x86 : AMD Create virtual environment (recommended):

python3 -m venv ~/tensorflow-metal

source ~/tensorflow-metal/bin/activate

python -m pip install -U pip

NOTE: python version 3.8 required

arm64 : Apple Silicon

Download and install Conda env:

chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh

sh ~/Downloads/Miniforge3-MacOSX-arm64.sh

source ~/miniforge3/bin/activate

Install the TensorFlow dependencies:

conda install -c apple tensorflow-deps
  • When upgrading to new base TensorFlow version, recommend:
# uninstall existing tensorflow-macos and tensorflow-metal

python -m pip uninstall tensorflow-macos

python -m pip uninstall tensorflow-metal

# Upgrade tensorflow-deps

conda install -c apple tensorflow-deps --force-reinstall

# or point to specific conda environment

conda install -c apple tensorflow-deps --force-reinstall -n my_env
  • tensorflow-deps versions are following base TensorFlow versions so:

for v2.5

conda install -c apple tensorflow-deps==2.5.0

for v2.6

conda install -c apple tensorflow-deps==2.6.0

Step2: Install base TensorFlow

python -m pip install tensorflow-macos

Step3: Install tensorflow-metal plugin

python -m pip install tensorflow-metal

Install TensorCircuit on Apple M1

After properly install tensorflow, you can continue install TensorCircuit. Up to now, for Apple M1, the Tensorcircuit package can not be installed by simply conducting "pip install tensorcircuit", which will lead to improper way for Tensorflow installation. One need to download the installation package to the local, only in this way the installation proceess can recognize the Apple M1 environment.

One should download the TensorCircuit package to local at first.

git clone https://github.com/tencent-quantum-lab/tensorcircuit.git

Then unpackage it, and cd into the folder with "setup.py". Conducting

python setup.py build

python setup.py install