liveBook · Manning

Unitary transformation

As explained in Quantum Programming in Depth

A unitary transformation is a linear transformation that preserves inner products and therefore quantum-state norm and measurement probabilities.

A unitary transformation is a linear transformation that preserves inner products, quantum-state norms, and measurement probabilities. In quantum programming, its matrix description must be converted into a sequence of gates that implements the same operation. section 3.1 section 3.13

Implementing a unitary transformation typically involves:

  • Representing a single-qubit operation with four coefficients and recognizing special matrix shapes. section 3.1
  • Expressing the operation as a circuit or reusable gate in Qiskit. section 3.1.2
  • Decomposing multiqubit matrices recursively using cosine-sine decomposition and block-diagonal operations. section 3.10.2
  • Running the operation on a quantum simulator and comparing its implemented matrix with the target. section 3.2 section 3.13

Analyzing an unknown unitary

To reconstruct a real single-qubit unitary, prepare suitable states, apply the unknown operation, measure the resulting states, and infer its matrix representation under a stated sign convention. Related experiments distinguish promised unitaries or estimate properties such as eigenvalues. section 5.2 section 5.0

Listing 3.20 Qiskit code to implement an arbitrary unitary
from scipy.linalg import cossin

def apply_arbitrary_unitary(n, u):
  if n == 1:
    return apply_one_qubit(u)
    
  circ = QuantumCircuit(n)
  left, cs, right = cossin(u, p=len(u) / 2, q=len(u) / 2)

  ar, br = extract_blocks(right)
  circ.append(apply_two_block_diagonal(n, ar, br), range(n))

  cs_pairs = []
  for i in range(len(cs) // 2):
    cs_pairs += [(cs[i][i], cs[i + len(cs) // 2][i])]
  circ.append(apply_arbitrary_cs_matrix(n, cs_pairs), range(n))

  al, bl = extract_blocks(left)
  circ.append(apply_two_block_diagonal(n, al, bl), range(n))
  return circ.decompose().to_gate()

def extract_blocks(matrix):  #1
  block_len = len(matrix)  #1
  a = [row[0 : block_len] for row in matrix[0 : block_len]]
  b = [row[block_len : ] for row in matrix[block_len : ]]
  return a, b

Inspect the recursive Qiskit construction: handle the one-qubit base case, compute a cosine-sine decomposition, extract blocks, and assemble the resulting gates. section 3.10.2

Figure 5.1 To learn a property of a given unitary operation, we choose an initial state, apply one or sev-eral quantum operations, including the operation we’re analyzing or its variants, and measure the resulting state. Depending on the problem we’re solving, we might have to repeat this sequence of steps multiple times to gather statistics about the measurement outcomes and/or vary the initial state and the unitaries applied.
figure

Trace the experimental pattern for learning a unitary property: prepare an initial state, apply the operation or a variant, measure, and repeat when statistics or varied inputs are needed. section 5.0

How Quantum Programming in Depth covers it

How deep it goes
Develops single- and multiqubit implementations, recursive decomposition, simulator testing, and experimental analysis without proving optimality.
Examples
Uses single-qubit gate construction, arbitrary multiqubit decomposition, unitary distinction, matrix reconstruction, and eigenvalue estimation.
What it assumes
Assumes quantum states, measurements, and basic programming, while refreshing the matrix-to-gate reasoning needed for implementation.
What you can do after
Builds and tests unitary circuits, inspects their matrices, distinguishes promised operations, and reconstructs simple unknown unitaries.
How it connects
Connects unitary transformations with quantum gates, quantum states, measurements, controlled operations, cosine-sine decomposition, phase estimation, and quantum process tomography.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quantum Programming in Depth. The section links point to the parts of the book it draws on.