Notepad/enter/Machine Tips (Quantum)/Project Vault/Quantum Master's Paper/Code Samples/templates/Exercise 1.md

46 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

2023-07-05 18:29:11 +00:00
Exercise 1 - Here is a general outline of qisket circuit template. Transpiled the quantum circuit on the IBM-Q backend and draws the optimized circuit. This is a great first step to visualize what's going on. Custom code is what you input in the commented area and I give you samples for that in the next section.
```python
import qiskit
# Qiskit quantum circuits libraries
quantum_circuit = qiskit.circuit.library.QuantumVolume(5)
quantum_circuit.measure_all()
quantum_circuit.draw()
# prepare your circuit to run
from qiskit import IBMQ
# Get the API token in
# https://quantum-computing.ibm.com/
IBMQ.save_account("YOUR TOKEN")
provider = IBMQ.load_account()
backend = provider.get_backend('ibmq_quito')
optimized_circuit = qiskit.transpile(quantum_circuit, backend)
optimized_circuit.draw()
# run in real hardware
job = backend.run(optimized_circuit)
# this is where I put my code
retrieved_job = backend.retrieve_job(job.job_id())
result = retrieved_job.result()
print(result.get_counts())
```
[Reference here](https://lab.quantum-computing.ibm.com/hub/spawn-pending/5d798394a5375400195c9658?next=%2Fhub%2Fuser%2F5d798394a5375400195c9658%2Flab%2Ftree%2Fqiskit-textbook%2Fgetting-started%2Fexample.ipynb)