Example #1
0
def test_group_experiments_greedy():
    ungrouped_tomo_expt = Experiment(
        [
            [
                ExperimentSetting(
                    _pauli_to_product_state(
                        PauliTerm.from_compact_str("(1+0j)*Z7Y8Z1Y4Z2Y5Y0X6")),
                    PauliTerm.from_compact_str("(1+0j)*Z4X8Y5X3Y7Y1"),
                )
            ],
            [ExperimentSetting(plusZ(7), sY(1))],
        ],
        program=Program(H(0), H(1), H(2)),
    )
    grouped_tomo_expt = group_settings(ungrouped_tomo_expt, method="greedy")
    expected_grouped_tomo_expt = Experiment(
        [[
            ExperimentSetting(
                TensorProductState.from_str(
                    "Z0_7 * Y0_8 * Z0_1 * Y0_4 * Z0_2 * Y0_5 * Y0_0 * X0_6"),
                PauliTerm.from_compact_str("(1+0j)*Z4X8Y5X3Y7Y1"),
            ),
            ExperimentSetting(plusZ(7), sY(1)),
        ]],
        program=Program(H(0), H(1), H(2)),
    )
    assert grouped_tomo_expt == expected_grouped_tomo_expt
Example #2
0
def test_max_tpb_overlap_2():
    expt_setting = ExperimentSetting(PauliTerm.from_compact_str('(1+0j)*Z7Y8Z1Y4Z2Y5Y0X6'),
                                     PauliTerm.from_compact_str('(1+0j)*Z4X8Y5X3Y7Y1'))
    p = Program(H(0), H(1), H(2))
    qubits = [0, 1, 2]
    tomo_expt = TomographyExperiment([expt_setting], p, qubits)
    expected_dict = {expt_setting: [expt_setting]}
    assert expected_dict == _max_tpb_overlap(tomo_expt)
Example #3
0
def test_max_tpb_overlap_3():
    # add another ExperimentSetting to the above
    expt_setting = ExperimentSetting(PauliTerm.from_compact_str('(1+0j)*Z7Y8Z1Y4Z2Y5Y0X6'),
                                     PauliTerm.from_compact_str('(1+0j)*Z4X8Y5X3Y7Y1'))
    expt_setting2 = ExperimentSetting(sZ(7), sY(1))
    p = Program(H(0), H(1), H(2))
    qubits = [0, 1, 2]
    tomo_expt2 = TomographyExperiment([expt_setting, expt_setting2], p, qubits)
    expected_dict2 = {expt_setting: [expt_setting, expt_setting2]}
    assert expected_dict2 == _max_tpb_overlap(tomo_expt2)
Example #4
0
def test_max_tpb_overlap_2():
    expt_setting = ExperimentSetting(
        _pauli_to_product_state(
            PauliTerm.from_compact_str("(1+0j)*Z7Y8Z1Y4Z2Y5Y0X6")),
        PauliTerm.from_compact_str("(1+0j)*Z4X8Y5X3Y7Y1"),
    )
    p = Program(H(0), H(1), H(2))
    tomo_expt = Experiment([expt_setting], p)
    expected_dict = {expt_setting: [expt_setting]}
    assert expected_dict == _max_tpb_overlap(tomo_expt)
Example #5
0
def test_pauli_term_from_str():
    # tests that should _not_ fail are in test_pauli_sum_from_str
    with pytest.raises(ValueError):
        PauliTerm.from_compact_str("X0")
    with pytest.raises(ValueError):
        PauliTerm.from_compact_str("10")
    with pytest.raises(ValueError):
        PauliTerm.from_compact_str("1.0X0")
    with pytest.raises(ValueError):
        PauliTerm.from_compact_str("(1.0+9i)*X0")
    with pytest.raises(ValueError):
        PauliTerm.from_compact_str("(1.0+0j)*A0")
Example #6
0
def test_max_tpb_overlap_3():
    # add another ExperimentSetting to the above
    expt_setting = ExperimentSetting(
        _pauli_to_product_state(
            PauliTerm.from_compact_str("(1+0j)*Z7Y8Z1Y4Z2Y5Y0X6")),
        PauliTerm.from_compact_str("(1+0j)*Z4X8Y5X3Y7Y1"),
    )
    expt_setting2 = ExperimentSetting(plusZ(7), sY(1))
    p = Program(H(0), H(1), H(2))
    tomo_expt2 = Experiment([expt_setting, expt_setting2], p)
    expected_dict2 = {expt_setting: [expt_setting, expt_setting2]}
    assert expected_dict2 == _max_tpb_overlap(tomo_expt2)
Example #7
0
 def from_str(cls, s: str) -> "ExperimentSetting":
     """The opposite of str(expt)"""
     instr, outstr = s.split("→")
     return ExperimentSetting(
         in_state=TensorProductState.from_str(instr),
         out_operator=PauliTerm.from_compact_str(outstr),
     )
Example #8
0
def test_group_experiments_greedy():
    ungrouped_tomo_expt = TomographyExperiment(
        [[ExperimentSetting(PauliTerm.from_compact_str('(1+0j)*Z7Y8Z1Y4Z2Y5Y0X6'),
                            PauliTerm.from_compact_str('(1+0j)*Z4X8Y5X3Y7Y1'))],
         [ExperimentSetting(sZ(7), sY(1))]], program=Program(H(0), H(1), H(2)),
        qubits=[0, 1, 2])
    grouped_tomo_expt = group_experiments(ungrouped_tomo_expt, method='greedy')
    expected_grouped_tomo_expt = TomographyExperiment(
        [[
            ExperimentSetting(TensorProductState.from_str('Z0_7 * Y0_8 * Z0_1 * Y0_4 * '
                                                          'Z0_2 * Y0_5 * Y0_0 * X0_6'),
                              PauliTerm.from_compact_str('(1+0j)*Z4X8Y5X3Y7Y1')),
            ExperimentSetting(plusZ(7), sY(1))
        ]],
        program=Program(H(0), H(1), H(2)),
        qubits=[0, 1, 2])
    assert grouped_tomo_expt == expected_grouped_tomo_expt
Example #9
0
def test_group_experiments_greedy():
    ungrouped_tomo_expt = TomographyExperiment([[
        ExperimentSetting(
            PauliTerm.from_compact_str('(1+0j)*Z7Y8Z1Y4Z2Y5Y0X6'),
            PauliTerm.from_compact_str('(1+0j)*Z4X8Y5X3Y7Y1'))
    ], [ExperimentSetting(sZ(7), sY(1))]],
                                               program=Program(
                                                   H(0), H(1), H(2)),
                                               qubits=[0, 1, 2])
    grouped_tomo_expt = group_experiments_greedy(ungrouped_tomo_expt)
    expected_grouped_tomo_expt = TomographyExperiment([[
        ExperimentSetting(
            PauliTerm.from_compact_str('(1+0j)*Z7Y8Z1Y4Z2Y5Y0X6'),
            PauliTerm.from_compact_str('(1+0j)*Z4X8Y5X3Y7Y1')),
        ExperimentSetting(sZ(7), sY(1))
    ]],
                                                      program=Program(
                                                          H(0), H(1), H(2)),
                                                      qubits=[0, 1, 2])
    assert grouped_tomo_expt == expected_grouped_tomo_expt
 def from_str(cls, s: str):
     """The opposite of str(expt)"""
     instr, outstr = s.split('→')
     return ExperimentSetting(in_state=TensorProductState.from_str(instr),
                              observable=PauliTerm.from_compact_str(outstr))
Example #11
0
def test_from_str():
    with pytest.raises(ValueError):
        PauliTerm.from_compact_str('1*A0→1*Z0')
Example #12
0
 def from_str(cls, s: str):
     """The opposite of str(expt)"""
     instr, outstr = s.split('→')
     return ExperimentSetting(
         in_operator=PauliTerm.from_compact_str(instr),
         out_operator=PauliTerm.from_compact_str(outstr))