如何安装IBM QISKit,并实现第一个量子程序Bell State

本文档是IBM QISKit教程的一部分,指导如何安装QISKit并实现Bell State。首先,需要安装Anaconda 3,创建特定环境并激活。接着,安装QISKit和Jupyter Notebook。若要使用远程后端运行,需要IBM Q账户和令牌。本地模拟器在远程后端忙碌时提供替代方案。最后,展示了量子电路的可视化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


使用平台为Jupyter Notebook。

QISKit tutorial – Bell State

This project is based on the IBM QISKit tutorial on Github. The code can be found in bell state link and visualization link.

If this is the first time for you to run QISKit, please follow the following steps to install the environment:

  1. Install Anaconda 3 (Can be downloaded here)
  2. Create a new environment for running QISKit
conda create -n env_name python=3.6

Note that env_name is the name you given to this new environment. Here this line is to install the current latest version for python – version 3.6, and QISKit is only available with python 3.5 or later.
3. Activate the newly generated environment

conda activate env_name
  1. Install QISKit package
pip install qiskit

QISKit is available on these platforms: Linux x86_64, Darwin and Win64.
5. Install Jupyter Notebook

pip install jupyter
  1. Run Jupyter Notebook
jupyter notebook

Part 1: Use remote backend

Now we have finished all the installation. If you want to run QISKit locally, you can start the coding part now.

But if you want to execute the code on a quantum chip, there is one last step left, which is to get an IBM Q token:

  1. Create an IBM Q account if you do not have one.
  2. Go to My Account > Advanced > API Token to get your token.
  3. Copy your token and paste it below:
# If you want to execute your code on a quantum chip:
My_token = 'XXX' # Paste your token here
from qiskit import IBMQ
# Store API credentials locally
IBMQ.save_account(My_token)

Here after this process, a file named qiskit.ipynb will be created. You should find the location of that file on your computer, and create another file named Qconfig.py in that folder with the following content:

APItoken = 'PUT_YOUR_API_TOKEN_HERE'

config = {
    'url': 'https://quantumexperience.ng.bluemix.net/api'
}

A more detailed tutorial for this process can be found here.

# If you want to execute your code on a quantum chip:
from qiskit.backends.ibmq import least_busy
# Authenticate for access to remote backends

try:
    import Qconfig
    IBMQ.enable_account(Qconfig.APItoken, Qconfig.config['url'])
except:
    print("""WARNING: There's no connection with the API for remote backends.
             Have you initialized a Qconfig.py file with your personal token?
             For now, there's only access to local simulator backends...""")
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值