Commit 89ebad8
authored
Cache the result of CircuitOperation.has_unitary (#7483)
Otherwise every time `CircuitOperation.has_unitary` is called,
`has_unitary_protocol` [decomposes the circuit into
operations](https://github.com/quantumlib/Cirq/blob/609d93dbc51a6608a0d0c3f5d50d51325052e027/cirq-core/cirq/protocols/has_unitary_protocol.py#L98)
and calls `has_unitary` on each. This is inefficient, especially if
`repetitions > 1`, because `has_unitary_protocol` looks at the circuit
with repetitions.
To ensure this change is correct, I wrote the tests first, and then made
the change.1 parent 460dda0 commit 89ebad8
File tree
2 files changed
+32
-4
lines changed- cirq-core/cirq/circuits
2 files changed
+32
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| 299 | + | |
299 | 300 | | |
300 | 301 | | |
301 | | - | |
302 | 302 | | |
303 | 303 | | |
304 | | - | |
| 304 | + | |
| 305 | + | |
305 | 306 | | |
306 | 307 | | |
307 | 308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
1297 | 1297 | | |
1298 | 1298 | | |
1299 | 1299 | | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
0 commit comments