29 votes
Accepted

How to derive the CNOT matrix for a 3-qubit system where the control & target qubits are not adjacent?

For a presentation from first principles, I like Ryan O'Donnell's answer. But for a slightly higher-level algebraic treatment, here's how I would do it. The main feature of a controlled-$U$ operation,...
Niel de Beaudrap's user avatar
26 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
  • 461
19 votes
Accepted

How do you implement the Toffoli gate using only single-qubit and CNOT gates?

is the decomposition (I took this from google images, originally on this website.) In order to understand how to decompose it, we can look at it's base structure. The idea is that we combine gates ...
Dripto Debroy's user avatar
16 votes
Accepted

Given a decomposition for a unitary $U$, how do you decompose the corresponding controlled unitary gate $C(U)$?

The question may not be entirely well-defined, in the sense that to ask for a way to compute $C(U)$ from a decomposition of $U$ you need to specify the set of gates that you are willing to use. Indeed,...
glS's user avatar
  • 22.9k
14 votes
Accepted

What is the mathematical justification for the "universality" of the universal set of quantum gates (CNOT, H, Z, X and π/8)?

The answer you mention references Michael Nielsen and Isaac Chuang's book, Quantum Computation and Quantum Information (Cambridge University Press), which does contain a proof of the universality of ...
Brian R. La Cour's user avatar
13 votes

How to derive the CNOT matrix for a 3-qubit system where the control & target qubits are not adjacent?

This is a good question; it's one that textbooks seem to sneak around. I reached this exact question when preparing a quantum computing lecture a couple days ago. As far as I can tell, there's no ...
Ryan O'Donnell's user avatar
13 votes

Composing the CNOT gate as a tensor product of two level matrices

The whole point is that CNOT cannot be written in the form $A\otimes B$. This is absolutely essential because if we only ever had operators of the form $A\otimes B$, states of the form $|\psi\rangle\...
DaftWullie's user avatar
  • 54.4k
12 votes
Accepted

How to implement the "Square root of Swap gate" on the IBM Q (composer)?

Here is a SQRT(SWAP) construction which only requires CNOTs in one direction, Hadamards, S gates ($Z^{\frac{1}{2}}$), S dagger gates ($Z^{-\frac{1}{2}}$), T gates ($Z^{\frac{1}{4}}$) and T dagger ...
Craig Gidney's user avatar
  • 32.4k
12 votes

How do you implement the Toffoli gate using only single-qubit and CNOT gates?

You also have this one with V the square root of NOT gate: If you have as control qubits : (0,0) : do nothing; (0,1) : apply V and its conjugate which is identity; (1,0) : same but inversed; (1,1) : ...
cnada's user avatar
  • 4,644
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,468
12 votes
Accepted

Is the Solovay-Kitaev theorem relevant for modern hardware?

I think you'll find that most hardware, at the hardware level, gives you arbitrary single qubit rotations. So, in that sense, it is true that Solovay-Kitaev is not directly applicable to current ...
DaftWullie's user avatar
  • 54.4k
11 votes

Is there any method of adding two operators in a circuit?

Below is a recent paper by Gilyén et al on doing "quantum matrix arithmetics", allowing to implement linear combinations of unitary operators. They consider the general case where the linear ...
smapers's user avatar
  • 324
10 votes
Accepted

What components are needed to realize a photonic CNOT gate?

Contrary to DaftWullie's answer, it is possible to implement a CNOT gate in a photonic system with 100% efficiency. However, there are caveats to this - it depends on what's used as the qubits (or, ...
Mithrandir24601's user avatar
  • 3,647
10 votes
Accepted

Implementing a CCCNOT gate using only Toffoli gates

I guess what you're looking for is the following circuit. Here, $b_1,b_2,b_3,b_4 \in \{0,1\}$, and $\oplus$ is addition modulo $2$. Here, the fifth qubit is used as an auxiliary, or ancilla qubit. It ...
arriopolis's user avatar
10 votes
Accepted

How does approximating gates via universal gates scale with the length of the computation?

Throughout this answer, the norm of a matrix $A$, $\left\lVert A\right\rVert$ will be taken to be the spectral norm of $A$ (that is, the largest singular value of $A$). The solovay-Kitaev theorem ...
Mithrandir24601's user avatar
  • 3,647
10 votes
Accepted

Shortest sequence of universal quantum gates that correspond to a given unitary

Getting an optimal decomposition is definitely an open problem. (And, of course, the decomposition is intractable, $\exp(n)$ gates for large $n$.) A "simpler" question you might ask first is what is ...
rrtucci's user avatar
  • 679
10 votes
Accepted

Arbitrary powers of NOT and SWAP

Let's start with some general theory. If you have a normal matrix $A$ (of which unitaries are a subset), you can define any function of that matrix $f(A)$. For example, $A^{1/2}$ or $A^{\pi}$. The ...
DaftWullie's user avatar
  • 54.4k
10 votes
Accepted

Explicit Conversion Between Universal Gate Sets

To fix what we are talking about, I think you mean $$ H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \quad S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} \quad ...
Greg Kuperberg's user avatar
10 votes
Accepted

Approximating unitary matrices

You have picked two particularly simple matrices to implement. The first operation (G) is just the square root of X gate (up to global phase): In your gate set, this is $R_X(\pi/2)$. The second ...
Craig Gidney's user avatar
  • 32.4k
10 votes
Accepted

Is there any method of adding two operators in a circuit?

What you are trying to do is called Hamiltonian Simulation. If your exponential can be split in a sum of unitary matrices, @smapers' answer guide you to a good algorithm: the Linear Combination of ...
Adrien Suau's user avatar
  • 4,777
10 votes
Accepted

How can I see, without math, the action of a gate in matrix form?

Besides the already given answers note that there is indeed some "mental gymnastics" involved here. As soon as you're getting more acquainted with quantum computing, you know some of your usual gates, ...
Johannes Jakob Meyer's user avatar
9 votes
Accepted

Obtaining gate $e^{-i\Delta t Z}$ from elementary gates

One way order to perform Z rotations by arbitrary angles is to approximate them with a sequence of Hadamard and T gates. If you need the approximation to have maximum error $\epsilon$, there are known ...
Craig Gidney's user avatar
  • 32.4k
9 votes
Accepted

How to construct a multi-qubit controlled-Z from elementary gates?

(EDIT: Improved to 14 CNOTs.) It can be done with 14 CNOTs, plus 15 single-qubit Z rotations, and no auxiliary qubits. The corresponding circuit is where the $\fbox{$\pm$}$ gates are rotations $$ ...
Norbert Schuch'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
  • 32.4k
9 votes

How is it possible to implement unitary operator when its size is exponential in inputs?

The key is that you don't actually construct a matrix. Yes, if you wanted to simulate a quantum computation on a classical computer, one method is to build the corresponding unitary matrix, and this ...
DaftWullie's user avatar
  • 54.4k
9 votes

Sampling random circuits vs Solovay-Kitaev compiler

The Solovay-Kitaev algorithm is not practical. It is very useful theoretically because it proves that once you have a "dense" set of quantum gates (i.e. a set with which you can approximate any other ...
Adrien Suau's user avatar
  • 4,777
9 votes

Would IBM's "compiler" turn my identity circuit into nothing?

Any compilation/circuit optimization happens transparently by Qiskit. As a user you have control over what happens via the optimization_level argument passed to <...
Ali Javadi's user avatar
  • 1,612
8 votes
Accepted

How to implement a matrix exponential in a quantum circuit?

Reformulating your question: How to perform Hamiltonian Simulation for a generic square matrix $A$? Quick answer: it is not possible. The goal of Hamiltonian Simulation (HS) is to find a quantum ...
Adrien Suau's user avatar
  • 4,777
8 votes
Accepted

Quantum XNOR Gate Construction

Any classical one-bit function $f:x\mapsto y$ where $x\in\{0,1\}^n$ is an $n$-bit input and $y\in\{0,1\}$ is an $n$-bit output can be written as a reversible computation, $$ f_r:(x,y)\mapsto (x,y\...
DaftWullie's user avatar
  • 54.4k
8 votes
Accepted

Quantum XOR Linked List Construction

Caveat. I can't be absolutely certain that no-one has contemplated a quantum XOR list before — but I can be pretty confident. On the theory side, the idea of data structures as granular as ...
Niel de Beaudrap's user avatar

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