Updated Doing Nothing with Qiskit In this notebook, we demonstrate how to create and execute a quantum circuit using Qiskit. This updated code works with the latest version of Qiskit, addressing previous issues with deprecated functions and imports.
작성자 정보
- 작성자 bryanai
- 작성일
컨텐츠 정보
- 조회 87
본문
https://github.com/qiskit-community/qiskit-community-tutorials/blob/master/hello_world/hello_zero.ipynb
Updated Doing Nothing with Qiskit
In this notebook, we demonstrate how to create and execute a quantum circuit using Qiskit. This updated code works with the latest version of Qiskit, addressing previous issues with deprecated functions and imports.
Importing Necessary Libraries
First, we need to import the required libraries:
import qiskit
import qiskit_aer
Creating Quantum and Classical Registers
We create a quantum register with 1 qubit and a classical register with 1 bit to store measurement results:
qr = qiskit.QuantumRegister(1)
cr = qiskit.ClassicalRegister(1)
program = qiskit.QuantumCircuit(qr, cr)
Defining the Quantum Circuit
Next, we define the quantum circuit and add a measurement operation:
program.measure(qr, cr)
<qiskit.circuit.instructionset.InstructionSet at 0x1f13fe2f100>
Selecting the Backend and Transpiling the Circuit
We choose the qasm_simulator backend from Aer for simulation. The circuit is then transpiled to be compatible with this backend:
backend = qiskit_aer.Aer.get_backend('qasm_simulator')
program_ = qiskit.transpile(program, backend)
job = backend.run(program_)
Running the Circuit and Retrieving Results
Finally, we run the transpiled circuit on the simulator and print the results:
result = job.result()
counts = result.get_counts()
print(counts)
{'0': 1024}
Great! Now you are ready to create and execute programs!
관련자료
-
링크
-
이전
-
다음