Replies: 3 comments 1 reply
-
|
I don't think that old code working, but silently degrading in performance is a good idea. Personally, I'd be happy to swallow the pain of refactoring code for the benefit or being able to reason about my program's performance more easily. |
Beta Was this translation helpful? Give feedback.
-
|
If we support printing futures, it would be nice to add a (FUTURE_REF:T:$name, $future_id) in the result stream immediately. Then when it is actually forced, we add (FUTURE_VALUE:T:$name, $future_id, $value) to the result stream. Then in result processing (e.g. Selene's result_handling code) we can perform a lookahead and insert values back into the order users currently expect, and replace the future ref with a (USER:T:$name, $value) Where this breaks existing use is when a measure is later followed by an exit before the read happens, in which case the measure doesn't happen and there is nothing to bind the value to. We could force any hanging references on exit for this case if we want to. If we do no such reordering then I think that would be unfortunate without supporting formatted tags for results. Users will have no way of printing in a nested scope and recovering meaning from the results. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The guppy quantum execution model is a little unintuitive:
The
measurefunction instd.quantumreturnsbool. To make sure the flushing doesn't happen any earlier than necessary, under the hood this actually is a future. The guppylang compiler compilesbooltobool | Future[bool]in HUGR. "Forcing" the future in this case becomes the "block on measure" request, at which point the future becomes a standard bool.Certain operations, like resulting the measure or conditioning on it automatically force the measurement.
Proposal
I propose that
measurereturn a trueFuture[bool]type.std.qsystem.measure_leakedalready returns aFuture[int]under the hood.This is a breaking change because a program that previously was:
would fail to compile and would need to be written as
Though for simple cases like this it only increases verbosity, it allows the user to reason about when they want to force the measurement - and gives them a better mental model of the runtime, reducing the chance of "surprise" in their outcomes. (e.g. why does putting my
result(measure)in a for loop cause longer depth programs?).A common case might be doing some bitwise operations on the measurement result or collecting them in to an array - the explicit
.read()invites the user to think about whether they need to do that then or whether waiting would be preferable.A secondary benefit is that the arcane
bool | Future[bool]handling in HUGR can all go away, significantly simplifying the compilation pipeline.Breaking considerations
This is a big breaking change, so should not be taken lightly. If done, v1 would be the earliest we would want to do this.
Given current usage patterns, a lot of breakage could be avoided if
result()could accept aFuture, which should be doable. This meansresult("c", measure(q))will continue to compile without breaking.An alternative is to keep compiling the code by returning
boolfrommeasurestill and introducing new lower level functions that returnFuture[bool]. Though existing code would continue to compile I would call this breaking since it would make existing programs perform significantly worse by always eagerly forcing measurements.Beta Was this translation helpful? Give feedback.
All reactions