Exemplo n.º 1
0
Arquivo: plot.py Projeto: foosa/qudy
def profile( sequence, target, **keyword_args ):
    """
    Makes a log-log scaling plot of a sequence infidelity relative to a target gate.
    """
    
    # Parse keyword arguments.
    if keyword_args.has_key('min_epsilon'):
        min_epsilon = keyword_args['min_epsilon']
    else:
        min_epsilon = -1

    if keyword_args.has_key('max_epsilon'):
        max_epsilon = keyword_args['max_epsilon']
    else:
        max_epsilon = 1

    if keyword_args.has_key('points'):
        points = keyword_args['points']
    else:
        points = 500.0

    if keyword_args.has_key('show'):
        show = keyword_args['show']
    else:
        show = True

    if keyword_args.has_key('label'):
        label = keyword_args['label']
    else:
        label = None

    if keyword_args.has_key('calculation'):
        calculation = keyword_args['calculation']
    else:
        calculation = 'infidelity'
        
    
    # Create a set of error amplitudes to measure scaling
    dE  = max_epsilon - min_epsilon
    epsilon = qu.arange( min_epsilon, max_epsilon + dE/points, dE / points )

    # Compute matrix representation of target gate
    if hasattr( target, 'solve' ):
        Ut = target.solve()
    else:
        Ut = target

    # Perform calculation
    err = sequence.error.copy()
    y = []
    for index in range( len(epsilon) ):
        
        e = epsilon[index]
        err.error_parameters = [ e ]
        sequence.update_error(err)

        if calculation == 'infidelity':
            y.append( ro.infidelity(sequence.solve() , Ut) )

        elif calculation == 'population':
            p0 = qu.operator("0,0;0,1")
            p1 = qu.operator("1,0;0,0")
            U = sequence.solve()
            y.append( qu.trace( U*p0*U.H*p1 ) )
    
    if show:
        
        # Create plot
        if label == None:
            plt.plot( qu.real(epsilon) , qu.real( y ) )
        else:
            plt.plot( qu.real(epsilon) , qu.real( y ), label = label )
            
        plt.xlabel(r'Systematic Error')

        if calculation == 'infidelity':
            plt.ylabel(r'Infidelity')
            
        elif calculation == 'population':
            plt.ylabel(r'Population')
            
        plt.xlim([min_epsilon, max_epsilon]) 
        plt.show()
        
    else:
        
        # Return data to user
        return [ qu.real(epsilon) , qu.real(y) ]
Exemplo n.º 2
0
Arquivo: plot.py Projeto: foosa/qudy
def scaling( sequence, target, **keyword_args ):
    """
    Makes a log-log scaling plot of a sequence infidelity relative to a target gate.
    """
    
    # Parse keyword arguments.
    if keyword_args.has_key('min_epsilon'):
        min_epsilon = keyword_args['min_epsilon']
    else:
        min_epsilon = 1e-5

    if keyword_args.has_key('max_epsilon'):
        max_epsilon = keyword_args['max_epsilon']
    else:
        max_epsilon = 1

    if keyword_args.has_key('points'):
        points = keyword_args['points']
    else:
        points = 500.0

    if keyword_args.has_key('show'):
        show = keyword_args['show']
    else:
        show = True
    
    if keyword_args.has_key('calculation'):
        calculation = keyword_args['calculation']
    else:
        calculation = 'infidelity'
        
    
    # Create a set of error amplitudes to measure scaling
    log_epsilon = qu.arange( qu.log10(min_epsilon), qu.log10(max_epsilon), \
                  (qu.log10(max_epsilon) -qu.log10(min_epsilon))/float(points) )

    epsilon = []
    err = sequence.error.copy()
    for index in range( len(log_epsilon) ):
        epsilon.append( 10**log_epsilon[index] )

    # Compute matrix representation of target gate
    try:
        Ut = target.solve()
    except AttributeError:
        Ut = target

    # Measure infidelities
    y = []
    for index in range( len(epsilon) ):
        
        e = epsilon[index]
        err.error_parameters = [ e ]
        sequence.update_error(err)

        if calculation == 'infidelity':
            y.append( ro.infidelity(sequence.solve() , Ut) )

        elif calculation == 'population':
            p0 = qu.operator("0,0;0,1")
            p1 = qu.operator("1,0;0,0")
            U = sequence.solve()
            y.append( qu.trace( U*p0*U.H*p1 ) )
    
    if show:
        
        # Create plot
        plt.loglog( qu.real(epsilon) , qu.real( y ) )
        plt.xlabel(r'Systematic Error')

        if calculation == 'infidelity':
            plt.ylabel(r'Infidelity')
            
        elif calculation == 'population':
            plt.ylabel(r'Population')
            
        plt.xlim([min_epsilon, max_epsilon]) 
        plt.show()
        
    else:
        
        # Return data to user
        return [ qu.real(epsilon) , qu.real(infidelities) ]