Quanlse/Calibration/TwoQubit.py
def caliSingleQubitGates(sche: Scheduler, q0: int, q1: int, runner: Callable = None, bounds: List = None,
                         q0ParaInit: Optional[List[float]] = None, q1ParaInit: List[float] = None, options: Any = None):
    """
    Find the best qubit frequency.

    :param sche: the Scheduler instance
    :param q0: the index of the first qubit to be calibrated
    :param q1: the index of the second qubit to be calibrated
    :param runner: a callable function which can pass the QJob/QJobList instances and obtain the result
    :param bounds: the optimization bounds for each parameter
    :param q0ParaInit: specify a fixed frequency shift for qubit 0
    :param q1ParaInit: the list of the qubit 1 frequency shift (based on the present qubit frequency)
    :param options: options pass to the runner function
    """

    _, idealMatrixList = caliSingleQubitGatesJob(sche, q0, q1, None, None, True)

    def _singleQubitCaliLoss(x):
        """
        Obtain the calibration pulse jobs and calculate the loss function.
        """

        # Generate the pulse jobs for calibration
        caliJobs, _ = caliSingleQubitGatesJob(sche, q0, q1, [x[0], x[1]], [x[2], x[3]], False)

        # Simulate the calibration pulse
        if isinstance(sche, PulseModel):
            results = sche.simulate(jobList=caliJobs, options=options)
        else:
            if runner is None or not callable(runner):
                raise ArgumentError("Please input a callable runner!")
            results = runner(jobList=caliJobs, options=options)

        lossSum = 0.
        for _jobIdx, _idealMat in enumerate(idealMatrixList):
            # Obtain the output population value
            pop = project(numpy.square(abs(results[_jobIdx]["state"])).T[0], sche.subSysNum, sche.sysLevel, 2)

            # Obtain the ideal population
            stateIdeal = _idealMat @ basis(_idealMat.shape[0], 0).T[0]
            popIdeal = numpy.square(abs(stateIdeal))

            # Calculate the loss function
            lossSum += numpy.sum(numpy.abs(pop - popIdeal)) / len(pop)

        aveLoss = lossSum / len(idealMatrixList)
        return aveLoss

    from scipy.optimize import minimize
    InitParas = [q0ParaInit[0], q0ParaInit[1], q1ParaInit[0], q1ParaInit[1]]
    opt = minimize(_singleQubitCaliLoss, x0=numpy.array(InitParas), bounds=bounds, method="l-bfgs-b")
    return opt["x"][0], opt["x"][1], opt["x"][2], opt["x"][3], opt["fun"]

    Find the best qubit frequency.

    :param sche: the Scheduler instance
    :param q0: the index of the first qubit to be calibrated
    :param q1: the index of the second qubit to be calibrated
    :param runner: a callable function which can pass the QJob/QJobList instances and obtain the result
    :param bounds: the optimization bounds for each parameter
    :param q0ParaInit: specify a fixed frequency shift for qubit 0
    :param q1ParaInit: the list of the qubit 1 frequency shift (based on the present qubit frequency)
    :param options: options pass to the runner function
    
Find the best qubit frequency.
Find the best qubit frequency .
def caliSingleQubitGates(sche: Scheduler, q0: int, q1: int, runner: Callable = None, bounds: List = None,
                         q0ParaInit: Optional[List[float]] = None, q1ParaInit: List[float] = None, options: Any = None):
    _, idealMatrixList = caliSingleQubitGatesJob(sche, q0, q1, None, None, True)
    def _singleQubitCaliLoss(x):
        caliJobs, _ = caliSingleQubitGatesJob(sche, q0, q1, [x[0], x[1]], [x[2], x[3]], False)
        if isinstance(sche, PulseModel):
            results = sche.simulate(jobList=caliJobs, options=options)
        else:
            if runner is None or not callable(runner):
                raise ArgumentError("Please input a callable runner!")
            results = runner(jobList=caliJobs, options=options)
        lossSum = 0.
        for _jobIdx, _idealMat in enumerate(idealMatrixList):
            pop = project(numpy.square(abs(results[_jobIdx]["state"])).T[0], sche.subSysNum, sche.sysLevel, 2)
            stateIdeal = _idealMat @ basis(_idealMat.shape[0], 0).T[0]
            popIdeal = numpy.square(abs(stateIdeal))
            lossSum += numpy.sum(numpy.abs(pop - popIdeal)) / len(pop)
        aveLoss = lossSum / len(idealMatrixList)
        return aveLoss
    from scipy.optimize import minimize
    InitParas = [q0ParaInit[0], q0ParaInit[1], q1ParaInit[0], q1ParaInit[1]]
    opt = minimize(_singleQubitCaliLoss, x0=numpy.array(InitParas), bounds=bounds, method="l-bfgs-b")
    return opt["x"][0], opt["x"][1], opt["x"][2], opt["x"][3], opt["fun"]
def caliSingleQubitGates ( sche : Scheduler , q0 : int , q1 : int , runner : Callable = None , bounds : List = None , q0ParaInit : Optional [ List [ float ] ] = None , q1ParaInit : List [ float ] = None , options : Any = None ) : _ , idealMatrixList = caliSingleQubitGatesJob ( sche , q0 , q1 , None , None , True ) def _singleQubitCaliLoss ( x ) : """
        Obtain the calibration pulse jobs and calculate the loss function.
        """ caliJobs , _ = caliSingleQubitGatesJob ( sche , q0 , q1 , [ x [ 0 ] , x [ 1 ] ] , [ x [ 2 ] , x [ 3 ] ] , False ) if isinstance ( sche , PulseModel ) : results = sche . simulate ( jobList = caliJobs , options = options ) else : if runner is None or not callable ( runner ) : raise ArgumentError ( "Please input a callable runner!" ) results = runner ( jobList = caliJobs , options = options ) lossSum = 0. for _jobIdx , _idealMat in enumerate ( idealMatrixList ) : pop = project ( numpy . square ( abs ( results [ _jobIdx ] [ "state" ] ) ) . T [ 0 ] , sche . subSysNum , sche . sysLevel , 2 ) stateIdeal = _idealMat @ basis ( _idealMat . shape [ 0 ] , 0 ) . T [ 0 ] popIdeal = numpy . square ( abs ( stateIdeal ) ) lossSum += numpy . sum ( numpy . abs ( pop - popIdeal ) ) / len ( pop ) aveLoss = lossSum / len ( idealMatrixList ) return aveLoss from scipy . optimize import minimize InitParas = [ q0ParaInit [ 0 ] , q0ParaInit [ 1 ] , q1ParaInit [ 0 ] , q1ParaInit [ 1 ] ] opt = minimize ( _singleQubitCaliLoss , x0 = numpy . array ( InitParas ) , bounds = bounds , method = "l-bfgs-b" ) return opt [ "x" ] [ 0 ] , opt [ "x" ] [ 1 ] , opt [ "x" ] [ 2 ] , opt [ "x" ] [ 3 ] , opt [ "fun" ]
Find the best qubit frequency.
Find the best qubit frequency .
"""
    Find the best qubit frequency.

    :param sche: the Scheduler instance
    :param q0: the index of the first qubit to be calibrated
    :param q1: the index of the second qubit to be calibrated
    :param runner: a callable function which can pass the QJob/QJobList instances and obtain the result
    :param bounds: the optimization bounds for each parameter
    :param q0ParaInit: specify a fixed frequency shift for qubit 0
    :param q1ParaInit: the list of the qubit 1 frequency shift (based on the present qubit frequency)
    :param options: options pass to the runner function
    """ """
        Obtain the calibration pulse jobs and calculate the loss function.
        """ # Generate the pulse jobs for calibration # Simulate the calibration pulse # Obtain the output population value # Obtain the ideal population # Calculate the loss function
sche
Scheduler
the Scheduler instance
the Scheduler instance
q0
int
the index of the first qubit to be calibrated
the index of the first qubit to be calibrated
q1
int
the index of the second qubit to be calibrated
the index of the second qubit to be calibrated
runner
Callable
a callable function which can pass the QJob/QJobList instances and obtain the result
a callable function which can pass the QJob / QJobList instances and obtain the result
bounds
List
the optimization bounds for each parameter
the optimization bounds for each parameter
q0ParaInit
Optional[List[float]]
specify a fixed frequency shift for qubit 0
specify a fixed frequency shift for qubit 0
q1ParaInit
List[float]
the list of the qubit 1 frequency shift (based on the present qubit frequency)
the list of the qubit 1 frequency shift ( based on the present qubit frequency )
options
Any
options pass to the runner function
options pass to the runner function