Skip to main content
33 votes
Accepted

What is a "barrier" in Qiskit circuits?

You won't find the barrier in quantum computing textbooks because it isn't a standard primitive of quantum information theory like unitary gates and quantum circuits. The barrier acts as a directive ...
cjwood's user avatar
  • 1,221
28 votes

How do I build a gate from a matrix on Qiskit?

You can build your gate with Operator and unitary function e.g: ...
iUrii's user avatar
  • 481
25 votes

How can I implement an n-bit Toffoli gate?

A simple way to do this is illustrated in Figure 4.10 of Nielsen & Chuang. Where U can be any single-qubit rotation (in this case, an X gate). This circuit works like this: We want to apply U ...
Ali Javadi's user avatar
  • 1,632
24 votes
Accepted

What's meant by the depth of a quantum circuit?

The depth of a circuit is the longest path in the circuit. The path length is always an integer number, representing the number of gates it has to execute in that path. For example, the following ...
KAJ226's user avatar
  • 13.9k
19 votes

How can I obtain transformation matrix of a quantum circuit in the Qiskit?

While you can get the unitary matrix representation of a circuit using the unitary simulator as shown in the other answers, there is a much easier way using the ...
cjwood's user avatar
  • 1,221
17 votes
Accepted

Phase-Shift Gate in Qiskit

You can implement the phase shift gate $$P_h(\theta) = \begin{pmatrix}e^{i\theta} & 0\\0 & e^{i\theta}\end{pmatrix}$$ with the X and ...
Adrien Suau's user avatar
  • 4,987
17 votes
Accepted

Evaluating expectation values of operators in Qiskit

Note: This post is a bit older and Qiskit Aqua is now deprecated. Replace all occurences of qiskit.aqua.operators with ...
Cryoris's user avatar
  • 2,953
17 votes
Accepted

How to measure in another basis

Yes, your solution is correct. Please find here circuits for measurement in z (computational), y (circular) and x (Hadamard) bases: Source: Quantum Algorithm Implementations for Beginners, pg. 68. ...
Martin Vesely's user avatar
17 votes
Accepted

Is Qiskit more popular than cirq? Why?

The answer above, from a Cirq developer, is mostly in the right direction. We (Qiskit / IBM) probably do spend more on outreach and education (I also do not know for sure). Democratization of ...
Paul Nation's user avatar
  • 2,239
16 votes
Accepted

Big Endian vs. Little Endian in Qiskit

Qiskit uses little-endian for both classical bit ordering and qubit ordering. For classical bits: A 3-bit classical register creg with value ...
cjwood's user avatar
  • 1,221
15 votes
Accepted

How good is basic_device_noise_model() simulating the noise in the quantum computer?

There is no specific paper for this, though information on the model can be found in the Qiskit Aer API documentation and is based on the research of IBMQ quantum computing group. As examples you can ...
cjwood's user avatar
  • 1,221
14 votes

Is Qiskit more popular than cirq? Why?

Completely speculating here, but I think the main differentiator is that IBM has a stated goal of, and spends significant resources on, getting quantum computing into everyone's hands. For example, ...
Craig Gidney's user avatar
  • 38.5k
14 votes
Accepted

Why isn't $Ry(\pi/2)$ gate equivalent to Hadamard gate?

While Hadamard gate is defined as $$ H= \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}, $$ $y$-rotation by $\pi/2$ leads to gate $$ Ry(\pi/2)= \frac{1}{\sqrt{2}} \begin{...
Martin Vesely's user avatar
13 votes

How can I implement an n-bit Toffoli gate?

I want to add a method that does not use ancilla qubits, but does require gates more complicated than just controlled-not. I believe this method was first presented by Barenco et. al. in this paper, ...
myorbs's user avatar
  • 231
13 votes
Accepted

Intuition behind the construction of an ansatz circuit

Interesting question! An ansatz circuit is a parameterized circuit, say $V(\theta)$ where $\theta$ are a set of parameters, used to prepare a trial state for your problem: $$ |\Psi(\theta)\rangle = V(\...
Cryoris's user avatar
  • 2,953
12 votes
Accepted

What does the error rate on the IBMQ website mean?

Readout error: do a bunch (1000's) of experiments preparing the qubit in either the 0 state or the 1 state and then immediately measuring the qubit state after each preparation. Two types of readout ...
Doug McClure's user avatar
12 votes

Transpilation into custom gate set in qiskit

The Qiskit standard gate list You can find the full list of Qiskit standard gates in the module qiskit.circuit.library.standard_gates (documentation). The matrix ...
luciano's user avatar
  • 5,813
11 votes

How is the Grover-Algorithm applied to a database?

I've been working on this problem as well. As a beginner and a classical programmer (i.e., I don't speak Quantum Mechanics), it is difficult to get an understanding of the concepts without complete ...
Joel Leach's user avatar
11 votes
Accepted

What does fidelity mean?

It might be worth mentioning the physical motivation for these definitions and the concept of fidelity itself. Unlike the classical computers we all know and love, quantum computers are ...
MMK1137's user avatar
  • 366
11 votes
Accepted

What is the relationship between Choi and Chi matrix in Qiskit?

( I copied some text from a previous answer of mine) Defining the Choi and $\chi$ matrix The Choi matrix is a direct result of the Choi-Jamiolkowski isomorphism. Some intuition on what this is can be ...
JSdJ's user avatar
  • 5,539
11 votes
Accepted

Qiskit CNOT-gate matrix mixup?

Qiskit uses "little endian" bit ordering. That means, if A and B are $2 \times 2$ unitary matrices then $B \otimes A$ (note the order) is equivalent to applying $A$ to first qubit and $B$ to ...
Egretta.Thula's user avatar
11 votes
Accepted

What are the differences between Qiskit's AerSimulator, QasmSimulator and StatevectorSimulator?

Deprecation Note: The StatevectorSimulator has been superseded by the AerSimulator and will be deprecated in the future. It has ...
Egretta.Thula's user avatar
10 votes
Accepted

What are theta, phi and lambda in cu1(theta, ctl, tgt) and cu3(theta, phi, lam, ctl, tgt)? What are the rotation matrices being used?

From IBM Q Documentation (the link is hard to find) here is the definition of the generic gate: $$ U(\theta, \phi, \lambda) = \begin{pmatrix} \cos\left(\frac{\theta}{2}\right) & -e^{i\lambda} \...
Adrien Suau's user avatar
  • 4,987
10 votes

How can I implement an n-bit Toffoli gate?

Qiskit's QuantumCircuit has mct method to build multiple-control Toffoli gate with several modes: basic, basic-dirty-ancilla, advanced, noancilla. For instance Toffoli gate with 3 control qubits: <...
iUrii's user avatar
  • 481
10 votes
Accepted

Can I remove gates from a QuantumCircuit?

Quantum circuits have a data attribute, which is a list of all gates. You can remove elements from this as with any Python list. For example, here's a circuit <...
James Wootton's user avatar
10 votes
Accepted

How to calculate an Expected Value of some operator acting on qubits?

Qiskit currently supports measurements in the computational basis from Qiskit Terra and Aer, that is, returning 1 if the qubit is in state $|1\rangle$, and ...
Josh Izaac's user avatar
10 votes
Accepted

How to selectively apply noise in Qiskit simulations?

Yes you can: When you build a noise model the noise is defined with respect to the name or label of gate objects, so you can use the labelto create multiple versions of a single gate but reference ...
cjwood's user avatar
  • 1,221
9 votes
Accepted

How to create an arbitrary state in QISKit for a local_qasm_simulator?

I think you can use the initialize function as detailed at the section "Arbitrary Initialization" at this tutorial. As an example, this tutorial ...
Rudy Raymond Harry Putra's user avatar
9 votes

How do I build a gate from a matrix on Qiskit?

Here's the circuit for your specific case: I made it manually, by entering the matrix into Quirk, diagonalizing the matrix by adding operations, then simplifying the operations. It's not too hard to ...
Craig Gidney's user avatar
  • 38.5k
9 votes
Accepted

How to run a qasm file on IBMQ device?

This is a example for loading QASM, executing and displaying the result. ...
gyu-don's user avatar
  • 324

Only top scored, non community-wiki answers of a minimum length are eligible