Commit b9bdc5a
authored
[Stretch] Support
* WIP
* Add try_const to lift.
* Try multiple singletons, new one for const.
* Revert "Try multiple singletons, new one for const."
This reverts commit e2b3221.
* Remove Bool singleton test.
* Add const handling for stores, fix test bugs.
* Fix formatting.
* Remove Duration and Stretch for now.
* Cleanup, fix const bug in index.
* Fix ordering issue for types with differing const-ness.
Types that have some natural order no longer have an ordering
when one of them is strictly greater but has an incompatible
const-ness (i.e. when the greater type is const but the other
type is not).
* Fix QPY serialization.
We need to reject types with const=True in QPY until it supports them.
For now, I've also made the Index and shift operator constructors
lift their RHS to the same const-ness as the target to make it
less likely that existing users of expr run into issues when
serializing to older QPY versions.
* Make expr.Lift default to non-const.
This is probably a better default in general, since we
don't really have much use for const except for timing
stuff.
* Revert to old test_expr_constructors.py.
* Make binary_logical lift independent again.
Since we're going for using a Cast node when const-ness
differs, this will be fine.
* Update tests, handle a few edge cases.
* Fix docstring.
* Remove now redundant arg from tests.
* Add const testing for ordering.
* Add const tests for shifts.
* Add release note.
* Add const store tests.
* Address lint, minor cleanup.
* Reject const vars in add_var and add_input.
Also removes the assumption that a const-type can never be an l-value
in favor of just restricting l-values with const types from being
added to circuits for now.
We will (in a separate PR) add support for adding stretch variables
to circuits, which are const. However, we may track those
differently, or at least not report them as variable when users
query the circuit for variables.
* Implement QPY support for const-typed expressions.
* Remove invalid test.
This one I'd added thinking I ought to block store from using
a const var target. But since I figured it's better to just
restrict adding vars to the circuit that are const (and leave
the decision of whether or not a const var can be an l-value
till later), this test no longer makes sense.
* Update QPY version 14 desc.
* Fix lint.
* Add serialization testing.
* Test pre-v14 QPY rejects const-typed exprs.
* Revert visitors.py.
* Address review comments.
* Improve type docs.
* Revert QPY, since the old format can support constexprs.
By making const-ness a property of expressions, we don't need
any special serialization in QPY. That's because we assume that
all `Var` expressions are non-const, and all `Value` expressions
are const. And the const-ness of any expression is defined by
the const-ness of its operands, e.g. when QPY reconstructs a
binary operand, the constructed expression's `const` attribute
gets set to `True` if both of the operands are `const`, which
ultimately flows bottom-up from the `Var` and `Value` leaf nodes.
* Move const-ness from Type to Expr.
* Revert QPY testing, no longer needed.
* Add explicit validation of const expr.
* Revert stuff I didn't need to touch.
* Update release note.
* A few finishing touches.
* Address review comments.const classical expressions. (Qiskit#13811)1 parent a00279b commit b9bdc5a
File tree
4 files changed
+82
-4
lines changed- qiskit/circuit/classical/expr
- releasenotes/notes
- test/python/circuit/classical
4 files changed
+82
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
49 | | - | |
| 53 | + | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| |||
99 | 101 | | |
100 | 102 | | |
101 | 103 | | |
| 104 | + | |
102 | 105 | | |
103 | 106 | | |
104 | 107 | | |
| |||
141 | 144 | | |
142 | 145 | | |
143 | 146 | | |
| 147 | + | |
144 | 148 | | |
145 | 149 | | |
146 | 150 | | |
| |||
151 | 155 | | |
152 | 156 | | |
153 | 157 | | |
154 | | - | |
155 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
156 | 161 | | |
157 | 162 | | |
158 | 163 | | |
| |||
185 | 190 | | |
186 | 191 | | |
187 | 192 | | |
| 193 | + | |
188 | 194 | | |
189 | 195 | | |
190 | 196 | | |
| |||
206 | 212 | | |
207 | 213 | | |
208 | 214 | | |
| 215 | + | |
209 | 216 | | |
210 | 217 | | |
211 | 218 | | |
| |||
257 | 264 | | |
258 | 265 | | |
259 | 266 | | |
| 267 | + | |
260 | 268 | | |
261 | 269 | | |
262 | 270 | | |
| |||
265 | 273 | | |
266 | 274 | | |
267 | 275 | | |
| 276 | + | |
268 | 277 | | |
269 | 278 | | |
270 | 279 | | |
| |||
348 | 357 | | |
349 | 358 | | |
350 | 359 | | |
| 360 | + | |
351 | 361 | | |
352 | 362 | | |
353 | 363 | | |
| |||
356 | 366 | | |
357 | 367 | | |
358 | 368 | | |
| 369 | + | |
359 | 370 | | |
360 | 371 | | |
361 | 372 | | |
| |||
381 | 392 | | |
382 | 393 | | |
383 | 394 | | |
| 395 | + | |
384 | 396 | | |
385 | 397 | | |
386 | 398 | | |
| |||
389 | 401 | | |
390 | 402 | | |
391 | 403 | | |
| 404 | + | |
392 | 405 | | |
393 | 406 | | |
394 | 407 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
188 | 190 | | |
189 | 191 | | |
190 | 192 | | |
| 193 | + | |
191 | 194 | | |
192 | 195 | | |
193 | 196 | | |
| |||
199 | 202 | | |
200 | 203 | | |
201 | 204 | | |
| 205 | + | |
| 206 | + | |
202 | 207 | | |
203 | 208 | | |
204 | 209 | | |
| |||
208 | 213 | | |
209 | 214 | | |
210 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
211 | 228 | | |
212 | 229 | | |
213 | 230 | | |
| |||
278 | 295 | | |
279 | 296 | | |
280 | 297 | | |
| 298 | + | |
281 | 299 | | |
282 | 300 | | |
283 | 301 | | |
| |||
288 | 306 | | |
289 | 307 | | |
290 | 308 | | |
| 309 | + | |
291 | 310 | | |
292 | 311 | | |
293 | 312 | | |
| |||
298 | 317 | | |
299 | 318 | | |
300 | 319 | | |
| 320 | + | |
301 | 321 | | |
302 | 322 | | |
303 | 323 | | |
| |||
314 | 334 | | |
315 | 335 | | |
316 | 336 | | |
| 337 | + | |
317 | 338 | | |
318 | 339 | | |
319 | 340 | | |
| |||
324 | 345 | | |
325 | 346 | | |
326 | 347 | | |
| 348 | + | |
327 | 349 | | |
328 | 350 | | |
329 | 351 | | |
| |||
334 | 356 | | |
335 | 357 | | |
336 | 358 | | |
| 359 | + | |
337 | 360 | | |
338 | 361 | | |
339 | 362 | | |
| |||
360 | 383 | | |
361 | 384 | | |
362 | 385 | | |
| 386 | + | |
363 | 387 | | |
364 | 388 | | |
365 | 389 | | |
| |||
370 | 394 | | |
371 | 395 | | |
372 | 396 | | |
| 397 | + | |
373 | 398 | | |
374 | 399 | | |
375 | 400 | | |
| |||
388 | 413 | | |
389 | 414 | | |
390 | 415 | | |
| 416 | + | |
| 417 | + | |
391 | 418 | | |
392 | 419 | | |
393 | 420 | | |
394 | 421 | | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
395 | 429 | | |
396 | 430 | | |
397 | 431 | | |
| |||
414 | 448 | | |
415 | 449 | | |
416 | 450 | | |
| 451 | + | |
| 452 | + | |
417 | 453 | | |
418 | 454 | | |
419 | 455 | | |
420 | 456 | | |
| 457 | + | |
| 458 | + | |
421 | 459 | | |
422 | 460 | | |
423 | 461 | | |
424 | 462 | | |
425 | 463 | | |
426 | 464 | | |
| 465 | + | |
427 | 466 | | |
428 | 467 | | |
429 | 468 | | |
| |||
0 commit comments