def create_extra_control_header(cmd, cmd_data, cqc_version=CQC_VERSION): cmd_length = CQCXtraQubitHeader.HDR_LENGTH hdr = CQCXtraQubitHeader(cmd_data[:cmd_length]) hdr_control = CQCXtraQubitHeader(cmd_data[cmd_length:cmd_length + 2]) return hdr, hdr_control
def create_extra_header(cmd, cmd_data, cqc_version=CQC_VERSION): """ Create the extra header (communication header, rotation header, etc) based on the command """ if cqc_version < 1: if has_extra(cmd): cmd_length = CQCXtraHeader.HDR_LENGTH hdr = CQCXtraHeader(cmd_data[:cmd_length]) return hdr else: return None instruction = cmd.instr if instruction == CQC_CMD_SEND or instruction == CQC_CMD_EPR: cmd_length = CQCCommunicationHeader.HDR_LENGTH hdr = CQCCommunicationHeader(cmd_data[:cmd_length], cqc_version=cqc_version) elif instruction == CQC_CMD_CNOT or instruction == CQC_CMD_CPHASE: cmd_length = CQCXtraQubitHeader.HDR_LENGTH hdr = CQCXtraQubitHeader(cmd_data[:cmd_length]) elif instruction == CQC_CMD_ROT_X or instruction == CQC_CMD_ROT_Y or instruction == CQC_CMD_ROT_Z: cmd_length = CQCRotationHeader.HDR_LENGTH hdr = CQCRotationHeader(cmd_data[:cmd_length]) elif instruction == CQC_CMD_MEASURE or instruction == CQC_CMD_MEASURE_INPLACE: cmd_length = CQCAssignHeader.HDR_LENGTH hdr = CQCAssignHeader(cmd_data[:cmd_length]) else: return None return hdr
def construct_command_headers(self, qID, command, **kwargs): """Construct a commmand consisting of a list of header objects. Extra arguments are only used if the command if of a type that needs them. - **Arguments** :qID: qubit ID :command: Command to be executed, eg CQC_CMD_H :nofify: Do we wish to be notified when done. :block: Do we want the qubit to be blocked """ # Construct extra header if needed. xtra_hdr = None if command == CQC_CMD_SEND or command == CQC_CMD_EPR: xtra_hdr = CQCCommunicationHeader() remote_appID = kwargs.get("remote_appID", 0) remote_node = kwargs.get("remote_node", 0) remote_port = kwargs.get("remote_port", 0) xtra_hdr.setVals(remote_appID, remote_node, remote_port) elif command == CQC_CMD_CNOT or command == CQC_CMD_CPHASE: xtra_hdr = CQCXtraQubitHeader() xtra_qID = kwargs.get("xtra_qID", 0) xtra_hdr.setVals(xtra_qID) elif (command == CQC_CMD_ROT_X or command == CQC_CMD_ROT_Y or command == CQC_CMD_ROT_Z): xtra_hdr = CQCRotationHeader() step = kwargs.get("step", 0) xtra_hdr.setVals(step) elif command == CQC_CMD_MEASURE or command == CQC_CMD_MEASURE_INPLACE: xtra_hdr = CQCAssignHeader() ref_id = kwargs.get("ref_id", 0) xtra_hdr.setVals(ref_id) # If xtra_hdr is None, we don't need an extra message. if xtra_hdr is None: header_length = CQCCmdHeader.HDR_LENGTH else: header_length = CQCCmdHeader.HDR_LENGTH + xtra_hdr.HDR_LENGTH # Construct Header hdr = CQCHeader() hdr.setVals(CQC_VERSION, CQC_TP_COMMAND, self._appID, header_length) # Construct Command cmd_hdr = CQCCmdHeader() notify = int(kwargs.get("notify", True)) block = int(kwargs.get("block", True)) action = int(kwargs.get("action", False)) cmd_hdr.setVals(qID, command, notify, block, action) headers = [hdr, cmd_hdr] if xtra_hdr is not None: headers.append(xtra_hdr) return headers