"""Shared types and helpers for qsystem platforms.These definitions are platform-agnostic and should be reexported by allplatforms (e.g. ``guppylang.std.qsystem.helios`` and ``guppylang.std.qsystem.sol``)."""fromtypingimportno_type_checkfromguppylangimportguppyfromguppylang.std.arrayimportarrayfromguppylang.std.builtinsimportownedfromguppylang.std.futuresimportFuturefromguppylang.std.optionimportOption,nothing,somefromguppylang.std.quantumimportMeasurement_N=guppy.nat_var("_N")
[docs]@guppy.struct(frozen=True)@no_type_checkclassMaybeLeaked:# type: ignore[misc] # Error for Python < 3.13"""A class representing a measurement that may have leaked. This is used to represent the result of ``measure_leaked``, which can either return a boolean measurement result or indicate that the qubit has leaked. """_measurement:Future[int]# type: ignore[type-arg]
[docs]@guppy@no_type_checkdefis_leaked(self:"MaybeLeaked")->bool:"""Check if the measurement indicates a leak."""returnself._measurement.copy().read()==2
[docs]@guppy@no_type_checkdefto_result(self:"MaybeLeaked @ owned")->Option[bool]:"""Returns the measurement result or ``nothing`` if leaked."""int_value:int=self._measurement.read()ifint_value==2:returnnothing()measurement=int_value==1returnsome(measurement)
[docs]@guppy@no_type_checkdefcollect_measurements(measurements:array[Measurement,_N]@owned,)->array[bool,_N]:"""Block on each measurement until it is available and collect results into an array of bools. """returnarray(m.read()forminmeasurements)