3 Implement quantum operations
This chapter covers
- Implementing quantum operations based on their matrix notation
- Using Q# and Qiskit to write more complicated quantum programs
- Observing the matrix implemented by a quantum operation
- Writing tests for validating quantum operations
As we’ve seen in the previous chapter, a typical quantum algorithm can be represented as a standard sequence of steps (see figure 3.1). In chapter 2, we’ve learned to implement the first step, preparing the quantum system in the given state.
Figure 3.1 Any quantum algorithm can be broken down into several steps: prepare the initial state, evolve it by applying unitary transformations, and measure the final state. In this chapter, we’ll learn to perform the second step, implementing unitary transformations as the algorithm dictates.

In this chapter, we’ll focus on the second step: changing the state of the system using quantum operations. More specifically, we’ll learn to implement quantum operations that change the state of the system the way the algorithm requires.
What do we mean by “implementing” a quantum operation? Figure 3.2 shows how quantum algorithms are decomposed into simpler building blocks on multiple levels.