Skip to content

MeasurementResult Predicates #550

@johnzl-777

Description

@johnzl-777

Since #308 measurement now returns a MeasurementResult type instead of defaulting to a boolean type.

While SquinToStim handles this without a problem (it just checks the condition has a proper MeasureIdBool from the measure_id analysis) it does make type inference problematic because you run into cases where one could write:

measurement_result : MeasurementResult = squin.qubit.measure(q[0])
if measurement_result: # this is not a boolean! 
	squin.z(q[0])

To remedy this there have to be predicate statements (probably added to the qubit dialect) that can consume a MeasurementResult and query specific information about it to give a bool that can be properly inferred with. (Credit to @cduck who I believe brought this up in an older meeting).

For example, the above problematic code would be fixed via:

measurement_result: MeasurementResult = squin.qubit.measure(q[0])
if is_one(measurement_result):
	squin.z(q[0])

# which can be interpreted as CZ rec[<insert negative int here>] 0

The IfToStim rewrite rule would have to be slightly tweaked so that it only rewrites scf.IfElse if the condition's parent is is_one but that should just be a few additional lines of code.

I believe it would be best for #549 to be addressed first before proceeding with any of this.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestpriority: mediummedium priority, default prioritysquinsquin related issuesstimIssues regarding the stim dialect

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions