Quanlse/QWaveform.py
def generatePulseSequence(self, operators: Union[QOperator, Callable, List[QOperator], List[Callable]] = None,
                              onSubSys: Union[int, List[int]] = None, name: str = None, tag: str = None,
                              forPlot: bool = False, counting: Dict[str, int] = None,
                              phaseList: List[int] = None) -> List[Union[float, complex]]:
        """
        Generate the piecewise-constant pulse sequence according to the waveform configurations during
        the whole evolution time.

        :param operators: the list of operators
        :param onSubSys: the list of subsystems
        :param name: the key of control term
        :param tag: the tag of the waveforms
        :param forPlot: whether the sequence is for plotting
        :param counting: the waveform counting for all control terms
        :param phaseList: the list of phase on every time piece

        :return: the list of pulse sequence
        """

        _sequenceList = []
        _phaseList = []
        self.computeMaxTime()

        # Generate waveKey
        if name is not None:
            waveKey = name
        elif operators is not None and onSubSys is not None:
            _operators = formatOperatorInput(operators, onSubSys, self._sysLevel)
            operatorForSearch = combineOperatorAndOnSubSys(self._subSysNum, _operators, onSubSys)
            waveKey = generateOperatorKey(self.subSysNum, operatorForSearch)
        else:
            raise Error.ArgumentError("You must indicate the operators with onSubSys or the name of the term.")

        # Combine all waves (waves from current QJob instance and the parent QHamiltonian instance)
        combinedWaves = []
        if waveKey in self.waves:
            combinedWaves.extend(copy.deepcopy(self.waves[waveKey]))
        if self.parent is not None and waveKey in self.parent.doNotClearFlagWaves.keys():
            combinedWaves.extend(copy.deepcopy(self.parent.doNotClearFlagWaves[waveKey]))

        # A register for recording the phase accumulation for every control term.
        #     The values in this register may change over time.
        phaseAcc = {}
        phaseAccList = []

        # Traverse all the time slices.
        for nowDt in range(self.endTimeDt):
            # The amount of phase
            finalPhase = 0.
            # The amount of amplitude
            currentAmp = 0.
            # The nanosecond time of this moment
            nowNs = nowDt * self.dt + self.dt / 2.
            # The phase waveforms can work in this time window
            timeWindow = (nowNs - self.dt / 2., nowNs + self.dt / 2.)
            # Traverse all the waveforms
            for waveId, waveform in enumerate(combinedWaves):
                if waveform.flag & QWAVEFORM_FLAG_DO_NOT_PLOT > 0 and forPlot is True:
                    continue
                elif waveform.flag & QWAVEFORM_FLAG_ALWAYS_ON > 0:
                    waveform.t0 = 0.0
                    waveform.t = self.endTime
                else:
                    if tag is not None and waveform.tag != tag:
                        continue

                # Count the number of waveforms of the given operator
                if counting is not None:
                    if waveKey not in counting.keys():
                        counting[waveKey] = 0
                    counting[waveKey] += 1

                # Calculate the start and end time
                insertNs = waveform.t0
                if waveform.seq is not None:
                    endNs = waveform.t0 + len(waveform.seq) * self.dt
                else:
                    endNs = waveform.t0 + waveform.t

                # if the current waveform works
                if waveform.flag & QWAVEFORM_FLAG_PHASE_SHIFT > 0:
                    isWaveWorking = timeWindow[0] <= waveform.t0 < timeWindow[1]
                else:
                    isWaveWorking = insertNs <= nowNs < endNs

                if isWaveWorking:
                    # Calculate the waveforms' amplitudes.
                    waveform.dt = self.dt
                    if waveKey in self._LO.keys() or any([waveform.freq, waveform.phase0, waveform.phase]):
                        # The freq and phase shift set in QWaveform object
                        freq = 0. if waveform.freq is None else waveform.freq
                        phase = 0. if waveform.phase is None else waveform.phase
                        phase0 = 0. if waveform.phase0 is None else waveform.phase0
                        # Calculate the phase of the contemporary waveform
                        totalPhase = phase0
                        totalFreq = freq
                        # Plus the phase and frequency of the LO setup in QJob instance.
                        if waveKey in self._LO.keys():
                            totalFreq += self._LO[waveKey][0]
                            totalPhase += self._LO[waveKey][1]
                        # Calculate the accumulated phase in phaseAcc
                        if waveKey not in phaseAcc.keys():
                            phaseAcc[waveKey] = phase
                        else:
                            if waveId not in phaseAccList:
                                phaseAcc[waveKey] += phase
                                phaseAccList.append(waveId)
                        # The constant freq and phase set in QJob
                        totalPhase += phaseAcc[waveKey]
                        # Calculate the final LO value
                        if waveform.flag & QWAVEFORM_FLAG_MIX_WAVE > 0:
                            # If the waveform is the mixture of X and Y control
                            amp, varPhase = waveform(nowNs - waveform.t0)
                            finalPhase = totalPhase + varPhase
                            lo = math.cos(totalFreq * nowNs + finalPhase)
                            currentAmp += amp * lo
                        else:
                            finalPhase = totalPhase
                            lo = math.cos(totalFreq * nowNs + finalPhase)
                            currentAmp += waveform(nowNs - waveform.t0) * lo
                    else:
                        currentAmp += waveform(nowNs - waveform.t0)

                    # Modify the amplitudes by drive strength and amplitude noise.
                    currentAmp = currentAmp * waveform.strength
            _phaseList.append(finalPhase)
            _sequenceList.append(currentAmp)

        if phaseList is not None:
            phaseList = _phaseList
        del combinedWaves
        return _sequenceList

        Generate the piecewise-constant pulse sequence according to the waveform configurations during
        the whole evolution time.

        :param operators: the list of operators
        :param onSubSys: the list of subsystems
        :param name: the key of control term
        :param tag: the tag of the waveforms
        :param forPlot: whether the sequence is for plotting
        :param counting: the waveform counting for all control terms
        :param phaseList: the list of phase on every time piece

        :return: the list of pulse sequence
        
Generate the piecewise-constant pulse sequence according to the waveform configurations during
the whole evolution time.
Generate the piecewise - constant pulse sequence according to the waveform configurations during the whole evolution time .
def generatePulseSequence(self, operators: Union[QOperator, Callable, List[QOperator], List[Callable]] = None,
                              onSubSys: Union[int, List[int]] = None, name: str = None, tag: str = None,
                              forPlot: bool = False, counting: Dict[str, int] = None,
                              phaseList: List[int] = None) -> List[Union[float, complex]]:
        _sequenceList = []
        _phaseList = []
        self.computeMaxTime()
        if name is not None:
            waveKey = name
        elif operators is not None and onSubSys is not None:
            _operators = formatOperatorInput(operators, onSubSys, self._sysLevel)
            operatorForSearch = combineOperatorAndOnSubSys(self._subSysNum, _operators, onSubSys)
            waveKey = generateOperatorKey(self.subSysNum, operatorForSearch)
        else:
            raise Error.ArgumentError("You must indicate the operators with onSubSys or the name of the term.")
        combinedWaves = []
        if waveKey in self.waves:
            combinedWaves.extend(copy.deepcopy(self.waves[waveKey]))
        if self.parent is not None and waveKey in self.parent.doNotClearFlagWaves.keys():
            combinedWaves.extend(copy.deepcopy(self.parent.doNotClearFlagWaves[waveKey]))
        phaseAcc = {}
        phaseAccList = []
        for nowDt in range(self.endTimeDt):
            finalPhase = 0.
            currentAmp = 0.
            nowNs = nowDt * self.dt + self.dt / 2.
            timeWindow = (nowNs - self.dt / 2., nowNs + self.dt / 2.)
            for waveId, waveform in enumerate(combinedWaves):
                if waveform.flag & QWAVEFORM_FLAG_DO_NOT_PLOT > 0 and forPlot is True:
                    continue
                elif waveform.flag & QWAVEFORM_FLAG_ALWAYS_ON > 0:
                    waveform.t0 = 0.0
                    waveform.t = self.endTime
                else:
                    if tag is not None and waveform.tag != tag:
                        continue
                if counting is not None:
                    if waveKey not in counting.keys():
                        counting[waveKey] = 0
                    counting[waveKey] += 1
                insertNs = waveform.t0
                if waveform.seq is not None:
                    endNs = waveform.t0 + len(waveform.seq) * self.dt
                else:
                    endNs = waveform.t0 + waveform.t
                if waveform.flag & QWAVEFORM_FLAG_PHASE_SHIFT > 0:
                    isWaveWorking = timeWindow[0] <= waveform.t0 < timeWindow[1]
                else:
                    isWaveWorking = insertNs <= nowNs < endNs
                if isWaveWorking:
                    waveform.dt = self.dt
                    if waveKey in self._LO.keys() or any([waveform.freq, waveform.phase0, waveform.phase]):
                        freq = 0. if waveform.freq is None else waveform.freq
                        phase = 0. if waveform.phase is None else waveform.phase
                        phase0 = 0. if waveform.phase0 is None else waveform.phase0
                        totalPhase = phase0
                        totalFreq = freq
                        if waveKey in self._LO.keys():
                            totalFreq += self._LO[waveKey][0]
                            totalPhase += self._LO[waveKey][1]
                        if waveKey not in phaseAcc.keys():
                            phaseAcc[waveKey] = phase
                        else:
                            if waveId not in phaseAccList:
                                phaseAcc[waveKey] += phase
                                phaseAccList.append(waveId)
                        totalPhase += phaseAcc[waveKey]
                        if waveform.flag & QWAVEFORM_FLAG_MIX_WAVE > 0:
                            amp, varPhase = waveform(nowNs - waveform.t0)
                            finalPhase = totalPhase + varPhase
                            lo = math.cos(totalFreq * nowNs + finalPhase)
                            currentAmp += amp * lo
                        else:
                            finalPhase = totalPhase
                            lo = math.cos(totalFreq * nowNs + finalPhase)
                            currentAmp += waveform(nowNs - waveform.t0) * lo
                    else:
                        currentAmp += waveform(nowNs - waveform.t0)
                    currentAmp = currentAmp * waveform.strength
            _phaseList.append(finalPhase)
            _sequenceList.append(currentAmp)
        if phaseList is not None:
            phaseList = _phaseList
        del combinedWaves
        return _sequenceList
def generatePulseSequence ( self , operators : Union [ QOperator , Callable , List [ QOperator ] , List [ Callable ] ] = None , onSubSys : Union [ int , List [ int ] ] = None , name : str = None , tag : str = None , forPlot : bool = False , counting : Dict [ str , int ] = None , phaseList : List [ int ] = None ) -> List [ Union [ float , complex ] ] : _sequenceList = [ ] _phaseList = [ ] self . computeMaxTime ( ) if name is not None : waveKey = name elif operators is not None and onSubSys is not None : _operators = formatOperatorInput ( operators , onSubSys , self . _sysLevel ) operatorForSearch = combineOperatorAndOnSubSys ( self . _subSysNum , _operators , onSubSys ) waveKey = generateOperatorKey ( self . subSysNum , operatorForSearch ) else : raise Error . ArgumentError ( "You must indicate the operators with onSubSys or the name of the term." ) combinedWaves = [ ] if waveKey in self . waves : combinedWaves . extend ( copy . deepcopy ( self . waves [ waveKey ] ) ) if self . parent is not None and waveKey in self . parent . doNotClearFlagWaves . keys ( ) : combinedWaves . extend ( copy . deepcopy ( self . parent . doNotClearFlagWaves [ waveKey ] ) ) phaseAcc = { } phaseAccList = [ ] for nowDt in range ( self . endTimeDt ) : finalPhase = 0. currentAmp = 0. nowNs = nowDt * self . dt + self . dt / 2. timeWindow = ( nowNs - self . dt / 2. , nowNs + self . dt / 2. ) for waveId , waveform in enumerate ( combinedWaves ) : if waveform . flag & QWAVEFORM_FLAG_DO_NOT_PLOT > 0 and forPlot is True : continue elif waveform . flag & QWAVEFORM_FLAG_ALWAYS_ON > 0 : waveform . t0 = 0.0 waveform . t = self . endTime else : if tag is not None and waveform . tag != tag : continue if counting is not None : if waveKey not in counting . keys ( ) : counting [ waveKey ] = 0 counting [ waveKey ] += 1 insertNs = waveform . t0 if waveform . seq is not None : endNs = waveform . t0 + len ( waveform . seq ) * self . dt else : endNs = waveform . t0 + waveform . t if waveform . flag & QWAVEFORM_FLAG_PHASE_SHIFT > 0 : isWaveWorking = timeWindow [ 0 ] <= waveform . t0 < timeWindow [ 1 ] else : isWaveWorking = insertNs <= nowNs < endNs if isWaveWorking : waveform . dt = self . dt if waveKey in self . _LO . keys ( ) or any ( [ waveform . freq , waveform . phase0 , waveform . phase ] ) : freq = 0. if waveform . freq is None else waveform . freq phase = 0. if waveform . phase is None else waveform . phase phase0 = 0. if waveform . phase0 is None else waveform . phase0 totalPhase = phase0 totalFreq = freq if waveKey in self . _LO . keys ( ) : totalFreq += self . _LO [ waveKey ] [ 0 ] totalPhase += self . _LO [ waveKey ] [ 1 ] if waveKey not in phaseAcc . keys ( ) : phaseAcc [ waveKey ] = phase else : if waveId not in phaseAccList : phaseAcc [ waveKey ] += phase phaseAccList . append ( waveId ) totalPhase += phaseAcc [ waveKey ] if waveform . flag & QWAVEFORM_FLAG_MIX_WAVE > 0 : amp , varPhase = waveform ( nowNs - waveform . t0 ) finalPhase = totalPhase + varPhase lo = math . cos ( totalFreq * nowNs + finalPhase ) currentAmp += amp * lo else : finalPhase = totalPhase lo = math . cos ( totalFreq * nowNs + finalPhase ) currentAmp += waveform ( nowNs - waveform . t0 ) * lo else : currentAmp += waveform ( nowNs - waveform . t0 ) currentAmp = currentAmp * waveform . strength _phaseList . append ( finalPhase ) _sequenceList . append ( currentAmp ) if phaseList is not None : phaseList = _phaseList del combinedWaves return _sequenceList
Generate the piecewise-constant pulse sequence according to the waveform configurations during
the whole evolution time.
Generate the piecewise - constant pulse sequence according to the waveform configurations during the whole evolution time .
"""
        Generate the piecewise-constant pulse sequence according to the waveform configurations during
        the whole evolution time.

        :param operators: the list of operators
        :param onSubSys: the list of subsystems
        :param name: the key of control term
        :param tag: the tag of the waveforms
        :param forPlot: whether the sequence is for plotting
        :param counting: the waveform counting for all control terms
        :param phaseList: the list of phase on every time piece

        :return: the list of pulse sequence
        """ # Generate waveKey # Combine all waves (waves from current QJob instance and the parent QHamiltonian instance) # A register for recording the phase accumulation for every control term. #     The values in this register may change over time. # Traverse all the time slices. # The amount of phase # The amount of amplitude # The nanosecond time of this moment # The phase waveforms can work in this time window # Traverse all the waveforms # Count the number of waveforms of the given operator # Calculate the start and end time # if the current waveform works # Calculate the waveforms' amplitudes. # The freq and phase shift set in QWaveform object # Calculate the phase of the contemporary waveform # Plus the phase and frequency of the LO setup in QJob instance. # Calculate the accumulated phase in phaseAcc # The constant freq and phase set in QJob # Calculate the final LO value # If the waveform is the mixture of X and Y control # Modify the amplitudes by drive strength and amplitude noise.
the list of pulse sequence
the list of pulse sequence
self
operators
Union[QOperator, Callable, List[QOperator], List[Callable]]
the list of operators
the list of operators
onSubSys
Union[int, List[int]]
the list of subsystems
the list of subsystems
name
str
the key of control term
the key of control term
tag
str
the tag of the waveforms
the tag of the waveforms
forPlot
bool
whether the sequence is for plotting
whether the sequence is for plotting
counting
Dict[str, int]
the waveform counting for all control terms
the waveform counting for all control terms
phaseList
List[int]
the list of phase on every time piece
the list of phase on every time piece