Exemplo n.º 1
0
def acquire_data(heater_index, N=20, hold=[]):
    min_voltage, max_voltage=0, 7
    parameter_space=np.linspace(min_voltage, max_voltage, N)
    experiment=np.zeros([N, 5])
    theory=np.zeros([N, 4])
    fidelity=np.zeros(N)
        
    for index_1, parameter_1 in enumerate(parameter_space):
        
        
        # Figure out the settings
        phases=np.zeros(8)
        for index, phase in hold:
            print 'hold phase %d: %.3f' % (index, phase)
            phases[index]=phase
        
        voltages=np.array(table.get_voltages(phases))
        print 'sweep voltage %d: %.3f' % (heater_index, parameter_1)
        voltages[heater_index] = parameter_1
        print 'final voltages',  voltages.round(2)
        parameters=table.get_parameters(heater_index)
        #phase_voltage_2 for added linear dependance
        phases[heater_index] = fitting.phase_voltage_2(parameters, parameter_1)
        
        # Do the measurement
        experiment[index_1] = do_experiment(voltages)
        theory[index_1] = do_theory(phases, experiment[index_1][4])
        fidelity[index_1]=statistical_fidelity(experiment[index_1][:4]/experiment[index_1][4], theory[index_1]/experiment[index_1][4])
        print fidelity[index_1]
        
        # Plot
        plot_now(experiment, theory, parameter_space, fidelity, do_fit=False)

    # Close hardware
    dac.zero()
    
    # Normalize, save and return data
    #data=data/np.amax(data)
    experiment_filename, theory_filename, param_filename = get_filenames(heater_index)
    np.save(experiment_filename, experiment)
    np.save(theory_filename, theory)
    np.save(param_filename, parameter_space)
    return experiment_filename, theory_filename, param_filename
Exemplo n.º 2
0
def new_sample(device):
    #phases=[0,pi,0,0,0,0,0,0]
    #phases=[pi,pi,0,0,0,0,0,0]
    phases=np.random.uniform(0,np.pi*2,8)
    phases[6]=0.93361981
    phases[0]=np.pi
    counts=do_measurement(phases, ontime=2)
    
    coincidences=np.array(counts[8:12])
    accidentals=np.array([counts[12], counts[17], counts[16], counts[13]])
    corrected_counts=coincidences-accidentals
    probabilities_expt=corrected_counts/float(np.sum(corrected_counts))
    print probabilities_expt
    
    '''get some simulated probabilities'''
    device.set_phases(phases)
    simulator=lo.simulator(device, nphotons=2)
    simulator.set_input_state([1,3])
    probabilities_theory=simulator.get_probabilities(patterns=[[1,3],[1,4],[2,3],[2,4]])
    sum_probs=sum(probabilities_theory)
    probabilities_theory=np.array(probabilities_theory)/sum_probs
    fidelity=statistical_fidelity(probabilities_expt, probabilities_theory)
    return np.sum(coincidences), np.sum(accidentals), np.sum(fidelity), phases, coincidences, accidentals
Exemplo n.º 3
0
def new_sample(device):
    #phases=[0,pi,0,0,0,0,0,0]
    #phases=[pi,pi,0,0,0,0,0,0]
    phases = np.random.uniform(0, np.pi * 2, 8)
    phases[6] = 0.93361981
    phases[0] = np.pi
    counts = do_measurement(phases, ontime=2)

    coincidences = np.array(counts[8:12])
    accidentals = np.array([counts[12], counts[17], counts[16], counts[13]])
    corrected_counts = coincidences - accidentals
    probabilities_expt = corrected_counts / float(np.sum(corrected_counts))
    print probabilities_expt
    '''get some simulated probabilities'''
    device.set_phases(phases)
    simulator = lo.simulator(device, nphotons=2)
    simulator.set_input_state([1, 3])
    probabilities_theory = simulator.get_probabilities(
        patterns=[[1, 3], [1, 4], [2, 3], [2, 4]])
    sum_probs = sum(probabilities_theory)
    probabilities_theory = np.array(probabilities_theory) / sum_probs
    fidelity = statistical_fidelity(probabilities_expt, probabilities_theory)
    return np.sum(coincidences), np.sum(accidentals), np.sum(
        fidelity), phases, coincidences, accidentals