In case you get: AttributeError: 'generator' object has no attribute 'is_hermitian'

Hello, without running the code can you identify which line throws an error?

wires = 4
dev4 = qml.device("default.qubit", wires=wires)

@qml.qnode(dev4)
def ghz_circuit():
    qml.Hadamard(wires=0)
    ...
    exp_vals = [qml.expval(qml.PauliZ(i)) for i in range(wires)]
    exp_vals = [qml.expval(qml.PauliZ(i) for i in range(wires))]
    return exp_vals

Well the difference between:
exp_vals = [qml.expval(qml.PauliZ(i)) for i in range(wires)] and exp_vals = [qml.expval(qml.PauliZ(i) for i in range(wires))] is very subtle.

The correct form is of course:

exp_vals = [qml.expval(qml.PauliZ(i)) for i in range(wires)]

Best,

1 Like

Thanks @Solomon! Nice to have posts like this for people to reference in the future :grin: