# Understanding Paddle Quantum's MBQC simulation

Paddle Quantum have a toolkit for simulating measurement-based QC patterns in Python, and I'm having a hard time understanding how this works.

For example, the following code snippet considers the pattern of two qubits joined by an edge. We initialise the two qubits in the state $$|+\rangle |+\rangle$$, before applying a measurement on the 1st qubit with respect to the $$\{ |+\rangle, |-\rangle \}$$ basis:

# Define MBQC graph as two vertices joined by an edge
G = [['1','2'], [('1','2')]]
# Initialise MBQC model
mbqc = MBQC()
# Set the graph state
mbqc.set_graph(G)

# Define input state as |+>|+>
input_state = to_tensor([[0.5],[0.5],[0.5],[0.5]], dtype='complex128')
input_state = State(input_state, ['1','2'])
# Set the input state
mbqc.set_input_state(input_state)

# Print initial state
print('Input state:')
print(mbqc.get_quantum_output().vector.numpy())
# Measure qubit 1
mbqc.measure('1', basis('XY', to_tensor(0, dtype='float64')))
# Print measurement outcome and resultant state of qubit 2
print('Measurement outcome of 1st qubit:')
print(mbqc.sum_outcomes(['1']))
print('Post-measurement state:')
print(mbqc.get_quantum_output().vector.numpy())

As I understand it, the measurement outcome of the first qubit should always be 0, since the first qubit has state $$|+\rangle$$ and we are measuring in the $$\{ |+\rangle, |-\rangle \}$$ basis. However, the code above sometimes gives a measurement outcome of 1 in the console:

Input state:
[[0.5+0.j]
[0.5+0.j]
[0.5+0.j]
[0.5+0.j]]
Measurement outcome of 1st qubit:
1
Post-measurement state:
[[0.+0.j]
[1.+0.j]]

Hence, my question is simply: which part of the above simulation am I misunderstanding?

Thanks very much for using our MBQC toolkit, and also thanks for your feedback. In the first part of your code, you set the underlying graph of your MBQC algorithm.

# Define MBQC graph as two vertices joined by an edge
G = [['1','2'], [('1','2')]]
# Initialise MBQC model
mbqc = MBQC()
# Set the graph state
mbqc.set_graph(G)

So you have set two vertices and an edge between them. This edge represents a controlled-Z gate between these qubits.

All the vertices are initially plus states in MBQC by default. But we do allow users to replace it to any given state for flexibility. This is equivalent to specify an input state in the quantum circuit model. In your case, you set these two vertices again to two plus states, which means doing nothing.

# Define input state as |+>|+>
input_state = to_tensor([[0.5],[0.5],[0.5],[0.5]], dtype='complex128')
input_state = State(input_state, ['1','2'])
# Set the input state
mbqc.set_input_state(input_state)

Then you apply X measurement on the first qubit.

# Measure qubit 1
mbqc.measure('1', basis('XY', to_tensor(0, dtype='float64')))

This is equivalent to perform a Z measurement on a bell state 1/sqrt(2) (|00>+|11>) (initialize two plus state, perform a CZ gate and the measure the first qubit in X basis). So you get zero or one with equal probability. If you get outcome 0, the post-measurement state on the second qubit is |0>. If you get outcome 1, the post-measurement state is |1>.

So I guess you miss the CZ gate here. This gate is automatically applied when you measure a qubit.

Also note that once a graph is specified, the computation is completely driven by the measurements. In your code

# Print initial state
print('Input state:')
print(mbqc.get_quantum_output().vector.numpy())

no measurement has been applied yet. So the computation does not get started. The state you print is exactly the input state you set.

Hope everything makes sense now. Let me know if you need more help.

We do hope to make Paddle Quantum better together with the community!

• Thanks very much for writing this answer. I've realised that my mistake was a very silly one -- I was treating the edges as applying a controlled-$X$ gate (i.e. doing nothing on the state $|+\rangle |+\rangle$) rather than a controlled-$Z$ gate between the qubits. Your toolkit is great and I'm having a lot of fun using it!
– T.H
Jul 7, 2022 at 12:50
• I'm curious to see if PaddlePaddle can be used to simulate the examples in this paper arxiv.org/abs/2101.09310 is it a good fit? or do you have better starter examples? Jul 8, 2022 at 2:42
• @unknown As far as I concern, the paper 2101.09310 introduces a new type of quantum computation model that utilizes entangling measurements. So this is different from the MBQC (more specifically, the one-way quantum computation model) we consider in Paddle Quantum. The standard MBQC uses graph states and single-qubit measurement only. Our tutorials and the references therein can be a good starting point.
– Kun
Jul 8, 2022 at 4:23
• @J.T. I am glad that it helps. Just want to point out that we have also applied the MBQC toolkit to the universal blind quantum computation. You can find the tutorial here if interested. Basically, we have a module that automatically translates user's quantum circuit to a MBQC algorithm with brickwork pattern. Then the computation follows the UBQC protocol and interacts in real-time between your laptop and our cloud server :)
– Kun
Jul 8, 2022 at 4:40
• @Kun That is quite the coincidence, as I've just spent the last few weeks implementing a simulation of UBQC on your MBQC toolkit for use with verification. I'm actually working with one of the authors of the UBQC paper you mention so will be sure to let them know that this exists! Thanks for letting me know! :)
– T.H
Jul 8, 2022 at 10:14