Пример #1
0
def test_setting_no_in():
    out_ops = _generate_random_paulis(n_qubits=4, n_terms=7)
    for oop in out_ops:
        expt = ExperimentSetting(zeros_state(oop.get_qubits()), oop)
        expt2 = ExperimentSetting.from_str(str(expt))
        assert expt == expt2
        assert expt2.in_operator == functools.reduce(mul, [sZ(q) for q in oop.get_qubits()], sI())
        assert expt2.out_operator == oop
Пример #2
0
def test_setting_no_in_back_compat():
    out_ops = _generate_random_paulis(n_qubits=4, n_terms=7)
    for oop in out_ops:
        expt = ExperimentSetting(TensorProductState(), oop)
        expt2 = ExperimentSetting.from_str(str(expt))
        assert expt == expt2
        assert expt2.in_operator == sI()
        assert expt2.out_operator == oop
Пример #3
0
def test_experiment_setting():
    in_states = _generate_random_states(n_qubits=4, n_terms=7)
    out_ops = _generate_random_paulis(n_qubits=4, n_terms=7)
    for ist, oop in zip(in_states, out_ops):
        expt = ExperimentSetting(ist, oop)
        assert str(expt) == expt.serializable()
        expt2 = ExperimentSetting.from_str(str(expt))
        assert expt == expt2
        assert expt2.in_state == ist
        assert expt2.out_operator == oop
Пример #4
0
def _operator_object_hook(obj: Mapping[str, Any]) -> Union[Mapping[str, Any], Experiment]:
    if "type" in obj and obj["type"] in ["Experiment", "TomographyExperiment"]:
        # I bet this doesn't work for grouped experiment settings
        settings = [[ExperimentSetting.from_str(s) for s in stt] for stt in obj["settings"]]
        p = Program(obj["program"])
        p.wrap_in_numshots_loop(obj["shots"])
        ex = Experiment(settings=settings, program=p, symmetrization=obj["symmetrization"])
        ex.reset = obj["reset"]
        return ex
    return obj
Пример #5
0
def _operator_object_hook(obj):
    if 'type' in obj and obj['type'] == 'TomographyExperiment':
        # I bet this doesn't work for grouped experiment settings
        settings = [[ExperimentSetting.from_str(s) for s in stt]
                    for stt in obj['settings']]
        p = Program(obj['program'])
        p.wrap_in_numshots_loop(obj['shots'])
        ex = TomographyExperiment(settings=settings,
                                  program=p,
                                  symmetrization=obj['symmetrization'])
        ex.reset = obj['reset']
        return ex
    return obj