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

Work around index-limiting bug in np.einsum #687

Merged
merged 2 commits into from
Jul 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cirq/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1319,11 +1319,18 @@ def _apply_unitary_operation(state: np.ndarray,
work_indices = tuple(range(k))
data_indices = tuple(range(k, k + d))
used_data_indices = tuple(data_indices[q] for q in target_axes)
input_indices = work_indices + used_data_indices
output_indices = list(data_indices)
for w, t in zip(work_indices, target_axes):
output_indices[t] = w

return np.einsum(matrix, work_indices + used_data_indices,
all_indices = set(input_indices + data_indices + tuple(output_indices))

return np.einsum(matrix, input_indices,
state, data_indices,
output_indices,
out=out)
out=out,
# Note: this is a workaround for a bug in numpy:
# https://github.com/numpy/numpy/issues/10926
# Turning optimize on actually makes things slower.
optimize=len(all_indices) >= 26)