Skip to content

Commit

Permalink
Fixing 3 demos (#952)
Browse files Browse the repository at this point in the history
`dev.state` does not work with the new device:
`variational_classifier`
`tutorial_noisy_circuits`

Typo:
`circuit_cutting`
  • Loading branch information
KetpuntoG authored Oct 11, 2023
1 parent a59bef6 commit 1a5f3ee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions demonstrations/tutorial_noisy_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ def circuit():
print(f"QNode output = {circuit():.4f}")

######################################################################
# The device stores the output state as a density matrix. In this case, the density matrix is
# With a small modification of the circuit we can also ask for the density matrix. In this case, the density matrix is
# equal to :math:`|\psi\rangle\langle\psi|`,
# where :math:`|\psi\rangle=\frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)`.

@qml.qnode(dev)
def density_matrix_circuit():
qml.Hadamard(wires=0)
qml.CNOT(wires=[0, 1])
return qml.state()

print(f"Output state is = \n{np.real(dev.state)}")
matrix = density_matrix_circuit()
print(f"Output density matrix is = \n{np.real(matrix)}")

######################################################################
# Incoherent noise is modelled by
Expand Down
2 changes: 1 addition & 1 deletion demonstrations/tutorial_quantum_circuit_cutting.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def circuit(x):


######################################################################
# The double vertical lines between the two ``CZ`` gates on qubit 1 in the
# The dashed line and the scissors between the two ``CZ`` gates on qubit 1 in the
# above figure show where we have chosen to cut. This is where the ``WireCut``
# operation is inserted. ``WireCut`` is used to manually mark locations for
# wire cuts.
Expand Down
8 changes: 4 additions & 4 deletions demonstrations/tutorial_variational_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@ def test(angles):

statepreparation(angles)

return qml.expval(qml.PauliZ(0))
return qml.state()


test(ang)
state = test(ang)

print("x : ", x)
print("angles : ", ang)
print("amplitude vector: ", np.real(dev.state))
print("amplitude vector: ", np.real(state))


##############################################################################
Expand Down Expand Up @@ -376,7 +376,7 @@ def cost(weights, bias, features, labels):

##############################################################################
# Data
# ~~~~
# ~~~~
#
# We then load the Iris data set. There is a bit of preprocessing to do in
# order to encode the inputs into the amplitudes of a quantum state. In
Expand Down

0 comments on commit 1a5f3ee

Please sign in to comment.