内容参考官方文档 https://qiskit.org/documentation/install.html

  1. conda create -n name_of_my_env python=3

    创建虚拟环境,如果后面要下载qiskit[visualization],这里的python要安装3.6版本,不然后面安装pywinpty时,会有冲突,目前3.7和3.8版本都有问题。

  2. conda activate name_of_my_env

    激活虚拟环境,然后在虚拟环境里安包

  3. pip install qiskit

    这里可以直接安装,目前的qiskit已经到了0.16版本,目前有人安装的时候numpy的版本可能不匹配,需要安装对应版本。

  4. pip install qiskit[visualization]

    如果希望能够把线路图画出来,那么需要安装visualization,安装python3.6版本就不会有冲突。

至此,Qiskit的安装成功,如果要检验的话,这里有一段最为简单的代码,使用的是IBM的量子模拟器,如果你安装成功,将能直接运行得到答案。

import numpy as np
from qiskit import(
QuantumCircuit,
execute,
Aer)
from qiskit.visualization import plot_histogram # Use Aer's qasm_simulator
simulator = Aer.get_backend('qasm_simulator') # Create a Quantum Circuit acting on the q register
circuit = QuantumCircuit(2, 2) # Add a H gate on qubit 0
circuit.h(0) # Add a CX (CNOT) gate on control qubit 0 and target qubit 1
circuit.cx(0, 1) # Map the quantum measurement to the classical bits
circuit.measure([0,1], [0,1]) # Execute the circuit on the qasm simulator
job = execute(circuit, simulator, shots=1000) # Grab results from the job
result = job.result() # Returns counts
counts = result.get_counts(circuit)
print("\nTotal count for 00 and 11 are:",counts) # Draw the circuit
circuit.draw()

关于python的小伙伴,有一个常用的网页交互的小伙伴,Jupyter notebook。

关于安装,因为我直接采用的就是anaconda,所以直接就安装好了,不过现在直接使用jupyter notebook有一个问题,那就是,不能找到我们先前创造的conda环境,这里就需要进一步的配置。

  1. conda install ipykernel

    在base的环境里安装ipykernel,问y/n的那就都y了

  2. python -m ipykernel install --user --name 环境名称 --display-name "在jupyter中显示的环境名称"

    前一个环境名称是刚刚conda创建的虚拟环境的名字,后一个是jupyter中显示的名字,可以和前面的不一样。

这个时候再打开jupyter notebook : jupyter notebook,在new的地方就能看见新的环境了。

执行一下先前的代码,得到结果:

目前我们使用的是simulator,但是我们选择IBM一定是眼馋他的量子计算机,而不仅仅是个模拟,所以我们的下一步,就是想要来连上我们的真机器。

  1. 创建一个IBM的账号 https://quantum-computing.ibm.com/login

  2. 在My Account的地方复制自己的API token

  3. 运行以下语句:把引号中的字符串替换成自己的token

    from qiskit import IBMQ
    IBMQ.save_account('MY_API_TOKEN')
  4. 运行以下语句:

    IBMQ.load_account() # Load account from disk 前面我们已经把账号存好了,现在直接加载下来就好。
    IBMQ.providers() # List all available providers

不过这里可能出现一下问题

SSLEOFError: EOF occurred in violation of protocol (_ssl.c:852)

我搜到的解决方法有:

pip install ndg-httpsclient
pip install pyopenssl
pip install pyasn1

但是这样也可能解决不了问题,因为ssl的问题还有可能是开了代理(比如你的fq),当你关了代理的时候,SSLEOFError的问题就解决了。

这个时候你再查一查有哪些机器是可以给你用的,得到结果:

[<AccountProvider for IBMQ(hub='ibm-q', group='open', project='main')>]

这个时候,我们已经愉快地和真的机器有了联系。

我们重跑上面的代码,但是这次我们选择真的机器来跑,IBM有不止一个的机器还有自己的名字:ibmq_qasm_simulator,ibmq_16_melbourne,ibmq_ourense,ibmqx2,ibmq_vigo等等

import numpy as np
from qiskit import(
QuantumCircuit,
execute,
Aer)
from qiskit.visualization import plot_histogram from qiskit import IBMQ provider = IBMQ.load_account()
backend = provider.get_backend('ibmq_16_melbourne') # Create a Quantum Circuit acting on the q register
circuit = QuantumCircuit(2, 2) # Add a H gate on qubit 0
circuit.h(0) # Add a CX (CNOT) gate on control qubit 0 and target qubit 1
circuit.cx(0, 1) # Map the quantum measurement to the classical bits
circuit.measure([0,1], [0,1]) # Execute the circuit on the qasm simulator
job = execute(circuit, backend, shots=1000) # Grab results from the job
result = job.result() # Returns counts
counts = result.get_counts(circuit)
print("\nTotal count for 00 and 11 are:",counts) # Draw the circuit
circuit.draw()

在真的机器上跑要等一会,排个队,等前面的人跑完了再轮到你,让我们来看看这个期待的结果:

因为有噪声的存在,所以原本不该出现的01,10也会产生,这也是真机和模拟器的区别。

Qiskit 安装指南的更多相关文章

  1. nGrinder安装指南

    NGrinder 由两个模块组成,其运行环境为 Oracle JDK 1.6 nGrinder controller  web 应用程序,部署在Tomcat 6.x 或更高的版本 nGrinder A ...

  2. postgresql pgsql最新版安装指南及数据存储路径更改及主从配置

    postgresql pgsql最新版安装指南及数据存储路径更改及主从配置 安装指南 首先在apt的list添加你当前系统版本对应的apt列表 目前官网有16.04,14.04,12.04 分别对应下 ...

  3. 全新 Mac 安装指南(编程篇)(环境变量、Shell 终端、SSH 远程连接)

    注:本文专门用于指导对计算机编程与设计(尤其是互联网产品开发与设计)感兴趣的 Mac 新用户,如何在 Mac OS X 系统上配置开发与上网环境,另有<全新 Mac 安装指南(通用篇)>作 ...

  4. 全新 Mac 安装指南(通用篇)(推荐设置、软件安装、推荐软件)

    注:本文将会不定期维护与更新,有需要的朋友请在 Github 上订阅该条 Issues:<全新 Mac 安装指南(通用篇)>. 在 Mac 电脑上只用 Windows 操作系统的同学请看到 ...

  5. ArchLinux安装指南

    将ArchLinux作为进阶Linux发行版,主要看重滚动更新和深入理解Linux的安装过程. 由于是新手,所以先选择在公司电脑上用VMware来安装.然后渐进到借助U盘在win10笔记本上安装双系统 ...

  6. Linux环境中Openfire安装指南

    Linux环境中Openfire安装指南 安装环境: 安装软件:Openfire 4_1_0 http://download.igniterealtime.org/openfire/openfire_ ...

  7. scrapy3_ 安装指南

    安装指南 安装Scrapy 注解 请先阅读 平台安装指南. 下列的安装步骤假定您已经安装好下列程序: Python 2.7 Python Package: pip and setuptools. 现在 ...

  8. storm 原理简介及单机版安装指南——详细版【转】

    storm 原理简介及单机版安装指南 本文翻译自: https://github.com/nathanmarz/storm/wiki/Tutorial 原文链接自:http://www.open-op ...

  9. mac osx 系统 brew install hadoop 安装指南

    mac osx 系统 brew  install hadoop 安装指南   brew install hadoop 配置 core-site.xml:配置hdfs文件地址(记得chmod 对应文件夹 ...

随机推荐

  1. PyTorch常用参数初始化方法详解

    1. 均匀分布 torch.nn.init.uniform_(tensor, a=0, b=1) 从均匀分布U(a, b)中采样,初始化张量. 参数: tensor - 需要填充的张量 a - 均匀分 ...

  2. 全宇宙首个.NET5+Vue.js前后端分离以及业务模块化快速开发框架【NetModular】发布~

    最近.Net圈子很热闹啊,我也来凑凑,今天中午耗时长达半小时,把NetModular升级到了.NET5,详情查看分支https://github.com/iamoldli/NetModular/tre ...

  3. 人生第一篇博客 , 当然是经典的 "Hello World"

    package com.cqvie.Hello; public class FirstDemo {  public static void main(String[] args) {  System. ...

  4. Spring Boot注解与资源文件配置

    date: 2018-11-18 16:57:17 updated: 2018-11-18 16:57:17 1.不需要多余的配置文件信息 application.properties mybatis ...

  5. 模型评价指标:AUC

    参考链接:https://www.iteye.com/blog/lps-683-2387643 问题: AUC是什么 AUC能拿来干什么 AUC如何求解(深入理解AUC) AUC是什么 混淆矩阵(Co ...

  6. Redis学习笔记(二)——Keys通用操作

    1.查询所有key: keys * 2.*通用符(代表0或多),查询所有以n(*)开头的key: keys n* 3.?通用符(代表1个字符): key n? 4.del删除key [key1 key ...

  7. EXPECT交互式批量上传公钥

    EXPECT交互式批量上传公钥 # vim key.sh #/bin/bash Public_Key() { [ ! -f /usr/bin/expect ] && yum insta ...

  8. Java学习的第二十五天

    1.字节流输出内容 用字节流读文件内容 字符输出流写入 字符输入流 2.没问题 3.明天学习到缓冲流

  9. 容器探针(liveness and readiness probe)

    一.为什么需要容器探针 如何保持Pod健康   只要将pod调度到某个节点,Kubelet就会运行pod的容器,如果该pod的容器有一个或者所有的都终止运行(容器的主进程崩溃),Kubelet将重启容 ...

  10. Python爬虫urllib模块

    Python爬虫练习(urllib模块) 关注公众号"轻松学编程"了解更多. 1.获取百度首页数据 流程:a.设置请求地址 b.设置请求时间 c.获取响应(对响应进行解码) ''' ...