2929
3030
3131# This import allows to use type hints for classes that have not been defined yet.
32- # See https://stackoverflow.com/questions/33533148/how-do-i-specify-that-the-return-type-of-a-method-is-the-same-as-the-class-itsel
32+ # See https://stackoverflow.com/questions/33533148/
3333# This import must be the very first import in this file, otherwise an error is raised
3434from __future__ import annotations
3535
@@ -134,8 +134,8 @@ class CQCType(IntEnum):
134134 GET_TIME = 8 # Get creation time of qubit
135135 INF_TIME = 9 # Return timinig information
136136 NEW_OK = 10 # Created a new qubit
137- MIX = 11 # Indicate that the CQC program will contain multiple header types
138- IF = 12 # Announce a CQC IF header
137+ MIX = 11 # Indicate that the CQC program will contain multiple header types
138+ IF = 12 # Announce a CQC IF header
139139
140140 ERR_GENERAL = 20 # General purpose error (no details
141141 ERR_NOQUBIT = 21 # No more qubits available
@@ -146,16 +146,16 @@ class CQCType(IntEnum):
146146
147147
148148class CQCLogicalOperator (IntEnum ):
149- EQ = 0 # Equal
150- NEQ = 1 # Not equal
149+ EQ = 0 # Equal
150+ NEQ = 1 # Not equal
151151
152152 @staticmethod
153- def opposite_of (operator : ' CQCLogicalOperator' ): # String literal type hint because it is a forward reference
154- opposites = {
155- CQCLogicalOperator .EQ : CQCLogicalOperator .NEQ ,
156- CQCLogicalOperator .NEQ : CQCLogicalOperator .EQ
157- }
158- return opposites [operator ]
153+ def opposite_of (operator : CQCLogicalOperator ):
154+ opposites = {
155+ CQCLogicalOperator .EQ : CQCLogicalOperator .NEQ ,
156+ CQCLogicalOperator .NEQ : CQCLogicalOperator .EQ
157+ }
158+ return opposites [operator ]
159159
160160 @staticmethod
161161 def is_true (first_operand : int , operator : CQCLogicalOperator , second_operand : int ):
@@ -165,6 +165,7 @@ def is_true(first_operand: int, operator: CQCLogicalOperator, second_operand: in
165165 }
166166 return comparison_method [operator ](second_operand )
167167
168+
168169class Header (metaclass = abc .ABCMeta ):
169170 """
170171 Abstact class for headers.
@@ -342,22 +343,19 @@ class CQCTypeHeader(Header):
342343 PACKAGING_FORMAT = "!BI"
343344 HDR_LENGTH = struct .calcsize (PACKAGING_FORMAT )
344345
345-
346- def _setVals (self , tp : CQCType = 0 , length : int = 0 ) -> None :
346+ def _setVals (self , tp : CQCType = 0 , length : int = 0 ) -> None :
347347 """
348348 Set using given values.
349349 """
350350 self .type = tp
351351 self .length = length
352352
353-
354353 def _pack (self ) -> bytes :
355354 """
356355 Pack data into packet format. For defnitions see cLib/cgc.h
357356 """
358357 return struct .pack (self .PACKAGING_FORMAT , self .type , self .length )
359358
360-
361359 def _unpack (self , headerBytes ) -> None :
362360 """
363361 Unpack packet data.
@@ -366,24 +364,21 @@ def _unpack(self, headerBytes) -> None:
366364 self .type = unpacked [0 ]
367365 self .length = unpacked [1 ]
368366
369-
370-
371367 def _printable (self ) -> str :
372368 """
373369 Produce a printable string for information purposes.
374370 """
375371 return "CQC Type header. Type=" + str (self .type ) + " | Length=" + str (self .length )
376372
377-
378373 def make_equivalent_CQCHeader (self , version : int , app_id : int ) -> CQCHeader :
379374 """
380- Produce a CQC Header that is equivalent to this CQCTypeHeader. This method does not make any modifications to self.
375+ Produce a CQC Header that is equivalent to this CQCTypeHeader.
376+ This method does not make any modifications to self.
381377 """
382378 cqc_header = CQCHeader ()
383379 cqc_header .setVals (version , self .type , app_id , self .length )
384380 return cqc_header
385-
386-
381+
387382
388383class CQCIFHeader (Header ):
389384 """
@@ -396,12 +391,14 @@ class CQCIFHeader(Header):
396391 TYPE_VALUE = 0
397392 TYPE_REF_ID = 1
398393
399- def _setVals (self ,
400- first_operand : int = 0 ,
401- operator : CQCLogicalOperator = 0 ,
402- type_of_second_operand : int = 0 ,
403- second_operand : int = 0 ,
404- length : int = 0 ) -> None :
394+ def _setVals (
395+ self ,
396+ first_operand : int = 0 ,
397+ operator : CQCLogicalOperator = 0 ,
398+ type_of_second_operand : int = 0 ,
399+ second_operand : int = 0 ,
400+ length : int = 0
401+ ) -> None :
405402 """
406403 Set the fields of this header.
407404 first_operand must be a reference id.
@@ -415,7 +412,6 @@ def _setVals(self,
415412 self .second_operand = second_operand
416413 self .length = length
417414
418-
419415 def _pack (self ) -> bytes :
420416 """
421417 Pack data into packet format. For defnitions see cLib/cgc.h
@@ -428,8 +424,7 @@ def _pack(self) -> bytes:
428424 self .type_of_second_operand ,
429425 self .second_operand ,
430426 self .length
431- )
432-
427+ )
433428
434429 def _unpack (self , headerBytes ) -> None :
435430 """
@@ -443,7 +438,6 @@ def _unpack(self, headerBytes) -> None:
443438 self .second_operand = unpacked [3 ]
444439 self .length = unpacked [4 ]
445440
446-
447441 def _printable (self ) -> str :
448442 """
449443 Produce a printable string for information purposes.
@@ -455,11 +449,12 @@ def _printable(self) -> str:
455449 operand_type = "Value"
456450
457451 # parenthesis to concatenate the string over multiple lines
458- return ("CQC IF header. RefID=" + str (self .first_operand )
459- + " | Operator=" + str (self .operator )
460- + " | " + operand_type + "=" + str (self .second_operand )
461- + " | Second_operand_type=" + operand_type
462- + " | Body_length=" + str (self .length )
452+ return (
453+ "CQC IF header. RefID=" + str (self .first_operand )
454+ + " | Operator=" + str (self .operator )
455+ + " | " + operand_type + "=" + str (self .second_operand )
456+ + " | Second_operand_type=" + operand_type
457+ + " | Body_length=" + str (self .length )
463458 )
464459
465460
@@ -471,7 +466,6 @@ class CQCCmdHeader(Header):
471466 PACKAGING_FORMAT = "!HBB"
472467 HDR_LENGTH = struct .calcsize (PACKAGING_FORMAT )
473468
474-
475469 def _setVals (self , qubit_id = 0 , instr = 0 , notify = False , block = False , action = False ):
476470 """
477471 Set using given values.
@@ -540,23 +534,20 @@ class CQCAssignHeader(Header):
540534
541535 PACKAGING_FORMAT = "!I"
542536 HDR_LENGTH = struct .calcsize (PACKAGING_FORMAT )
543-
544537
545- def _setVals (self , ref_id : int = 0 ) -> None :
538+ def _setVals (self , ref_id : int = 0 ) -> None :
546539 """
547540 Set using given values.
548541 """
549542 self .ref_id = ref_id
550543
551-
552544 def _pack (self ) -> bytes :
553545 """
554546 Pack data into packet format. For defnitions see cLib/cgc.h
555547 """
556548
557549 return struct .pack (self .PACKAGING_FORMAT , self .ref_id )
558550
559-
560551 def _unpack (self , headerBytes ) -> None :
561552 """
562553 Unpack packet data. For definitions see cLib/cqc.h
@@ -565,7 +556,6 @@ def _unpack(self, headerBytes) -> None:
565556
566557 self .ref_id = unpacked [0 ]
567558
568-
569559 def _printable (self ) -> str :
570560 """
571561 Produce a printable string for information purposes.
@@ -574,9 +564,6 @@ def _printable(self) -> str:
574564 return "CQC Assign sub header. RefID=" + str (self .ref_id )
575565
576566
577-
578-
579-
580567class CQCXtraHeader (Header ):
581568 """
582569 Optional addtional cmd header information. Only relevant for certain commands.
@@ -782,7 +769,7 @@ class CQCCommunicationHeader(Header):
782769
783770 PACKAGING_FORMAT = "!HHL"
784771 PACKAGING_FORMAT_V1 = "!HLH"
785- HDR_LENGTH = struct .calcsize (PACKAGING_FORMAT ) # Both versions have the same size
772+ HDR_LENGTH = struct .calcsize (PACKAGING_FORMAT ) # Both versions have the same size
786773
787774 def __init__ (self , headerBytes = None , cqc_version = CQC_VERSION ):
788775 """
0 commit comments