To perform a linear combination of two unitaries

we need the circuit

where

Create the k-dependent unitary matrix V_prepare. Then, build the two_unitary_combo circuit that implements the linear combination of unitaries.

def V_prepare(k):
"""
Builds the unitary matrix V_k.

Args:
- k (float): The value of kappa in the linear combination of two unitaries
Returns:
- (numpy.ndarray): The matrix V_k.
"""

v_k = # Build the unitary matrix V_k (np.ndarray)

return v_k


dev = qml.device("default.qubit", wires = 2)

@qml.qnode(dev)
def two_unitary_combo(state, k, U, V):
"""
Builds the quantum circuit that implements the linear combination of two unitaries.
Args:
- state (numpy.ndarray): The state to prepare in the main register
- k (float): The value of kappa in the linear combination of two unitaries
- U (numpy.ndarray): The first unitary matrix
- V (numpy.ndarray): The second unitary matrix
Returns:
- (numpy.ndarray): The output state of the circuit
"""

v_k = V_prepare(k)

# Apply the unitary v_k

# Prepare the state on the main register (second wire)

or to submit your code

To interact with codercises, please switch to a larger screen size.

Learning Objectives:

  • Define the concept of block encoding.
  • Implement the PREPSELPREP routine to encode a linear combination of unitaries.