예제 #1
0
    def test_apply_random(self):
        sampler = circuit.uniform_sampler(42)
        m = circuit.Measurement("A", 0, sampler=sampler)

        with patch('numpy.random.RandomState') as rsclass:
            rs = MagicMock()
            rsclass.return_value = rs
            rs.random_sample = MagicMock()
            p = rs.random_sample
            p.return_value = 0.3
            sdm = MagicMock()
            sdm.peak_measurement = MagicMock(return_value=(0.06, 0.04))
            sdm.project_measurement = MagicMock()

            m.apply_to(sdm)

            sdm.project_measurement.assert_called_once_with("A", 0)

            sdm.peak_measurement = MagicMock(return_value=(0.06, 0.04))
            sdm.project_measurement = MagicMock()
            p.return_value = 0.7

            m.apply_to(sdm)

            sdm.project_measurement.assert_called_once_with("A", 1)
예제 #2
0
    def test_uniform_sampler(self):
        with patch("numpy.random.RandomState") as rsclass:
            rs = MagicMock()
            rsclass.return_value = rs
            rs.random_sample = MagicMock(return_value=0.5)

            s = circuit.uniform_sampler(seed=42)
            next(s)

            rsclass.assert_called_once_with(seed=42)

            for p0 in np.linspace(0, 1, 10):
                proj, dec, prob = s.send((p0, 1 - p0))
                assert proj == dec
                assert prob == 1
                assert proj == int(p0 < 0.5)
예제 #3
0
    def test_one_sampler_two_measurements(self):
        # Biased sampler
        s = circuit.BiasedSampler(alpha=1, readout_error=0.7)
        m1 = circuit.Measurement("A", 0, sampler=s, output_bit="O")
        m2 = circuit.Measurement("A", 0, sampler=s, output_bit="O")

        # uniform sampler
        s = circuit.uniform_sampler(seed=42)
        m1 = circuit.Measurement("A", 0, sampler=s, output_bit="O")
        m2 = circuit.Measurement("A", 0, sampler=s, output_bit="O")

        # selection sampler
        s = circuit.selection_sampler(result=1)
        m1 = circuit.Measurement("A", 0, sampler=s, output_bit="O")
        m2 = circuit.Measurement("A", 0, sampler=s, output_bit="O")

        m1, m2
예제 #4
0
def get_qubit(noise_flag=True,
              t1=np.inf,
              t2=100000,
              dephasing_axis=1e-5,
              dephasing_angle=1e-5,
              dephasing=1e-5,
              p_exc_init=0,
              p_dec_init=0,
              p_exc_fin=0,
              p_dec_fin=0,
              dephase_var=1e-2 / (2 * pi),
              msmt_time=3000,
              interval_time=1000,
              oneq_gate_time=100,
              CZ_gate_time=40,
              reset_time=100,
              sampler=None,
              seed=None,
              readout_error=0.02,
              static_flux_std=None,
              **kwargs):
    '''
    The dictionary for parameters of the DiCarlo qubits, with standard
    parameters pre-set.

    This is a bit messy right now, but has the advantage of telling
    the user which parameters they can set. Not sure how to improve
    over this.
    '''
    if sampler is None:
        if noise_flag is True:
            sampler = uniform_noisy_sampler(seed=seed,
                                            readout_error=readout_error)
        else:
            sampler = uniform_sampler(seed=seed)

    if static_flux_std is not None:
        quasistatic_flux = static_flux_std * np.random.randn()
    else:
        quasistatic_flux = None

    if noise_flag is True:

        param_dic = {
            't1': t1,
            't2': t2,
            'dephasing_axis': dephasing_axis,
            'dephasing': dephasing,
            'dephasing_angle': dephasing_angle,
            'dephase_var': dephase_var,
            'p_exc_init': p_exc_init,
            'p_dec_init': p_dec_init,
            'p_exc_fin': p_exc_fin,
            'p_dec_fin': p_dec_fin,
            'msmt_time': msmt_time,
            'interval_time': interval_time,
            'oneq_gate_time': oneq_gate_time,
            'CZ_gate_time': CZ_gate_time,
            'ISwap_gate_time': CZ_gate_time * np.sqrt(2),
            'reset_time': reset_time,
            'photons': photons,
            'alpha0': alpha0,
            'kappa': kappa,
            'chi': chi,
            'quasistatic_flux': quasistatic_flux,
            'high_frequency': high_frequency,
            'sampler': sampler
        }
    else:

        param_dic = {
            't1': np.inf,
            't2': np.inf,
            'dephasing_axis': 0,
            'dephasing': 0,
            'dephasing_angle': 0,
            'dephase_var': 0,
            'p_exc_init': 0,
            'p_dec_init': 0,
            'p_exc_fin': 0,
            'p_dec_fin': 0,
            'msmt_time': msmt_time,
            'interval_time': interval_time,
            'CZ_gate_time': CZ_gate_time,
            'ISwap_gate_time': CZ_gate_time * np.sqrt(2),
            'reset_time': reset_time,
            'photons': False,
            'quasistatic_flux': None,
            'high_frequency': False,
            'sampler': sampler
        }

    for key, val in kwargs.items():
        param_dic[key] = val

    return param_dic
예제 #5
0
def get_qubit(noise_flag=True,
              scale=1,
              t1=30000,
              t2=30000,
              dephasing_axis=1e-4,
              dephasing_angle=5e-4,
              dephasing=5e-4,
              p_exc_init=0.0,
              p_dec_init=0.005,
              p_exc_fin=0.0,
              p_dec_fin=0.015,
              residual_excitations=0.01,
              photons=False,
              alpha0=4,
              kappa=1 / 250,
              chi=1.3 * 1e-3,
              static_flux_std=None,
              high_frequency=False,
              dephase_var=1e-2/(2*pi),
              msmt_time=600,
              interval_time=150,
              oneq_gate_time=20,
              CZ_gate_time=40,
              reset_time=500,
              state=None,
              sampler=None,
              readout_error=0.005,
              **kwargs):
    """
    The dictionary for parameters of the DiCarlo qubits, with standard
    parameters pre-set.

    This is a bit messy right now, but has the advantage of telling
    the user which parameters they can set. Not sure how to improve
    over this.
    """
    if sampler is None:
        if noise_flag is True:
            sampler = uniform_noisy_sampler(state=state,
                                            readout_error=readout_error)
        else:
            readout_error = 0
            sampler = uniform_sampler(state=state)

    if static_flux_std is not None:
        quasistatic_flux = static_flux_std * np.random.randn()
    else:
        quasistatic_flux = None

    if noise_flag is True:

        param_dic = {
            't1': t1/scale,
            't2': t2/scale,
            'dephasing_axis': dephasing_axis*scale,
            'dephasing': dephasing*scale,
            'dephasing_angle': dephasing_angle*scale,
            'dephase_var': dephase_var*scale,
            'p_exc_init': p_exc_init*scale,
            'p_dec_init': p_dec_init*scale,
            'p_exc_fin': p_exc_fin*scale,
            'p_dec_fin': p_dec_fin*scale,
            'residual_excitations': residual_excitations*scale,
            'msmt_time': msmt_time,
            'interval_time': interval_time,
            'oneq_gate_time': oneq_gate_time,
            'CZ_gate_time': CZ_gate_time,
            'ISwap_gate_time': CZ_gate_time*np.sqrt(2),
            'reset_time': reset_time,
            'photons': photons,
            'alpha0': alpha0,
            'kappa': kappa,
            'chi': chi,
            'quasistatic_flux': quasistatic_flux,
            'high_frequency': high_frequency,
            'sampler': sampler,
            'readout_error': readout_error,
        }
    else:

        param_dic = {
            't1': np.inf,
            't2': np.inf,
            'dephasing_axis': 0,
            'dephasing': 0,
            'dephasing_angle': 0,
            'dephase_var': 0,
            'p_exc_init': 0,
            'p_dec_init': 0,
            'p_exc_fin': 0,
            'p_dec_fin': 0,
            'residual_excitations': 0,
            'msmt_time': msmt_time,
            'interval_time': interval_time,
            'oneq_gate_time': oneq_gate_time,
            'CZ_gate_time': CZ_gate_time,
            'ISwap_gate_time': CZ_gate_time*np.sqrt(2),
            'reset_time': reset_time,
            'photons': False,
            'quasistatic_flux': None,
            'high_frequency': False,
            'sampler': sampler,
            'readout_error': 0,
        }

    for key, val in kwargs.items():
        param_dic[key] = val

    return param_dic