Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take wire ordering in the wires argument to qml.density_matrix into account #4072

Merged
merged 17 commits into from
May 25, 2023
Prev Previous commit
Next Next commit
reduce
  • Loading branch information
dwierichs committed May 1, 2023
commit fc4b6994a0dcdccd1f9ae6e95ec954def949de64
9 changes: 2 additions & 7 deletions pennylane/math/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,19 +454,14 @@ def reduced_dm(state, indices, check_state=False, c_dtype="complex128"):
# State vector
density_matrix = _density_matrix_from_state_vector(state, indices, check_state)
return density_matrix
elif len(shape) == 2 and shape[0] != shape[1]:
# Broadcasted state vector
if (len(shape) == 2 and shape[0] != shape[1]) or len(shape) == 3:
dwierichs marked this conversation as resolved.
Show resolved Hide resolved
# Broadcasted state vector or broadcasted density matrix
# WARNING: if the broadcasting dimension matches the state dim, this
# will go unnoticed and be misinterpreted as a density matrix!
raise ValueError(
"Broadcasted density matrices are not supported yet. "
f"The batch dimension is {shape[0]}"
)
if len(shape) == 3:
raise ValueError(
"Broadcasted density matrices are not supported yet. "
f"The batch dimension is {shape[0]}"
)
density_matrix = _density_matrix_from_matrix(state, indices, check_state)

return density_matrix
Expand Down