Simulating MBQC Circuits

In the previous tutorial, you have learned how to create an MBQC circuit using the MBQCircuit class. Now, we will use this circuit to run an actual experiment. We will use the PatternSimulator class to create a simulator. Let’s try it out

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

In [2]: simulator = mp.PatternSimulator(grid_cluster, backend='numpy-dm')

In [3]: print(simulator)
PatternSimulator (NumpySimulatorDM for MBQCircuit with 15 qubits.)

You can specify the backend you want to use with the keyword argument backend. This can be useful if you want to run a circuit on real hardware.

Note

Currently, mentpy does not support running circuits on real hardware. This feature

will be added in the future.

Running the circuit

To run the circuit, we can simply call simulator with the circuit as an argument. If the measurement angle of a node is fixed (i.e. the measurement object Ment is not trainable), you will not need to specify the measurement angle in the call to the simulator.

In [4]: num_angles = len(grid_cluster.trainable_nodes)

In [5]: output_state = simulator(np.random.rand(num_angles))

In [6]: print(output_state.shape)
(8, 8)

Different inputs

If you want to run the circuit with a particular input state, you can specify it with the keyword argument input_state.

In [7]: random_state = mp.utils.generate_haar_random_states(3)

In [8]: simulator.reset(input_state = random_state)

In [9]: output_state = simulator(np.zeros(num_angles))

In [10]: print(output_state.shape)
(8, 8)