Quantum Computing Simulation
Published:
基于IBM提供的qiskit库进行量子计算模拟
Quantum computing simulation based on the qiskit library provided by IBM
以下为安装指令
The following are the installation instructions
pip install qiskit
请使用https源例如清华源执行pip安装 Windows 换源方法 - 创建文件 User/YourUserName/pip/pip.ini 内容如下
Please use https source such as Tsinghua source to perform pip installation Windows change source method-create a file User/YourUserName/pip/pip.ini with the following content
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
以下为示例代码
The following is sample code
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()
预期输出
Expected output
Total count for 00 and 11 are: {'11': 500, '00': 500}
更多见:官方文档
For more see: Official Document