First, I’d like to congratulate you all on making an awesome Python package! I recently saw @jmarrazola give a talk on quantum neural networks and I’ve been interested to try PennyLane for some new research I’ve recently started.
I am working on a proposed photonic architecture to prepare arbitrary multi-qubit (discrete, not CV) states, and I am trying to use PennyLane to optimize the trainable parameters to maximize the circuit fidelity
<psi_out|psi_target>. Ideally, what I would like to do is something like this:
dev = qml.device('default.qubit', wires=2) @qml.qnode(dev) def circuit(trainable_params): my_configurable_circuit(trainable_params) target_state = 1/np.sqrt(2) * np.array([1,0,0,1]) return qml.expval.Overlap(target_state) circuit() > 0.92523 (value of <psi|target>)
Since there’s no
Overlap() method available, I tried improvising:
@qml.qnode(dev) def circuit(trainable_params): my_configurable_circuit(trainable_params) target_state = 1/np.sqrt(2) * np.array([1,0,0,1]) target_herm_op = np.outer(target_state.conj(), target_state) return qml.expval.Hermitian(target_herm_op, [0,1]) # gives <psi|target>^2
This gives the error
ValueError: Hermitian: wrong number of wires. 2 wires given, 1 expected. (As a side note, the documentation is slightly ambiguous to a non-careful reader whether
Hermitian() could be a (
M<=N)-qubit operator which gets “padded” with identity operators. Perhaps change the
wires keyword to
wire for operators and expectations which only act on one qubit?)
Is there a way to do multi-qubit expectations like this in PennyLane? I understand this doesn’t necessarily correspond to a physically observable value that could be implemented on quantum hardware, but it’s easy to implement in TensorFlow and would be a nice feature to have in the default simulated qubit/qumode backend.