## Measurement-based quantum computing and cluster states

**Measurement-based quantum computing** (MBQC) is a clever approach to quantum computing that exploits entanglement created *off-line* as a resource for computation. This means that the entanglement is made independently from the computation, like how a blank sheet of paper is made separately from the text of a book. Even though this method, also referred to as one-way quantum computing, seems quite dissimilar from the gate-based model at face value, they are equivalent nonetheless.

In a one-way quantum computer, we start with an entangled state, a so-called **cluster state**, and apply adaptive single-qubit measurements that correspond to the desired quantum circuit. The measurements need to be adaptive because they can depend on prior measurement outcomes. One-way quantum computers circumvent the need for difficult two-qubit gates mid-computation that often limit the fidelities in gate-based quantum computers. Moreover, the MBQC approach is particularly suitable for photonic quantum computing because it does not require static qubits and it allows for constant-depth photonic circuits, mitigating loss. In MBQC, the measurements *are* the computation, and the entanglement of the cluster state is used as a resource.

Cluster states are a subclass of **graph states**, a special type of multi-qubit state that can be represented by a graph. Given a graph \(G\) and its edge set \(E(G)\), a graph state is defined as:

The nodes and edges represent the qubits and the entanglement between them, respectively. A graph state is a cluster state if the underlying graph \(G\) is a lattice. These “resourceful” cluster states and their graphs can be studied and visualized using FlamingPy (FP), a cross-platform Python library for efficient simulations of error correction in fault-tolerant quantum computers. This relatively novel library is aimed to be a tool for quantum error correction development and analysis for both measurement-based and gate-based quantum computers.

In this how-to, we will have a look at how to define and visualize cluster states in FlamingPy `v0.8.2a5`

. Note that we will not cover the theory of MBQC and cluster states in more depth here. For this, check out the seminal paper on one-way quantum computation by Rausendorf and Briegel from 2001. If you have not installed FP yet, you can follow this link for the installation instructions. Let’s dig right in!

## Cluster states in FlamingPy

FlamingPy comes equipped with some predefined cluster states and the ability to define your own ones. Let us first look at a cluster state that is already defined in FP and then see how to make our own one.

### The RHG cluster state

Ready-made cluster states corresponding to error-correction codes can be found in `flamingpy.codes`

and `flamingpy.utils.graph_states`

. For this demonstration, we will look at the so-called **RHG lattice**, named after its architects Raussendorf, Harrington, and Goyal. This cluster state is used to implement the MBQC-equivalent of the famous surface code! To define it, we simply use the `RHG_graph`

function and input the desired code distance which we will take to be 3.

```
from flamingpy.codes import RHG_graph
code_distance = 3
RHG = RHG_graph(code_distance)
```

To plot it, we simply use the `draw`

method.

```
RHG.draw()
```

Pretty cool, eh? Under the hood, we are making use of `EGraph`

objects. These are enhanced NetworkX graphs for representing quantum graph states and offer some additional functionality on top.

Another useful representation of a cluster state is through its adjacency matrix. We can output one by using the `adj_generator`

method of the `EGraph`

object.

```
RHG.adj_generator(sparse=False)
'''
Output:
array([[0, 1, 0, ..., 0, 0, 0],
[1, 0, 1, ..., 0, 0, 0],
[0, 1, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 1, 0],
[0, 0, 0, ..., 1, 0, 1],
[0, 0, 0, ..., 0, 1, 0]], dtype=int8)
'''
```

### Our own cluster state

We can now move on to see how we can create our own cluster states. Let’s go for a simple example: two maximally entangled qubits. One simply has to initialize an `EGraph`

object and add either nodes or edges to it. These nodes are specified by their coordinates in a 3-dimensional space. The interpretation of these dimensions is abstracted away and effectively depends on the physical system producing the state. For example, the hybrid RHG lattice proposed in Xanadu’s blueprint paper has two spatial coordinates and one temporal coordinate.

```
from flamingpy.codes.graphs import EGraph
# Fully entangled two-qubit state EGraph
edge = [(0,0,0), (0,0,1)]
two_qubit_state = EGraph()
two_qubit_state.add_edge(*edge)
```

Let’s see what state we have on our hands right now:

Interestingly enough, this two-qubit state is equivalent to a Bell state up to a single-qubit unitary, namely a Hadamard gate on either of the qubits. Indeed, this is the kind of entanglement we need for a cluster state!

Now that we have defined the two-qubit state, we can visualize it with the same `draw`

method we used before. You can even adapt the visualization to your liking, giving colours or labels to the qubits and edges.

```
# Plot the two-qubit state
two_qubit_state.draw(color_edges="MidnightBlue", color_nodes="magenta", label="index")
```

That looks good! I hope you got the gist. Have a look at the NetworkX documentation of `networkx.Graph`

and the FlamingPy documentation of `EGraph`

for relevant methods for adding and adjusting nodes and edges to the `EGraph`

. You can now make your cluster state as complicated as you like by adding more qubits and entangling them in different ways. Easy as pie!

## Conclusion

Let’s list the main takeaways.

- In MBQC, measurements are the computation and the entanglement of a cluster state is used as a resource.
- FlamingPy is a cross-platform Python library for efficient simulations of error correction in fault-tolerant quantum computers.
- In FalmingPy, cluster states are represented as 3D graphs, and you can define your own ones!

If you want to dive deeper, you can have a look at this FlamingPy tutorial for more elaborate information on graph states.