# Tag Info

### How and why does swap test works?

What that cSWAP test does (and doesn't) do The important thing about the controlled-SWAP test is that what it does isn't just to SWAP, or to not SWAP, the two inputs. The controlled-SWAP test ...
• 12.1k

### How and why does swap test works?

The key to understanding many quantum protocols and circuits is in the following circuit: This is especially true in the case where $U^2=I$, such that $U$ has eigenvalues $\pm1$. You can readily ...
• 57.9k

• 1,783

### pennylane:fidelity calculation after swap test between entagled states. Swap test issue

As the error suggests, you cannot use QubitStateVector twice in the same QNode. Take, for instance, this simpler example that reproduces your error. Here, I want to ...
• 171
Accepted

### What's the matrix representation of the CSWAP?

To get the $CSWAP$ matrix representation in Qiskit, you can use the Operator class defined in the qiskit.quantum_info module: <...
• 1,492
Accepted

### Fidelity (overlap) test over reduced density matrices on quantum circuit

For any two density matrices, no matter where they originated, the SWAP test can be used to calculate the desired quantity. Let's write this explicitly. We take three modes, one for the control that I'...
• 4,254

### SWAPing Schmidt vectors

TL;DR: In general, such "inner product" is not well-defined. This can be remedied by appropriate choice of $A$ and $B$. Still, the inner product depends on the global phase and thus cannot ...
• 22.3k
Accepted

### How to calculate inner product of quantum states with other method than swap test?

I doubt that this is possible. Given a state $|\phi\rangle$, we have no method for distinguishing it from $e^{i\varphi}|\phi\rangle$ for any phase $\varphi$. This means that we have no way of ...
• 4,254
Accepted

### In the swap test, how is the final probability $P(0)$ calculated?

Note that \begin{align}|\psi \rangle &= \frac {1}{2}(| 0 \rangle_1|\psi \rangle_2|\phi \rangle_3 + | 1 \rangle_1|\psi \rangle_2|\phi \rangle_3 + | 0 \rangle_1|\phi \rangle_2|\psi \rangle_3 - | 1 \...
• 13.8k

### Confusion in computing the $1+|\langle\phi|\psi\rangle|^2$ term in the quantum swap test algorithm

Remember that when you're multiplying out a term like $$(\langle\phi|\langle\psi|+\langle\psi|\langle\phi|)(|\phi\rangle|\psi\rangle+|\psi\rangle|\phi\rangle)$$ that (i) you get all the corss terms (...
• 57.9k
Accepted

### Swap Test for vector difference - how are different sized inputs combined?

The paper you refer is incomplete and not very right on this part. First a minus sign should be present in : $$|\phi\rangle = \frac{1}{\sqrt{Z}} (|a||0\rangle - |b||1\rangle)$$ Secondly, if you ...
• 4,754
Accepted

### Can the SWAP test only compare registers with the same number of qubits?

Qubits can be only with a size of 2, which means a dimensionality of 2. For $|\alpha \rangle,|\beta\rangle$ here, for the SWAP gate to make sense, they must be of the same dimensionality (in the ...
• 1,745
Accepted

### How to implement the state $|\psi\rangle = \frac{1}{\sqrt{2}}\left[|0\rangle \otimes |X_i\rangle + |1\rangle \otimes |X_j\rangle\right]$

Suppose that $U_i$ prepares the state $\left|X_i\right\rangle$. Start by applying an Hadamard gate on the first qubit: $$\frac{1}{\sqrt{2}}\left(|00\rangle+|10\rangle\right)$$ Then apply $U_j$ ...
• 6,162

### In a Swap Test why is the control qubit influenced and aren't the target qubits altered?

Deciding which qubit is a source and which is a target and changes depends on a basis. In a basis-independent sense, the qubits get entangled, and it affects both sides. In a swap test you apply ...
• 3,204
Accepted

### Implementing a SWAP-Test for samples with large numbers of features

You can employ a method described in paper Transformation of quantum states using uniformly controlled rotations. This allows you to prepare arbitrary quantum state. If you have $x$ features, you can ...
• 14.1k

### What's the matrix representation of the CSWAP?

2-qubit gates can be simulated effectively, much faster than potentially large matrix multiplies. They can be applied basically with linear complexity over the size of the full state (Python example ...
• 998