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.
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
