Commit e141008
committed
Fix #855: don't call cirq.unitary() on non-unitary matrices
In Cirq 1.6.0, the function
[`unitary(...)`](https://github.com/quantumlib/Cirq/blob/fe0dc2187ca3269c178526e8ba41083fa1a467c9/cirq-core/cirq/protocols/unitary_protocol.py#L81)
in `cirq-core/cirq/protocols/unitary_protocol.py` changed. Whereas
previously, if the value passed in was a NumPy array, it the function
returned the array directly without doing anything else, `unitary(...)`
was changed in [PR
the array really _is_ unitary and raise an exception if it isn't. This
arguably corrected a fault in `unitary(...)` because with the previous
definition, it would return non-unitary results if given a NumPy array
that wasn't already unitary. However, in one of the tests in qsim, it
had the result of revealing a small bug: the test case was knowingly
invoking `unitary(...)` with a non-unitary matrix. This led to
exceptions being raised in Cirq 1.6.0 but not in prior versions.
The solution in this case turned out to be very simple: the call to
`cirq.unitary(...)` on line 1060 was unnecessary because the previous
version of `unitary(...)` simply returned it right away. Removing the
call kept the previous behavior (which was to use a non-unitary matrix
in that situation) and works in both Cirq 1.5.0 and 1.6.0.1 parent 7932f78 commit e141008
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1057 | 1057 | | |
1058 | 1058 | | |
1059 | 1059 | | |
1060 | | - | |
| 1060 | + | |
1061 | 1061 | | |
1062 | 1062 | | |
1063 | 1063 | | |
| |||
0 commit comments