コード例 #1
0
ファイル: test_c2_calibration.py プロジェクト: q-optimize/c3
def test_calibration_cmaes() -> None:
    """Create a C2 style Optimizer object and run calibration
    with a mock_ORBIT function. Check if the goal in the optimizer
    correctly reflects the constant goal returned by the mock_ORBIT.
    """
    with open(OPT_CONFIG_FILE_NAME, "r") as cfg_file:
        cfg = hjson.load(cfg_file)

    pmap = ParameterMap()
    pmap.read_config(cfg.pop("instructions"))
    pmap.set_opt_map(
        [[tuple(par) for par in pset] for pset in cfg.pop("gateset_opt_map")]
    )

    exp = Experiment(pmap=pmap)

    algo_options = cfg.pop("options")
    run_name = cfg.pop("run_name")

    opt = Calibration(
        dir_path=LOGDIR,
        run_name=run_name,
        eval_func=mock_ORBIT,
        pmap=pmap,
        exp_right=exp,
        algorithm=algorithms.cmaes,
        options=algo_options,
    )

    opt.run()
    assert opt.current_best_goal == RESULT_VAL
コード例 #2
0
ファイル: conftest.py プロジェクト: q-optimize/c3
def get_xtalk_pmap() -> ParameterMap:
    xtalk = Crosstalk(
        name="crosstalk",
        channels=["TC1", "TC2"],
        crosstalk_matrix=Quantity(
            value=[[1, 0], [0, 1]],
            min_val=[[0, 0], [0, 0]],
            max_val=[[1, 1], [1, 1]],
            unit="",
        ),
    )

    gen = Generator(devices={"crosstalk": xtalk})
    pmap = ParameterMap(generator=gen)
    pmap.set_opt_map([[["crosstalk", "crosstalk_matrix"]]])
    return pmap
コード例 #3
0
ファイル: test_two_qubits.py プロジェクト: superplay1/c3
gateset_opt_map = [
    [
        ("X90p:Id", "d1", "gauss", "amp"),
    ],
    [
        ("X90p:Id", "d1", "gauss", "freq_offset"),
    ],
    [
        ("X90p:Id", "d1", "gauss", "xy_angle"),
    ],
    [
        ("X90p:Id", "d1", "gauss", "delta"),
    ],
]

pmap.set_opt_map(gateset_opt_map)

opt = C1(
    dir_path="/tmp/c3log/",
    fid_func=fidelities.average_infid_set,
    fid_subspace=["Q1", "Q2"],
    pmap=pmap,
    algorithm=algorithms.tf_sgd,
    options={"maxfun": 2},
    run_name="better_X90_tf_sgd",
)

opt.set_exp(exp)

with open("test/two_qubit_data.pickle", "rb") as filename:
    test_data = pickle.load(filename)
コード例 #4
0
ファイル: test_parameter_map.py プロジェクト: superplay1/c3
def setup_pmap() -> ParameterMap:
    t_final = 7e-9  # Time for single qubit gates
    sideband = 50e6
    lo_freq = 5e9 + sideband

    # ### MAKE GATESET
    gauss_params_single = {
        'amp':
        Quantity(value=0.45, min_val=0.4, max_val=0.6, unit="V"),
        't_final':
        Quantity(value=t_final,
                 min_val=0.5 * t_final,
                 max_val=1.5 * t_final,
                 unit="s"),
        'sigma':
        Quantity(value=t_final / 4,
                 min_val=t_final / 8,
                 max_val=t_final / 2,
                 unit="s"),
        'xy_angle':
        Quantity(value=0.0,
                 min_val=-0.5 * np.pi,
                 max_val=2.5 * np.pi,
                 unit='rad'),
        'freq_offset':
        Quantity(value=-sideband - 0.5e6,
                 min_val=-53 * 1e6,
                 max_val=-47 * 1e6,
                 unit='Hz 2pi'),
        'delta':
        Quantity(value=-1, min_val=-5, max_val=3, unit="")
    }

    gauss_env_single = Envelope(name="gauss",
                                desc="Gaussian comp for single-qubit gates",
                                params=gauss_params_single,
                                shape=envelopes.gaussian_nonorm)
    nodrive_env = Envelope(name="no_drive",
                           params={
                               't_final':
                               Quantity(value=t_final,
                                        min_val=0.5 * t_final,
                                        max_val=1.5 * t_final,
                                        unit="s")
                           },
                           shape=envelopes.no_drive)
    carrier_parameters = {
        'freq':
        Quantity(value=lo_freq, min_val=4.5e9, max_val=6e9, unit='Hz 2pi'),
        'framechange':
        Quantity(value=0.0, min_val=-np.pi, max_val=3 * np.pi, unit='rad')
    }
    carr = Carrier(name="carrier",
                   desc="Frequency of the local oscillator",
                   params=carrier_parameters)

    X90p = Instruction(name="X90p",
                       t_start=0.0,
                       t_end=t_final,
                       channels=["d1"])
    QId = Instruction(name="Id", t_start=0.0, t_end=t_final, channels=["d1"])

    X90p.add_component(gauss_env_single, "d1")
    X90p.add_component(carr, "d1")
    QId.add_component(nodrive_env, "d1")
    QId.add_component(copy.deepcopy(carr), "d1")
    QId.comps['d1']['carrier'].params['framechange'].set_value(
        (-sideband * t_final) % (2 * np.pi))
    Y90p = copy.deepcopy(X90p)
    Y90p.name = "Y90p"
    X90m = copy.deepcopy(X90p)
    X90m.name = "X90m"
    Y90m = copy.deepcopy(X90p)
    Y90m.name = "Y90m"
    Y90p.comps['d1']['gauss'].params['xy_angle'].set_value(0.5 * np.pi)
    X90m.comps['d1']['gauss'].params['xy_angle'].set_value(np.pi)
    Y90m.comps['d1']['gauss'].params['xy_angle'].set_value(1.5 * np.pi)

    parameter_map = ParameterMap(instructions=[QId, X90p, Y90p, X90m, Y90m])

    gateset_opt_map = [[("X90p", "d1", "gauss", "amp"),
                        ("Y90p", "d1", "gauss", "amp"),
                        ("X90m", "d1", "gauss", "amp"),
                        ("Y90m", "d1", "gauss", "amp")],
                       [("X90p", "d1", "gauss", "delta"),
                        ("Y90p", "d1", "gauss", "delta"),
                        ("X90m", "d1", "gauss", "delta"),
                        ("Y90m", "d1", "gauss", "delta")],
                       [("X90p", "d1", "gauss", "freq_offset"),
                        ("Y90p", "d1", "gauss", "freq_offset"),
                        ("X90m", "d1", "gauss", "freq_offset"),
                        ("Y90m", "d1", "gauss", "freq_offset")],
                       [("Id", "d1", "carrier", "framechange")]]

    parameter_map.set_opt_map(gateset_opt_map)

    return parameter_map
コード例 #5
0
ファイル: test_parameter_map.py プロジェクト: flo-maier/c3
def setup_pmap() -> ParameterMap:
    t_final = 7e-9  # Time for single qubit gates
    sideband = 50e6
    lo_freq = 5e9 + sideband

    # ### MAKE GATESET
    gauss_params_single = {
        "amp":
        Quantity(value=0.45, min_val=0.4, max_val=0.6, unit="V"),
        "t_final":
        Quantity(value=t_final,
                 min_val=0.5 * t_final,
                 max_val=1.5 * t_final,
                 unit="s"),
        "sigma":
        Quantity(value=t_final / 4,
                 min_val=t_final / 8,
                 max_val=t_final / 2,
                 unit="s"),
        "xy_angle":
        Quantity(value=0.0,
                 min_val=-0.5 * np.pi,
                 max_val=2.5 * np.pi,
                 unit="rad"),
        "freq_offset":
        Quantity(value=-sideband - 0.5e6,
                 min_val=-53 * 1e6,
                 max_val=-47 * 1e6,
                 unit="Hz 2pi"),
        "delta":
        Quantity(value=-1, min_val=-5, max_val=3, unit=""),
    }

    gauss_env_single = Envelope(
        name="gauss",
        desc="Gaussian comp for single-qubit gates",
        params=gauss_params_single,
        shape=envelopes.gaussian_nonorm,
    )
    nodrive_env = Envelope(
        name="no_drive",
        params={
            "t_final":
            Quantity(value=t_final,
                     min_val=0.5 * t_final,
                     max_val=1.5 * t_final,
                     unit="s")
        },
        shape=envelopes.no_drive,
    )
    carrier_parameters = {
        "freq":
        Quantity(value=lo_freq, min_val=4.5e9, max_val=6e9, unit="Hz 2pi"),
        "framechange":
        Quantity(value=0.0, min_val=-np.pi, max_val=3 * np.pi, unit="rad"),
    }
    carr = Carrier(
        name="carrier",
        desc="Frequency of the local oscillator",
        params=carrier_parameters,
    )

    RX90p = Instruction(name="RX90p",
                        t_start=0.0,
                        t_end=t_final,
                        channels=["d1"])
    QId = Instruction(name="Id", t_start=0.0, t_end=t_final, channels=["d1"])

    RX90p.add_component(gauss_env_single, "d1")
    RX90p.add_component(carr, "d1")
    QId.add_component(nodrive_env, "d1")
    QId.add_component(copy.deepcopy(carr), "d1")
    QId.comps["d1"]["carrier"].params["framechange"].set_value(
        (-sideband * t_final) % (2 * np.pi))
    RY90p = copy.deepcopy(RX90p)
    RY90p.name = "RY90p"
    RX90m = copy.deepcopy(RX90p)
    RX90m.name = "RX90m"
    RY90m = copy.deepcopy(RX90p)
    RY90m.name = "RY90m"
    RY90p.comps["d1"]["gauss"].params["xy_angle"].set_value(0.5 * np.pi)
    RX90m.comps["d1"]["gauss"].params["xy_angle"].set_value(np.pi)
    RY90m.comps["d1"]["gauss"].params["xy_angle"].set_value(1.5 * np.pi)

    parameter_map = ParameterMap(
        instructions=[QId, RX90p, RY90p, RX90m, RY90m])

    gateset_opt_map = [
        [
            ("RX90p", "d1", "gauss", "amp"),
            ("RY90p", "d1", "gauss", "amp"),
            ("RX90m", "d1", "gauss", "amp"),
            ("RY90m", "d1", "gauss", "amp"),
        ],
        [
            ("RX90p", "d1", "gauss", "delta"),
            ("RY90p", "d1", "gauss", "delta"),
            ("RX90m", "d1", "gauss", "delta"),
            ("RY90m", "d1", "gauss", "delta"),
        ],
        [
            ("RX90p", "d1", "gauss", "freq_offset"),
            ("RY90p", "d1", "gauss", "freq_offset"),
            ("RX90m", "d1", "gauss", "freq_offset"),
            ("RY90m", "d1", "gauss", "freq_offset"),
        ],
        [("Id", "d1", "carrier", "framechange")],
    ]

    parameter_map.set_opt_map(gateset_opt_map)

    return parameter_map