single-qubit-gates
July 9, 2021
[5]: import numpy as np
# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, transpile, Aer, IBMQ, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *
from math import pi, sqrt
# Loading your IBM Quantum account(s)
provider = IBMQ.load_account()
sim = Aer.get_backend('aer_simulator')
ibmqfactory.load_account:WARNING:2021-07-09 12:42:26,306: Credentials are
already in use. The existing account in the session will be replaced.
[6]: # Let's do an X-gate on a |0> qubit
qc = QuantumCircuit(1)
qc.x(0)
qc.draw()
[6]:
[7]: # Let's see the result
qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)
/opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69:
MatplotlibDeprecationWarning:
The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor
1
releases later. Use self.axes.M instead.
x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
[7]:
[8]: # Run the code in this cell to see the widget
from qiskit_textbook.widgets import gate_demo
gate_demo(gates='pauli')
/opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69:
MatplotlibDeprecationWarning:
The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor
releases later. Use self.axes.M instead.
x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
HBox(children=(Button(description='X', layout=Layout(height='3em', width='3em'), style=ButtonSt
Image(value=b'x89PNGrnx1anx00x00x00rIHDRx00x00x01 x00x00x01 x08x06x00x00x00
[9]: qc.y(0) # Do Y-gate on qubit 0
qc.z(0) # Do Z-gate on qubit 0
qc.draw()
[9]:
2
[10]: # Run the code in this cell to see the widget
from qiskit_textbook.widgets import gate_demo
gate_demo(gates='pauli+h')
/opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69:
MatplotlibDeprecationWarning:
The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor
releases later. Use self.axes.M instead.
x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
HBox(children=(Button(description='X', layout=Layout(height='3em', width='3em'), style=ButtonSt
Image(value=b'x89PNGrnx1anx00x00x00rIHDRx00x00x01 x00x00x01 x08x06x00x00x00
[11]: # Create the X-measurement function:
def x_measurement(qc, qubit, cbit):
"""Measure 'qubit' in the X-basis, and store the result in 'cbit'"""
qc.h(qubit)
qc.measure(qubit, cbit)
return qc
initial_state = [1/sqrt(2), -1/sqrt(2)]
# Initialize our qubit and measure it
qc = QuantumCircuit(1,1)
qc.initialize(initial_state, 0)
x_measurement(qc, 0, 0) # measure qubit 0 to classical bit 0
qc.draw()
[11]:
3
[12]: qobj = assemble(qc) # Assemble circuit into a Qobj that can be run
counts = sim.run(qobj).result().get_counts() # Do the simulation, returning␣
,
→the state vector
plot_histogram(counts) # Display the output on measurement of state vector
[12]:
[13]: # Run the code in this cell to see the widget
from qiskit_textbook.widgets import gate_demo
gate_demo(gates='pauli+h+p')
/opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69:
MatplotlibDeprecationWarning:
The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor
releases later. Use self.axes.M instead.
x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
VBox(children=(HBox(children=(Button(description='X', layout=Layout(height='3em', width='3em'),
Image(value=b'x89PNGrnx1anx00x00x00rIHDRx00x00x01 x00x00x01 x08x06x00x00x00
4
[14]: qc = QuantumCircuit(1)
qc.p(pi/4, 0)
qc.draw()
[14]:
[15]: qc = QuantumCircuit(1)
qc.s(0) # Apply S-gate to qubit 0
qc.sdg(0) # Apply Sdg-gate to qubit 0
qc.draw()
[15]:
[16]: qc = QuantumCircuit(1)
qc.t(0) # Apply T-gate to qubit 0
qc.tdg(0) # Apply Tdg-gate to qubit 0
qc.draw()
[16]:
[17]: # Run the code in this cell to see the widget
from qiskit_textbook.widgets import gate_demo
gate_demo()
/opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69:
MatplotlibDeprecationWarning:
The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor
5
releases later. Use self.axes.M instead.
x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
VBox(children=(HBox(children=(Button(description='I', layout=Layout(height='3em', width='3em'),
Image(value=b'x89PNGrnx1anx00x00x00rIHDRx00x00x01 x00x00x01 x08x06x00x00x00
[ ]: #Executed by Bhadale IT in IBM Quantum Lab ( https://www.bhadaleit.com)
6

More Related Content

PDF
Multi qubit entanglement
PDF
Quantum circuit example in Qiskit
PDF
Grover's Algorithm
PDF
Qsam simulator in IBM Quantum Lab cloud
PDF
Quantum neural network
PDF
Azure Quantum with IBM Qiskit and IonQ QPU
KEY
Grand centraldispatch
PDF
The Ring programming language version 1.7 book - Part 67 of 196
Multi qubit entanglement
Quantum circuit example in Qiskit
Grover's Algorithm
Qsam simulator in IBM Quantum Lab cloud
Quantum neural network
Azure Quantum with IBM Qiskit and IonQ QPU
Grand centraldispatch
The Ring programming language version 1.7 book - Part 67 of 196

What's hot (20)

PDF
The Ring programming language version 1.2 book - Part 43 of 84
PDF
Richard Salter: Using the Titanium OpenGL Module
PDF
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
PDF
オープンデータを使ったモバイルアプリ開発(応用編)
PDF
The Ring programming language version 1.5.4 book - Part 62 of 185
PDF
The Ring programming language version 1.10 book - Part 78 of 212
KEY
Cocos2d実践編 1.0.0rc
PDF
The Ring programming language version 1.3 book - Part 45 of 88
PDF
The Ring programming language version 1.9 book - Part 75 of 210
PDF
C# Assignmet Help
PDF
Ns2: Introduction - Part I
PDF
Ns2: OTCL - PArt II
PPTX
Synapse india dotnet development overloading operater part 4
PDF
The Ring programming language version 1.7 book - Part 69 of 196
PDF
The Ring programming language version 1.5.3 book - Part 72 of 184
PDF
The Ring programming language version 1.8 book - Part 69 of 202
PDF
Zone.js 2017
PDF
The Ring programming language version 1.2 book - Part 44 of 84
PDF
Understanding the nodejs event loop
PDF
201801 CSE240 Lecture 15
The Ring programming language version 1.2 book - Part 43 of 84
Richard Salter: Using the Titanium OpenGL Module
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
オープンデータを使ったモバイルアプリ開発(応用編)
The Ring programming language version 1.5.4 book - Part 62 of 185
The Ring programming language version 1.10 book - Part 78 of 212
Cocos2d実践編 1.0.0rc
The Ring programming language version 1.3 book - Part 45 of 88
The Ring programming language version 1.9 book - Part 75 of 210
C# Assignmet Help
Ns2: Introduction - Part I
Ns2: OTCL - PArt II
Synapse india dotnet development overloading operater part 4
The Ring programming language version 1.7 book - Part 69 of 196
The Ring programming language version 1.5.3 book - Part 72 of 184
The Ring programming language version 1.8 book - Part 69 of 202
Zone.js 2017
The Ring programming language version 1.2 book - Part 44 of 84
Understanding the nodejs event loop
201801 CSE240 Lecture 15
Ad

Similar to Single qubit-gates operations (20)

PDF
Probability of finding a single qubit in a state
PDF
Quantum Computing Notes Ver1.0
PDF
Quantum Computing Notes Ver 1.2
PDF
Cassandra Day Denver 2014: Building Java Applications with Apache Cassandra
PDF
Hybrid quantum classical neural networks with pytorch and qiskit
PPT
Project seminar ppt_steelcasting
PDF
Scripting Your Qt Application
PDF
Copy Your Favourite Nokia App with Qt
PDF
Kafka Summit NYC 2017 - The Best Thing Since Partitioned Bread
PPTX
PVS-Studio team experience: checking various open source projects, or mistake...
PDF
Drawing with Quartz on iOS
PDF
The Unicorn Getting Interested in KDE
PDF
The Ring programming language version 1.9 book - Part 78 of 210
PDF
Scala to assembly
ODP
Matlab robotics toolbox
PDF
writing-custom-qtquickcomponents-QtCon.pdf
PDF
The Ring programming language version 1.2 book - Part 48 of 84
PDF
SCIPY-SYMPY.pdf
PPTX
Detection of errors and potential vulnerabilities in C and C++ code using the...
PPTX
Score (smart contract for icon)
Probability of finding a single qubit in a state
Quantum Computing Notes Ver1.0
Quantum Computing Notes Ver 1.2
Cassandra Day Denver 2014: Building Java Applications with Apache Cassandra
Hybrid quantum classical neural networks with pytorch and qiskit
Project seminar ppt_steelcasting
Scripting Your Qt Application
Copy Your Favourite Nokia App with Qt
Kafka Summit NYC 2017 - The Best Thing Since Partitioned Bread
PVS-Studio team experience: checking various open source projects, or mistake...
Drawing with Quartz on iOS
The Unicorn Getting Interested in KDE
The Ring programming language version 1.9 book - Part 78 of 210
Scala to assembly
Matlab robotics toolbox
writing-custom-qtquickcomponents-QtCon.pdf
The Ring programming language version 1.2 book - Part 48 of 84
SCIPY-SYMPY.pdf
Detection of errors and potential vulnerabilities in C and C++ code using the...
Score (smart contract for icon)
Ad

More from Vijayananda Mohire (20)

PDF
Bhadale QAI Hub - for multicloud, multitechnology platform
PDF
Practical_Introduction_to_Quantum_Safe_Cryptography
PDF
Progress Report- MIT Course 8.371.3x - VD-Mohire
PDF
Quantum Communications Q&A with Gemini LLM
PDF
Peer Review Certificate for Journal of Engg
PDF
Quantum Algorithms for Electronics - IEEE Certificate
PDF
NexGen Solutions for cloud platforms, powered by GenQAI
PDF
Certificate- Peer Review of Book Chapter on ML
PDF
Key projects Data Science and Engineering
PDF
Key projects Data Science and Engineering
PDF
Bhadale IT Hub-Multi Cloud and Multi QAI
PDF
My key hands-on projects in Quantum, and QAI
PDF
Azure Quantum Workspace for developing Q# based quantum circuits
PDF
Key projects in AI, ML and Generative AI
PDF
My Journey towards Artificial Intelligence
PDF
Bhadale IT Cloud Solutions for Agriculture
PDF
Bhadale IT Cloud Solutions for Agriculture
PDF
Bhadale IT Intel and Azure Cloud Offerings
PDF
GitHub Copilot-vijaymohire
PDF
Practical ChatGPT From Use Cases to Prompt Engineering & Ethical Implications
Bhadale QAI Hub - for multicloud, multitechnology platform
Practical_Introduction_to_Quantum_Safe_Cryptography
Progress Report- MIT Course 8.371.3x - VD-Mohire
Quantum Communications Q&A with Gemini LLM
Peer Review Certificate for Journal of Engg
Quantum Algorithms for Electronics - IEEE Certificate
NexGen Solutions for cloud platforms, powered by GenQAI
Certificate- Peer Review of Book Chapter on ML
Key projects Data Science and Engineering
Key projects Data Science and Engineering
Bhadale IT Hub-Multi Cloud and Multi QAI
My key hands-on projects in Quantum, and QAI
Azure Quantum Workspace for developing Q# based quantum circuits
Key projects in AI, ML and Generative AI
My Journey towards Artificial Intelligence
Bhadale IT Cloud Solutions for Agriculture
Bhadale IT Cloud Solutions for Agriculture
Bhadale IT Intel and Azure Cloud Offerings
GitHub Copilot-vijaymohire
Practical ChatGPT From Use Cases to Prompt Engineering & Ethical Implications

Recently uploaded (20)

PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PPTX
Module 1 Introduction to Web Programming .pptx
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PPTX
Training Program for knowledge in solar cell and solar industry
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PDF
Statistics on Ai - sourced from AIPRM.pdf
PDF
Data Virtualization in Action: Scaling APIs and Apps with FME
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PDF
Auditboard EB SOX Playbook 2023 edition.
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPTX
Configure Apache Mutual Authentication
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
Module 1 Introduction to Web Programming .pptx
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
Taming the Chaos: How to Turn Unstructured Data into Decisions
Training Program for knowledge in solar cell and solar industry
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
Statistics on Ai - sourced from AIPRM.pdf
Data Virtualization in Action: Scaling APIs and Apps with FME
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
Early detection and classification of bone marrow changes in lumbar vertebrae...
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
Auditboard EB SOX Playbook 2023 edition.
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
giants, standing on the shoulders of - by Daniel Stenberg
Comparative analysis of machine learning models for fake news detection in so...
sustainability-14-14877-v2.pddhzftheheeeee
Configure Apache Mutual Authentication

Single qubit-gates operations

  • 1. single-qubit-gates July 9, 2021 [5]: import numpy as np # Importing standard Qiskit libraries from qiskit import QuantumCircuit, transpile, Aer, IBMQ, assemble from qiskit.tools.jupyter import * from qiskit.visualization import * from ibm_quantum_widgets import * from math import pi, sqrt # Loading your IBM Quantum account(s) provider = IBMQ.load_account() sim = Aer.get_backend('aer_simulator') ibmqfactory.load_account:WARNING:2021-07-09 12:42:26,306: Credentials are already in use. The existing account in the session will be replaced. [6]: # Let's do an X-gate on a |0> qubit qc = QuantumCircuit(1) qc.x(0) qc.draw() [6]: [7]: # Let's see the result qc.save_statevector() qobj = assemble(qc) state = sim.run(qobj).result().get_statevector() plot_bloch_multivector(state) /opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69: MatplotlibDeprecationWarning: The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor 1
  • 2. releases later. Use self.axes.M instead. x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) [7]: [8]: # Run the code in this cell to see the widget from qiskit_textbook.widgets import gate_demo gate_demo(gates='pauli') /opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69: MatplotlibDeprecationWarning: The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use self.axes.M instead. x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) HBox(children=(Button(description='X', layout=Layout(height='3em', width='3em'), style=ButtonSt Image(value=b'x89PNGrnx1anx00x00x00rIHDRx00x00x01 x00x00x01 x08x06x00x00x00 [9]: qc.y(0) # Do Y-gate on qubit 0 qc.z(0) # Do Z-gate on qubit 0 qc.draw() [9]: 2
  • 3. [10]: # Run the code in this cell to see the widget from qiskit_textbook.widgets import gate_demo gate_demo(gates='pauli+h') /opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69: MatplotlibDeprecationWarning: The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use self.axes.M instead. x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) HBox(children=(Button(description='X', layout=Layout(height='3em', width='3em'), style=ButtonSt Image(value=b'x89PNGrnx1anx00x00x00rIHDRx00x00x01 x00x00x01 x08x06x00x00x00 [11]: # Create the X-measurement function: def x_measurement(qc, qubit, cbit): """Measure 'qubit' in the X-basis, and store the result in 'cbit'""" qc.h(qubit) qc.measure(qubit, cbit) return qc initial_state = [1/sqrt(2), -1/sqrt(2)] # Initialize our qubit and measure it qc = QuantumCircuit(1,1) qc.initialize(initial_state, 0) x_measurement(qc, 0, 0) # measure qubit 0 to classical bit 0 qc.draw() [11]: 3
  • 4. [12]: qobj = assemble(qc) # Assemble circuit into a Qobj that can be run counts = sim.run(qobj).result().get_counts() # Do the simulation, returning␣ , →the state vector plot_histogram(counts) # Display the output on measurement of state vector [12]: [13]: # Run the code in this cell to see the widget from qiskit_textbook.widgets import gate_demo gate_demo(gates='pauli+h+p') /opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69: MatplotlibDeprecationWarning: The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use self.axes.M instead. x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) VBox(children=(HBox(children=(Button(description='X', layout=Layout(height='3em', width='3em'), Image(value=b'x89PNGrnx1anx00x00x00rIHDRx00x00x01 x00x00x01 x08x06x00x00x00 4
  • 5. [14]: qc = QuantumCircuit(1) qc.p(pi/4, 0) qc.draw() [14]: [15]: qc = QuantumCircuit(1) qc.s(0) # Apply S-gate to qubit 0 qc.sdg(0) # Apply Sdg-gate to qubit 0 qc.draw() [15]: [16]: qc = QuantumCircuit(1) qc.t(0) # Apply T-gate to qubit 0 qc.tdg(0) # Apply Tdg-gate to qubit 0 qc.draw() [16]: [17]: # Run the code in this cell to see the widget from qiskit_textbook.widgets import gate_demo gate_demo() /opt/conda/lib/python3.8/site-packages/qiskit/visualization/bloch.py:69: MatplotlibDeprecationWarning: The M attribute was deprecated in Matplotlib 3.4 and will be removed two minor 5
  • 6. releases later. Use self.axes.M instead. x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) VBox(children=(HBox(children=(Button(description='I', layout=Layout(height='3em', width='3em'), Image(value=b'x89PNGrnx1anx00x00x00rIHDRx00x00x01 x00x00x01 x08x06x00x00x00 [ ]: #Executed by Bhadale IT in IBM Quantum Lab ( https://www.bhadaleit.com) 6