当前位置: 首页>>代码示例>>Python>>正文


Python paulis.sI方法代码示例

本文整理汇总了Python中pyquil.paulis.sI方法的典型用法代码示例。如果您正苦于以下问题:Python paulis.sI方法的具体用法?Python paulis.sI怎么用?Python paulis.sI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyquil.paulis的用法示例。


在下文中一共展示了paulis.sI方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _single_projector_generator

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def _single_projector_generator(ket_op, bra_op, index):
    """
    Generate the pauli sum terms corresponding to |ket_op><brak_op|

    :param ket_op: single qubit computational basis state
    :param bra_op: single qubit computational basis state
    :param index: qubit index to assign to the projector
    :return: pauli sum of single qubit projection operator
    :rtype: PauliSum
    """
    if not isinstance(ket_op, int):
        raise TypeError("ket_op needs to be an integer")
    if not isinstance(bra_op, int):
        raise TypeError("ket_op needs to be an integer")
    if ket_op not in [0, 1] or bra_op not in [0, 1]:
        raise ValueError("bra and ket op needs to be either 0 or 1")

    if ket_op == 0 and bra_op == 0:
        return 0.5 * (sZ(index) + sI(index))
    elif ket_op == 0 and bra_op == 1:
        return 0.5 * (sX(index) + 1j * sY(index))
    elif ket_op == 1 and bra_op == 0:
        return 0.5 * (sX(index) - 1j * sY(index))
    else:
        return 0.5 * (sI(index) - sZ(index)) 
开发者ID:rigetti,项目名称:grove,代码行数:27,代码来源:amplitude_measurement.py

示例2: density

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def density(self, pyquil_program):
        """
        Run program and compute the density matrix

        Loads and checks program if all gates are within the stabilizer set.
        Then executes program and returns the final density matrix for the
        stabilizer

        :param Program pyquil_program: a pyquil Program containing only
                                       CNOT-H-S-MEASUREMENT operations
        :return:
        """
        self.load_program(pyquil_program)
        self.tableau = self._n_qubit_tableau(self.num_qubits)
        self.kernel()
        stabilizers = binary_stabilizer_to_pauli_stabilizer(self.stabilizer_tableau())
        pauli_ops = reduce(lambda x, y: x * y, [0.5 * (sI(0) + b) for b in stabilizers])
        return tensor_up(pauli_ops, self.num_qubits) 
开发者ID:rigetti,项目名称:reference-qvm,代码行数:20,代码来源:qvm_stabilizer.py

示例3: test_measure_observables

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def test_measure_observables(forest):
    expts = [
        ExperimentSetting(TensorProductState(), o1 * o2)
        for o1, o2 in itertools.product([sI(0), sX(0), sY(0), sZ(0)], [sI(1), sX(1), sY(1), sZ(1)])
    ]
    suite = Experiment(expts, program=Program(X(0), CNOT(0, 1)))
    assert len(suite) == 4 * 4
    gsuite = group_experiments(suite)
    assert len(gsuite) == 3 * 3  # can get all the terms with I for free in this case

    qc = get_qc("2q-qvm")
    for res in measure_observables(qc, gsuite, n_shots=2000):
        if res.setting.out_operator in [sI(), sZ(0), sZ(1), sZ(0) * sZ(1)]:
            assert np.abs(res.expectation) > 0.9
        else:
            assert np.abs(res.expectation) < 0.1 
开发者ID:rigetti,项目名称:pyquil,代码行数:18,代码来源:test_operator_estimation.py

示例4: test_measure_observables_many_progs

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def test_measure_observables_many_progs(forest):
    expts = [
        ExperimentSetting(TensorProductState(), o1 * o2)
        for o1, o2 in itertools.product([sI(0), sX(0), sY(0), sZ(0)], [sI(1), sX(1), sY(1), sZ(1)])
    ]

    qc = get_qc("2q-qvm")
    qc.qam.random_seed = 0
    for prog in _random_2q_programs():
        suite = Experiment(expts, program=prog)
        assert len(suite) == 4 * 4
        gsuite = group_experiments(suite)
        assert len(gsuite) == 3 * 3  # can get all the terms with I for free in this case

        wfn = WavefunctionSimulator()
        wfn_exps = {}
        for expt in expts:
            wfn_exps[expt] = wfn.expectation(gsuite.program, PauliSum([expt.out_operator]))

        for res in measure_observables(qc, gsuite):
            np.testing.assert_allclose(wfn_exps[res.setting], res.expectation, atol=2e-2) 
开发者ID:rigetti,项目名称:pyquil,代码行数:23,代码来源:test_operator_estimation.py

示例5: test_measure_observables_symmetrize

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def test_measure_observables_symmetrize(forest):
    """
    Symmetrization alone should not change the outcome on the QVM
    """
    expts = [
        ExperimentSetting(TensorProductState(), o1 * o2)
        for o1, o2 in itertools.product([sI(0), sX(0), sY(0), sZ(0)], [sI(1), sX(1), sY(1), sZ(1)])
    ]
    suite = Experiment(expts, program=Program(X(0), CNOT(0, 1)))
    assert len(suite) == 4 * 4
    gsuite = group_experiments(suite)
    assert len(gsuite) == 3 * 3  # can get all the terms with I for free in this case

    qc = get_qc("2q-qvm")
    for res in measure_observables(qc, gsuite, calibrate_readout=None):
        if res.setting.out_operator in [sI(), sZ(0), sZ(1), sZ(0) * sZ(1)]:
            assert np.abs(res.expectation) > 0.9
        else:
            assert np.abs(res.expectation) < 0.1 
开发者ID:rigetti,项目名称:pyquil,代码行数:21,代码来源:test_operator_estimation.py

示例6: test_measure_observables_symmetrize_calibrate

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def test_measure_observables_symmetrize_calibrate(forest):
    """
    Symmetrization + calibration should not change the outcome on the QVM
    """
    expts = [
        ExperimentSetting(TensorProductState(), o1 * o2)
        for o1, o2 in itertools.product([sI(0), sX(0), sY(0), sZ(0)], [sI(1), sX(1), sY(1), sZ(1)])
    ]
    suite = Experiment(expts, program=Program(X(0), CNOT(0, 1)))
    assert len(suite) == 4 * 4
    gsuite = group_experiments(suite)
    assert len(gsuite) == 3 * 3  # can get all the terms with I for free in this case

    qc = get_qc("2q-qvm")
    for res in measure_observables(qc, gsuite):
        if res.setting.out_operator in [sI(), sZ(0), sZ(1), sZ(0) * sZ(1)]:
            assert np.abs(res.expectation) > 0.9
        else:
            assert np.abs(res.expectation) < 0.1 
开发者ID:rigetti,项目名称:pyquil,代码行数:21,代码来源:test_operator_estimation.py

示例7: _max_weight_operator

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def _max_weight_operator(ops: Iterable[PauliTerm]) -> Union[None, PauliTerm]:
    """Construct a PauliTerm operator by taking the non-identity single-qubit operator at each
    qubit position.

    This function will return ``None`` if the input operators do not share a natural tensor
    product basis.

    For example, the max_weight_operator of ["XI", "IZ"] is "XZ". Asking for the max weight
    operator of something like ["XI", "ZI"] will return None.
    """
    mapping = dict()  # type: Dict[int, str]
    for op in ops:
        for idx, op_str in op:
            assert isinstance(idx, int)
            if idx in mapping:
                if mapping[idx] != op_str:
                    return None
            else:
                mapping[idx] = op_str
    op = functools.reduce(mul, (PauliTerm(op, q) for q, op in mapping.items()), sI())
    return op 
开发者ID:rigetti,项目名称:pyquil,代码行数:23,代码来源:_group.py

示例8: test_tomo_experiment_pre_grouped

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def test_tomo_experiment_pre_grouped():
    expts = [
        [
            ExperimentSetting(TensorProductState(), sX(0) * sI(1)),
            ExperimentSetting(TensorProductState(), sI(0) * sX(1)),
        ],
        [
            ExperimentSetting(TensorProductState(), sZ(0) * sI(1)),
            ExperimentSetting(TensorProductState(), sI(0) * sZ(1)),
        ],
    ]

    suite = Experiment(settings=expts, program=Program(X(0), Y(1)))
    assert len(suite) == 2  # number of groups
    for es1, es2 in zip(expts, suite):
        for e1, e2 in zip(es1, es2):
            assert e1 == e2
    prog_str = str(suite).splitlines()[3:5]
    assert prog_str == EXPERIMENT_REPR.splitlines()[4:6] 
开发者ID:rigetti,项目名称:pyquil,代码行数:21,代码来源:test_main.py

示例9: test_experiment_deser

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def test_experiment_deser(tmpdir):
    expts = [
        [
            ExperimentSetting(TensorProductState(), sX(0) * sI(1)),
            ExperimentSetting(TensorProductState(), sI(0) * sX(1)),
        ],
        [
            ExperimentSetting(TensorProductState(), sZ(0) * sI(1)),
            ExperimentSetting(TensorProductState(), sI(0) * sZ(1)),
        ],
    ]

    suite = Experiment(settings=expts, program=Program(X(0), Y(1)))
    to_json(f"{tmpdir}/suite.json", suite)
    suite2 = read_json(f"{tmpdir}/suite.json")
    assert suite == suite2 
开发者ID:rigetti,项目名称:pyquil,代码行数:18,代码来源:test_main.py

示例10: in_operator

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def in_operator(self) -> PauliTerm:
        warnings.warn(
            "ExperimentSetting.in_operator is deprecated in favor of in_state", DeprecationWarning
        )

        # Backwards compat
        pt = sI()
        for oneq_state in self.in_state.states:
            if oneq_state.label not in ["X", "Y", "Z"]:
                raise ValueError(f"Can't shim {oneq_state.label} into a pauli term. Use in_state.")
            if oneq_state.index != 0:
                raise ValueError(f"Can't shim {oneq_state} into a pauli term. Use in_state.")

            new_pt = pt * PauliTerm(op=oneq_state.label, index=oneq_state.qubit)
            pt = cast(PauliTerm, new_pt)

        return pt 
开发者ID:rigetti,项目名称:pyquil,代码行数:19,代码来源:_setting.py

示例11: _max_weight_operator

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def _max_weight_operator(ops: Iterable[PauliTerm]) -> Union[None, PauliTerm]:
    """
    Construct a PauliTerm operator by taking the non-identity single-qubit operator at each
    qubit position.

    This function will return ``None`` if the input operators do not share a natural tensor
    product basis.
    For example, the max_weight_operator of ["XI", "IZ"] is "XZ". Asking for the max weight
    operator of something like ["XI", "ZI"] will return None.
    """
    mapping = dict()  # type: Dict[int, str]
    for op in ops:
        for idx, op_str in op:
            if idx in mapping:
                if mapping[idx] != op_str:
                    return None
            else:
                mapping[idx] = op_str
    op = functools.reduce(mul, (PauliTerm(op, q) for q, op in mapping.items()), sI())
    return op 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:22,代码来源:observable_estimation.py

示例12: test_R_operator_fixed_point_2_qubit

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def test_R_operator_fixed_point_2_qubit():
    # Check fixed point of operator. See Eq. 5 in Řeháček et al., PRA 75, 042108 (2007).
    qubits = [0, 1]
    id_setting = ExperimentSetting(in_state=zeros_state(qubits), observable=sI(qubits[0])*sI(
        qubits[1]))
    zz_setting = ExperimentSetting(in_state=zeros_state(qubits), observable=sZ(qubits[0])*sI(
        qubits[1]))

    id_result = ExperimentResult(setting=id_setting, expectation=1, total_counts=1)
    zzplus_result = ExperimentResult(setting=zz_setting, expectation=1, total_counts=1)

    zz_results = [id_result, zzplus_result]

    # Z basis test
    r = _R(P00, zz_results, qubits)
    actual = r @ P00 @ r
    np.testing.assert_allclose(actual, P00, atol=1e-12) 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:19,代码来源:test_state_tomography.py

示例13: test_tomo_experiment_pre_grouped

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def test_tomo_experiment_pre_grouped():
    expts = [
        [ExperimentSetting(TensorProductState(), sX(0) * sI(1)), ExperimentSetting(TensorProductState(), sI(0) * sX(1))],
        [ExperimentSetting(TensorProductState(), sZ(0) * sI(1)), ExperimentSetting(TensorProductState(), sI(0) * sZ(1))],
    ]

    suite = ObservablesExperiment(
        settings=expts,
        program=Program(X(0), Y(1))
    )
    assert len(suite) == 2  # number of groups
    for es1, es2 in zip(expts, suite):
        for e1, e2 in zip(es1, es2):
            assert e1 == e2
    prog_str = str(suite).splitlines()[0]
    assert prog_str == 'X 0; Y 1' 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:18,代码来源:test_observable_estimation.py

示例14: test_estimate_observables

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def test_estimate_observables():
    expts = [
        ExperimentSetting(TensorProductState(), o1 * o2)
        for o1, o2 in itertools.product([sI(0), sX(0), sY(0), sZ(0)], [sI(1), sX(1), sY(1), sZ(1)])
    ]
    suite = ObservablesExperiment(expts, program=Program(X(0), CNOT(0, 1)))
    assert len(suite) == 4 * 4
    gsuite = group_settings(suite)
    assert len(gsuite) == 3 * 3  # can get all the terms with I for free in this case

    qc = get_qc('2q-qvm')
    qc.qam.random_seed = 1
    for res in estimate_observables(qc, gsuite, num_shots=1000):
        if res.setting.observable in [sI(), sZ(0), sZ(1), sZ(0) * sZ(1)]:
            assert np.abs(res.expectation) > 0.9
        else:
            assert np.abs(res.expectation) < 0.1 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:19,代码来源:test_observable_estimation.py

示例15: test_estimate_observables_many_progs

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sI [as 别名]
def test_estimate_observables_many_progs(forest):
    # for "random programs" calculate wfn.expectation see if operator estimation gets it right
    expts = [
        ExperimentSetting(TensorProductState(), o1 * o2)
        for o1, o2 in itertools.product([sI(0), sX(0), sY(0), sZ(0)], [sI(1), sX(1), sY(1), sZ(1)])
    ]

    qc = get_qc('2q-qvm')
    qc.qam.random_seed = 1
    qc.qam.random_seed = 0
    # default n_progs in _random_2q_programs is now three
    for prog in _random_2q_programs():
        suite = ObservablesExperiment(expts, program=prog)
        assert len(suite) == 4 * 4
        gsuite = group_settings(suite)
        assert len(gsuite) == 3 * 3  # can get all the terms with I for free in this case

        wfn = WavefunctionSimulator()
        wfn_exps = {}
        for expt in expts:
            wfn_exps[expt] = wfn.expectation(gsuite.program, PauliSum([expt.observable]))

        for res in estimate_observables(qc, gsuite, num_shots=1000):
            np.testing.assert_allclose(wfn_exps[res.setting], res.expectation, atol=3*res.std_err) 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:26,代码来源:test_observable_estimation.py


注:本文中的pyquil.paulis.sI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。