# Creating MBQC Circuits¶

Measurement-based quantum computation is a paradigm of quantum computation that uses single qubit measurements to perform universal quantum computation . It is equivalent to the standard gate-based model. The main difference is that the gates are not explicitly applied to the qubits, but rather a big resource (entangled) state is prepared and logical information flows through the system by measuring the qubits of the resource state.

## MBQC Circuits¶

In mentpy we can simulate an MBQC circuit by using the MBQCircuit class.

In : gs = mp.GraphState()

In : gs.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 4)])

In : mbcirc = mp.MBQCircuit(gs, input_nodes=, output_nodes=)

In : mp.draw(mbcirc)
Out: (<Figure size 800x300 with 1 Axes>, <Axes: >) This circuit is designed to implement a single qubit gate on the input qubit, with qubits measured in a left-to-right sequence. We can use this circuit to implement a teleportation from qubit 0 to qubit 4 by measuring qubits $$0$$, $$1$$, $$2$$, and $$3$$ in the $$X$$ basis.

## Ment Operators¶

To specify the measurement angles, we can use the Measurement (or its alias Ment) operator at each qubit position. The Measurement object is characterized by an angle and a measurement plane, which can be “XY”, “XZ”, or “YZ” (“X”, “Y”, and “Z” are also accepted), determining the basis in which the qubit is measured. The angle can be specified or set to None. If not provided, it will be treated as a trainable parameter.

Note

At the moment, only the “XY”, “X”, and “Y” measurement planes are supported.

In : mbcirc = mp.Ment('X')

In : mbcirc = mp.Ment('XY')

In : mbcirc = mp.Ment(0.5, 'XY')

In : mbcirc = mp.Ment('X')

In : mp.draw(mbcirc, label='planes')
Out: (<Figure size 800x300 with 1 Axes>, <Axes: >) We can define the same circuit when creating the MBQCircuit object with the measurements argument:

In : measurements = {0: mp.Ment('X'), 1: mp.Ment('XY'), 2: mp.Ment(0.5, 'XY'), 3: mp.Ment('X')}

In : mbcirc = mp.MBQCircuit(gs, input_nodes=, output_nodes=, measurements=measurements)

In : mp.draw(mbcirc, label='arrows')
Out: (<Figure size 800x300 with 1 Axes>, <Axes: >) The default measurement basis can be specified with the default_measurement kwarg. By default, it is set to $$XY$$, but we can change it to any other Ment object. Let’s see an example:

In : mbcirc = mp.MBQCircuit(gs, input_nodes=, output_nodes=,
....:                        measurements={1: mp.Ment('XY')},
....:                        default_measurement=mp.Ment('X'))
....:

In : print(mbcirc) # Not specified in the constructor
Ment(0, X)

In : print(mbcirc) # Specified in the constructor
Ment(θ, XY)

In : print(mbcirc.matrix()) # Matrix of the measurement operator
[[0 1]
[1 0]]


We can concatenate two MBQC circuits with the merge(), hstack(), or vstack() functions.

In : new_circ = mp.merge(mbcirc, mbcirc, along=[(4,0)])  # specify nodes to merge

In : mp.draw(new_circ, label='angles')
Out: (<Figure size 800x300 with 1 Axes>, <Axes: >) In : new_circ = mp.hstack((mbcirc, mbcirc))

In : mp.draw(new_circ, label='planes')
Out: (<Figure size 800x300 with 1 Axes>, <Axes: >) In : new_circ = mp.vstack((mbcirc, mbcirc))

In : mp.draw(new_circ, label='arrows')
Out: (<Figure size 800x300 with 1 Axes>, <Axes: >) ## Templates¶

To use pre-defined MBQC circuits, we can use the templates module, which contains some common MBQC circuits. For example, we can create a grid cluster state with the grid_cluster() function.

In : grid_cluster = mp.templates.grid_cluster(3, 5)

In : linear_cluster = mp.templates.linear_cluster(4)

In : grid_and_linear = mp.merge(grid_cluster, linear_cluster, along=[(9,0)])

In : mp.draw(grid_and_linear)
Out: (<Figure size 800x300 with 1 Axes>, <Axes: >) Finally, if you want to know the set of gates that the MBQC circuit you have created implements, you can use the utils.calculate_lie_algebra(). This function returns the lie algebra $$\mathfrak{g}$$ that the circuit implements, which can be used to calculate the set of gates using the exponential map $$\{e^{i \theta \mathfrak{g}} \mid \theta \in \mathbb{R} \}$$.

In : ops = mp.utils.calculate_lie_algebra(grid_cluster)

In : print(len(ops))
64

In : ops[:3]
Out:
IIZ
IIX
IXZ


Lie algebras are a powerful tool for studying QML models. It has been shown that, for a given model, the size of the Lie algebra is related to the phenomenon of barren plateaus  .