"""Data structure for single-qubit measurements in MBQC."""from__future__importannotationsimportdataclassesimportmathfromtypingimportNamedTuplefromgraphiximportutilsfromgraphix.fundamentalsimportAxis,Plane,Sign@dataclasses.dataclassclassDomains:"""Represent `X^sZ^t` where s and t are XOR of results from given sets of indices."""s_domain:set[int]t_domain:set[int]
[docs]classMeasurement(NamedTuple):"""An MBQC measurement. :param angle: the angle of the measurement. Should be between [0, 2) :param plane: the measurement plane """angle:floatplane:Planedefisclose(self,other:Measurement,rel_tol:float=1e-09,abs_tol:float=0.0)->bool:"""Compare if two measurements have the same plane and their angles are close. Example ------- >>> from graphix.opengraph import Measurement >>> from graphix.fundamentals import Plane >>> Measurement(0.0, Plane.XY).isclose(Measurement(0.0, Plane.XY)) True >>> Measurement(0.0, Plane.XY).isclose(Measurement(0.0, Plane.YZ)) False >>> Measurement(0.1, Plane.XY).isclose(Measurement(0.0, Plane.XY)) False """returnmath.isclose(self.angle,other.angle,rel_tol=rel_tol,abs_tol=abs_tol)andself.plane==other.plane
classPauliMeasurement(NamedTuple):"""Pauli measurement."""axis:Axissign:Sign@staticmethoddeftry_from(plane:Plane,angle:float)->PauliMeasurement|None:"""Return the Pauli measurement description if a given measure is Pauli."""angle_double=2*angleifnotutils.is_integer(angle_double):returnNoneangle_double_mod_4=int(angle_double)%4axis=plane.cosifangle_double_mod_4%2==0elseplane.sinsign=Sign.minus_if(angle_double_mod_4>=2)returnPauliMeasurement(axis,sign)