# Pennylane output-CNOT gate

Hello,

I am newbie to pennylane. I was trying to build some basic circuits and struggling in output reading. For example, I build a circuit with two wires and apply a CNOT gate on it. Now, I want to see output for different inouts (00,01,10,11), how can I do that, like in qiskit we can do that by simulators like QASM and get the output states probability.

Secondly, I am trying to implement something using Measurement-based quantum computation in pennylane, is there any convenient way of doing this?

Thanks for the help.

Could you expand more by what you mean by the following?

using Measurement-based quantum computation in pennylane

For example, I build a circuit with two wires and apply a CNOT gate on it. Now, I want to see output for different inouts (00,01,10,11), how can I do that

To do so, we want to first create a ‘device’. This is a quantum simulator, or quantum hardware, that we want to run our computation on. In this case, we’ll simply use the built in default.qubit simulator that comes with PennyLane:

dev = qml.device("default.qubit", wires=2)


Next, we can create our quantum function. This quantum function executes the gates on our device, and returns a measurement statistic. In this case, we will return the probability.

@qml.qnode(dev)
def circuit():
qml.CNOT(wires=[0, 1])
return qml.probs(wires=[0, 1])


We now execute this quantum function:

>>> circuit()
tensor([0.5, 0. , 0. , 0.5], requires_grad=True)


So we can see that there is a probability of 0.5 of being in the state |00\rangle and |11\rangle, and a probability of 0 of being in the state |01\rangle and |10\rangle.

Let me know if that helps!

Hi @josh

Thanks for the reply and example on CNOT gate. Just one more thing that if there is any visualization tools available like histogram plot for output state probabilities or bloch sphere representations?? And also to draw the circuit?

Measurement based quantum computation is an approach where an algorithm is designed by first preparing a highly entangled cluster state of qubits and then a single qubits measurements in different measurement basis(X,Y-basis among others) implements the algorithm. In qiskit the cluster state can be prepared by applying CNOT gate to neigboring qubits of graph/cluster state, not sure how it is done here in pennylane or more so in strawberry fields (qumodes case)? If you can please elaborate that in both (qubits and qumodes case) along with measurement basis available here as builtin function?

Thanks

Regarding your first question, PennyLane does not have built-in visualization functionality at the moment, but this can be done by importing matplotlib and using the bar plot function

For circuit drawing, you can do

qml.draw(circuit)(*circuit_parameters)


See the qml.draw documentation for more details.

Regarding your second question, I might tag @Nicolas_Quesada for any thoughts, as I am not an expert when it comes to measurement based QC!