How can we correctly implement the standard Meyer-Wallach measure using PennyLane? We’ve been encountering difficulties in accurately calculating the final Q value. Would it be possible to provide a reference implementation of the standard Meyer-Wallach measure for guidance? Thank you. For your reference, the Meyer-Wallach measure is detailed in the following paper: https://arxiv.org/pdf/quant-ph/0305094.pdf.
Hey @zj-lucky!
I’m not aware of any implementations of this measure that you can reference. Maybe I can still give you a hand, though. Can you be a bit more specific / detailed here? Seeing some code would help alongside a specific equation(s) from the paper you attached.
Hey, use this
def entangling_capability(circuit_template, num_qubits, num_params, num_samples=1000):
#Compute entangling capability (Q) of a parameterized quantum circuit using PennyLane.
dev = qml.device("default.qubit", wires=num_qubits)
@qml.qnode(dev)
def run_circuit(params):
circuit_template(params, wires=range(num_qubits))
return qml.state()
q_values = []
for _ in range(num_samples):
params = np.random.uniform(0, 2 * np.pi, num_params) #Generate random parameters
state = run_circuit(params)# statevector
# Meyer-Wallach Q
sum_purities = 0.0
for qubit in range(num_qubits):
psi = state.reshape([2] * num_qubits) #compute reduced density matrix
psi = np.moveaxis(psi, qubit, 0).reshape(2, -1)
rho = psi @ psi.conj().T #purity
purity = np.trace(rho @ rho).real
sum_purities += purity
Q = 2 * (1 - sum_purities / num_qubits)
q_values.append(Q)
return np.mean(q_values)
Thanks for sharing @mitul3737! ![]()
And welcome to the Forum! ![]()