2022 Developer Survey is open! Take survey.
26 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,...
user avatar
23 votes

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

You can build your gate with Operator and unitary function e.g: ...
user avatar
  • 431
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,...
user avatar
  • 18.2k
15 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 ...
user avatar
13 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 ...
user avatar
12 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 ...
user avatar
12 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\...
user avatar
  • 46.3k
11 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 ...
user avatar
  • 21.8k
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 ...
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 ...
user avatar
  • 3,407
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 ...
user avatar
  • 679
10 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) : ...
user avatar
  • 4,554
10 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 ...
user avatar
  • 314
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, ...
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 ...
user avatar
  • 21.8k
9 votes

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 ...
user avatar
  • 46.3k
9 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 ...
user avatar
9 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 ...
user avatar
  • 21.8k
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 ...
user avatar
  • 46.3k
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 <...
user avatar
  • 1,542
9 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 ...
user avatar
  • 46.3k
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 ...
user avatar
  • 4,467
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\...
user avatar
  • 46.3k
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 ...
user avatar
8 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 $$ ...
user avatar
8 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 ...
user avatar
  • 21.8k
8 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 ...
user avatar
  • 4,467
8 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 ...
user avatar
  • 4,467
8 votes
Accepted

Is it possible to make a Toffoli gate using only CNOTS and ancillas?

No this is not possible. One argument is the following: Toffoli + Hadamard are universal for quantum computation, so if you can make Toffoli from controlled-not then controlled-not + Hadamard would be ...
user avatar
  • 46.3k
8 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 ...
user avatar
  • 3,771

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