Quanlse/Simulator/__init__.py
def simulate(self, duration: Union[int, float], resIdx: Optional[List[int]] = None,
                 state: 'str' = 'ground') -> Dict:
        """
        Simulate the state evolution of the qubit-resonator system using Jaynes-Cumming model.

        :param duration: pulse duration of the measurement.
        :param resIdx: indexes of the resonator the pulse acted on.
        :param state: qubit state prepared in ground state or in excited state, Optional parameter 'ground' or 'excited'

        :return: None.
        """

        if self._readoutPulse is None:
            raise Error.ArgumentError("You need to define object of class: ReadoutPulse")

        # Extract information for qubit readout simulation
        k = self.conversionLoss
        kappa = self.dissipation
        g = self.gain
        z = self.impedance
        qubitLevel = self.pulseModel.sysLevel

        # check if the qubit index exists
        if resIdx is not None:
            for idx in resIdx:
                if idx not in range(self.pulseModel.subSysNum):
                    raise Error.ArgumentError(f"Qubit index {idx} not found")
        else:
            resIdx = range(self.pulseModel.subSysNum)

        readoutPulse = self.readoutPulse

        if state == 'ground':
            psi = tensor(basis(qubitLevel, 0), basis(self.level, 0))
        elif state == 'excited':
            psi = tensor(basis(qubitLevel, 1), basis(self.level, 0))
        else:
            raise Error.ArgumentError("The input qubit state is 'ground' or 'excited'")

        # set the frequency of local oscillator for demodulation
        omegaLo = readoutPulse.loFreq

        # initialize a dict object to record the evolution
        rhoHistory = {}

        # define annihilation and creation operators
        a = tensor([identity(qubitLevel), destroy(self.level).matrix])
        adag = dagger(a)

        # define quadrature operators
        x = 0.5 * (adag + a)
        p = 1j * 0.5 * (adag - a)

        viRawList = {}
        vqRawList = {}
        viList = {}
        vqList = {}
        rhoList = {}

        # simulate the readout dynamic of the designated qubits
        for idx in resIdx:

            # run simulation of the given qubit
            ham = self._createHam(idx=idx, driveFreq=readoutPulse.driveFreq[idx])
            job = self._readoutJob(amp=readoutPulse.driveStrength[idx], duration=duration)
            res0 = ham.simulate(state0=psi, job=job, isOpen=True, recordEvolution=True)

            # Append the evolution of density matrix to idx-th qubit
            rhoHistory[idx] = res0[0]['evolution_history']

            _, maxDt = job.computeMaxTime()
            timeIdx = range(0, int(maxDt))

            # Calculate the intermediate frequency
            omegaRf = self.readoutPulse.driveFreq[idx]

            omegaIf = abs(omegaLo - omegaRf)

            viRawList[idx] = []
            vqRawList[idx] = []

            vif = k * readoutPulse.driveStrength[idx] * sqrt(kappa * g * z * omegaRf / 2)

            # Record the raw data of vi, vq quadratures for each dt
            for dtIdx in timeIdx:

                nowTime = dtIdx * self.dt
                nowRho = rhoHistory[idx][dtIdx]

                vi = vif * (x * cos(omegaIf * nowTime) - p * sin(omegaIf * nowTime))

                vq = - vif * (p * cos(omegaIf * nowTime) + x * sin(omegaIf * nowTime))

                viRawList[idx].append(trace(vi @ nowRho).real)
                vqRawList[idx].append(trace(vq @ nowRho).real)

            viList[idx] = trace(vif * x @ rhoHistory[idx][-1]).real
            vqList[idx] = trace(-vif * p @ rhoHistory[idx][-1]).real

            rhoList[idx] = rhoHistory[idx][-1]

        # Return the result in the form of dictionary data type
        readoutData = {'vi': viList,
                       'vq': vqList,
                       'viRaw': viList,
                       'vqRaw': vqList,
                       'index': resIdx,
                       'duration': duration,
                       'dt': self.dt,
                       'loFreq': omegaLo,
                       'rho': rhoList}

        return readoutData

        Simulate the state evolution of the qubit-resonator system using Jaynes-Cumming model.

        :param duration: pulse duration of the measurement.
        :param resIdx: indexes of the resonator the pulse acted on.
        :param state: qubit state prepared in ground state or in excited state, Optional parameter 'ground' or 'excited'

        :return: None.
        
Simulate the state evolution of the qubit-resonator system using Jaynes-Cumming model.
Simulate the state evolution of the qubit - resonator system using Jaynes - Cumming model .
def simulate(self, duration: Union[int, float], resIdx: Optional[List[int]] = None,
                 state: 'str' = 'ground') -> Dict:
        if self._readoutPulse is None:
            raise Error.ArgumentError("You need to define object of class: ReadoutPulse")
        k = self.conversionLoss
        kappa = self.dissipation
        g = self.gain
        z = self.impedance
        qubitLevel = self.pulseModel.sysLevel
        if resIdx is not None:
            for idx in resIdx:
                if idx not in range(self.pulseModel.subSysNum):
                    raise Error.ArgumentError(f"Qubit index {idx} not found")
        else:
            resIdx = range(self.pulseModel.subSysNum)
        readoutPulse = self.readoutPulse
        if state == 'ground':
            psi = tensor(basis(qubitLevel, 0), basis(self.level, 0))
        elif state == 'excited':
            psi = tensor(basis(qubitLevel, 1), basis(self.level, 0))
        else:
            raise Error.ArgumentError("The input qubit state is 'ground' or 'excited'")
        omegaLo = readoutPulse.loFreq
        rhoHistory = {}
        a = tensor([identity(qubitLevel), destroy(self.level).matrix])
        adag = dagger(a)
        x = 0.5 * (adag + a)
        p = 1j * 0.5 * (adag - a)
        viRawList = {}
        vqRawList = {}
        viList = {}
        vqList = {}
        rhoList = {}
        for idx in resIdx:
            ham = self._createHam(idx=idx, driveFreq=readoutPulse.driveFreq[idx])
            job = self._readoutJob(amp=readoutPulse.driveStrength[idx], duration=duration)
            res0 = ham.simulate(state0=psi, job=job, isOpen=True, recordEvolution=True)
            rhoHistory[idx] = res0[0]['evolution_history']
            _, maxDt = job.computeMaxTime()
            timeIdx = range(0, int(maxDt))
            omegaRf = self.readoutPulse.driveFreq[idx]
            omegaIf = abs(omegaLo - omegaRf)
            viRawList[idx] = []
            vqRawList[idx] = []
            vif = k * readoutPulse.driveStrength[idx] * sqrt(kappa * g * z * omegaRf / 2)
            for dtIdx in timeIdx:
                nowTime = dtIdx * self.dt
                nowRho = rhoHistory[idx][dtIdx]
                vi = vif * (x * cos(omegaIf * nowTime) - p * sin(omegaIf * nowTime))
                vq = - vif * (p * cos(omegaIf * nowTime) + x * sin(omegaIf * nowTime))
                viRawList[idx].append(trace(vi @ nowRho).real)
                vqRawList[idx].append(trace(vq @ nowRho).real)
            viList[idx] = trace(vif * x @ rhoHistory[idx][-1]).real
            vqList[idx] = trace(-vif * p @ rhoHistory[idx][-1]).real
            rhoList[idx] = rhoHistory[idx][-1]
        readoutData = {'vi': viList,
                       'vq': vqList,
                       'viRaw': viList,
                       'vqRaw': vqList,
                       'index': resIdx,
                       'duration': duration,
                       'dt': self.dt,
                       'loFreq': omegaLo,
                       'rho': rhoList}
        return readoutData
def simulate ( self , duration : Union [ int , float ] , resIdx : Optional [ List [ int ] ] = None , state : 'str' = 'ground' ) -> Dict : if self . _readoutPulse is None : raise Error . ArgumentError ( "You need to define object of class: ReadoutPulse" ) k = self . conversionLoss kappa = self . dissipation g = self . gain z = self . impedance qubitLevel = self . pulseModel . sysLevel if resIdx is not None : for idx in resIdx : if idx not in range ( self . pulseModel . subSysNum ) : raise Error . ArgumentError ( f"Qubit index {idx} not found" ) else : resIdx = range ( self . pulseModel . subSysNum ) readoutPulse = self . readoutPulse if state == 'ground' : psi = tensor ( basis ( qubitLevel , 0 ) , basis ( self . level , 0 ) ) elif state == 'excited' : psi = tensor ( basis ( qubitLevel , 1 ) , basis ( self . level , 0 ) ) else : raise Error . ArgumentError ( "The input qubit state is 'ground' or 'excited'" ) omegaLo = readoutPulse . loFreq rhoHistory = { } a = tensor ( [ identity ( qubitLevel ) , destroy ( self . level ) . matrix ] ) adag = dagger ( a ) x = 0.5 * ( adag + a ) p = 1j * 0.5 * ( adag - a ) viRawList = { } vqRawList = { } viList = { } vqList = { } rhoList = { } for idx in resIdx : ham = self . _createHam ( idx = idx , driveFreq = readoutPulse . driveFreq [ idx ] ) job = self . _readoutJob ( amp = readoutPulse . driveStrength [ idx ] , duration = duration ) res0 = ham . simulate ( state0 = psi , job = job , isOpen = True , recordEvolution = True ) rhoHistory [ idx ] = res0 [ 0 ] [ 'evolution_history' ] _ , maxDt = job . computeMaxTime ( ) timeIdx = range ( 0 , int ( maxDt ) ) omegaRf = self . readoutPulse . driveFreq [ idx ] omegaIf = abs ( omegaLo - omegaRf ) viRawList [ idx ] = [ ] vqRawList [ idx ] = [ ] vif = k * readoutPulse . driveStrength [ idx ] * sqrt ( kappa * g * z * omegaRf / 2 ) for dtIdx in timeIdx : nowTime = dtIdx * self . dt nowRho = rhoHistory [ idx ] [ dtIdx ] vi = vif * ( x * cos ( omegaIf * nowTime ) - p * sin ( omegaIf * nowTime ) ) vq = - vif * ( p * cos ( omegaIf * nowTime ) + x * sin ( omegaIf * nowTime ) ) viRawList [ idx ] . append ( trace ( vi @ nowRho ) . real ) vqRawList [ idx ] . append ( trace ( vq @ nowRho ) . real ) viList [ idx ] = trace ( vif * x @ rhoHistory [ idx ] [ - 1 ] ) . real vqList [ idx ] = trace ( - vif * p @ rhoHistory [ idx ] [ - 1 ] ) . real rhoList [ idx ] = rhoHistory [ idx ] [ - 1 ] readoutData = { 'vi' : viList , 'vq' : vqList , 'viRaw' : viList , 'vqRaw' : vqList , 'index' : resIdx , 'duration' : duration , 'dt' : self . dt , 'loFreq' : omegaLo , 'rho' : rhoList } return readoutData
Simulate the state evolution of the qubit-resonator system using Jaynes-Cumming model.
Simulate the state evolution of the qubit - resonator system using Jaynes - Cumming model .
"""
        Simulate the state evolution of the qubit-resonator system using Jaynes-Cumming model.

        :param duration: pulse duration of the measurement.
        :param resIdx: indexes of the resonator the pulse acted on.
        :param state: qubit state prepared in ground state or in excited state, Optional parameter 'ground' or 'excited'

        :return: None.
        """ # Extract information for qubit readout simulation # check if the qubit index exists # set the frequency of local oscillator for demodulation # initialize a dict object to record the evolution # define annihilation and creation operators # define quadrature operators # simulate the readout dynamic of the designated qubits # run simulation of the given qubit # Append the evolution of density matrix to idx-th qubit # Calculate the intermediate frequency # Record the raw data of vi, vq quadratures for each dt # Return the result in the form of dictionary data type
None
self
duration
Union[int, float]
pulse duration of the measurement.
pulse duration of the measurement .
resIdx
Optional[List[int]]
indexes of the resonator the pulse acted on.
indexes of the resonator the pulse acted on .
state
'str'
qubit state prepared in ground state or in excited state, Optional parameter 'ground' or 'excited'
qubit state prepared in ground state or in excited state Optional parameter ' ground ' or ' excited '