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


Python paulis.sZ方法代码示例

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


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

示例1: _single_projector_generator

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [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: test_imaginary_removal

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [as 别名]
def test_imaginary_removal():
    """
    remove terms with imaginary coefficients from a pauli sum
    """
    test_term = 0.25 * sX(1) * sZ(2) * sX(3) + 0.25j * sX(1) * sZ(2) * sY(3)
    test_term += -0.25j * sY(1) * sZ(2) * sX(3) + 0.25 * sY(1) * sZ(2) * sY(3)
    true_term = 0.25 * sX(1) * sZ(2) * sX(3) + 0.25 * sY(1) * sZ(2) * sY(3)
    assert remove_imaginary_terms(test_term) == true_term

    test_term = (0.25 + 1j) * sX(0) * sZ(2) + 1j * sZ(2)
    # is_identity in pyquil apparently thinks zero is identity
    assert remove_imaginary_terms(test_term) == 0.25 * sX(0) * sZ(2)

    test_term = 0.25 * sX(0) * sZ(2) + 1j * sZ(2)
    assert remove_imaginary_terms(test_term) == PauliSum([0.25 * sX(0) * sZ(2)])

    with pytest.raises(TypeError):
        remove_imaginary_terms(5)

    with pytest.raises(TypeError):
        remove_imaginary_terms(sX(0)) 
开发者ID:rigetti,项目名称:grove,代码行数:23,代码来源:test_estimation.py

示例3: test_projector_generator

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [as 别名]
def test_projector_generator():
    """
    Test if we are getting accurate projectors--multiqubit case
    """
    true_zero_projector = 0.5 * (sZ(0) + sI(0))
    zero_projector = projector_generator([0], [0])
    assert true_zero_projector == zero_projector

    one_projector = projector_generator([1], [1])
    true_one_projector = 0.5 * (sI(0) - sZ(0))
    assert true_one_projector == one_projector

    lowering_projector = projector_generator([0], [1])
    true_lowering_projector = 0.5 * (sX(0) + 1j * sY(0))
    assert true_lowering_projector == lowering_projector

    raising_projector = projector_generator([1], [0])
    true_raising_projector = 0.5 * (sX(0) - 1j * sY(0))
    assert true_raising_projector == raising_projector 
开发者ID:rigetti,项目名称:grove,代码行数:21,代码来源:test_amplitude_measurement.py

示例4: binary_stabilizer_to_pauli_stabilizer

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [as 别名]
def binary_stabilizer_to_pauli_stabilizer(stabilizer_tableau):
    """
    Convert a stabilizer tableau to a list of PauliTerms

    :param stabilizer_tableau:  Stabilizer tableau to turn into pauli terms
    :return: a list of PauliTerms representing the tableau
    :rytpe: List of PauliTerms
    """
    stabilizer_list = []
    num_qubits = (stabilizer_tableau.shape[1] - 1) // 2
    for nn in range(stabilizer_tableau.shape[0]):  # iterate through the rows
        stabilizer_element = []
        for ii in range(num_qubits):
            if stabilizer_tableau[nn, ii] == 1 and stabilizer_tableau[nn, ii + num_qubits] == 0:
                stabilizer_element.append(sX(ii))
            elif stabilizer_tableau[nn, ii] == 0 and stabilizer_tableau[nn, ii + num_qubits] == 1:
                stabilizer_element.append(sZ(ii))
            elif stabilizer_tableau[nn, ii] == 1 and stabilizer_tableau[nn, ii + num_qubits] == 1:
                stabilizer_element.append(sY(ii))

        stabilizer_term = reduce(lambda x, y: x * y, stabilizer_element) * ((-1) ** stabilizer_tableau[nn, -1])
        stabilizer_list.append(stabilizer_term)
    return stabilizer_list 
开发者ID:rigetti,项目名称:reference-qvm,代码行数:25,代码来源:stabilizer_utils.py

示例5: test_compute_action_Z

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [as 别名]
def test_compute_action_Z():
    """
    Action of Pauli operators on state
    """
    comp_basis_state = [0, 0, 0, 0]
    for ii in range(4):
        pauli_term = sZ(ii)
        new_basis_state, coeff = compute_action(comp_basis_state, pauli_term,
                                            len(comp_basis_state))
        # abuse of comparisons in python
        true_basis_state = comp_basis_state.copy()
        true_basis_state[ii] = true_basis_state[ii]
        assert new_basis_state == true_basis_state
        assert np.isclose(coeff, 1)

    comp_basis_state = [1, 1, 1, 1]
    for ii in range(4):
        pauli_term = sZ(ii)
        new_basis_state, coeff = compute_action(comp_basis_state, pauli_term,
                                            len(comp_basis_state))
        # abuse of comparisons in python
        true_basis_state = comp_basis_state.copy()
        true_basis_state[ii] = true_basis_state[ii]
        assert new_basis_state == true_basis_state
        assert np.isclose(coeff, -1) 
开发者ID:rigetti,项目名称:reference-qvm,代码行数:27,代码来源:test_stabilizer_utils.py

示例6: test_compute_action_ZZ

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [as 别名]
def test_compute_action_ZZ():
    """
    Action of Pauli operators on state
    """
    comp_basis_state = [0, 0, 0, 0]
    for ii in range(3):
        pauli_term = sZ(ii) * sZ(ii + 1)
        new_basis_state, coeff = compute_action(comp_basis_state, pauli_term,
                                            len(comp_basis_state))
        # abuse of comparisons in python
        true_basis_state = comp_basis_state.copy()
        assert new_basis_state == true_basis_state
        assert np.isclose(coeff, 1)

    comp_basis_state = [1, 1, 1, 1]
    for ii in range(3):
        pauli_term = sZ(ii) * sZ(ii + 1)
        new_basis_state, coeff = compute_action(comp_basis_state, pauli_term,
                                            len(comp_basis_state))
        # abuse of comparisons in python
        true_basis_state = comp_basis_state.copy()
        assert new_basis_state == true_basis_state
        assert np.isclose(coeff, 1) 
开发者ID:rigetti,项目名称:reference-qvm,代码行数:25,代码来源:test_stabilizer_utils.py

示例7: test_lifted_pauli

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [as 别名]
def test_lifted_pauli():
    qubits = [0, 1]
    xy_term = sX(0) * sY(1)

    # test correctness
    trial_matrix = lifted_pauli(xy_term, qubits)
    true_matrix = np.kron(mat.Y, mat.X)
    np.testing.assert_allclose(trial_matrix, true_matrix)

    x1_term = sX(1)
    trial_matrix = lifted_pauli(x1_term, qubits)
    true_matrix = np.kron(mat.X, mat.I)
    np.testing.assert_allclose(trial_matrix, true_matrix)

    zpz_term = sZ(0) + sZ(1)
    trial_matrix = lifted_pauli(zpz_term, qubits)
    true_matrix = np.zeros((4, 4))
    true_matrix[0, 0] = 2
    true_matrix[-1, -1] = -2
    np.testing.assert_allclose(trial_matrix, true_matrix) 
开发者ID:rigetti,项目名称:pyquil,代码行数:22,代码来源:test_tools.py

示例8: test_qc_calibration_1q

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [as 别名]
def test_qc_calibration_1q(forest):
    # noise model with 95% symmetrized readout fidelity per qubit
    noise_model = asymmetric_ro_model([0], 0.945, 0.955)
    qc = get_qc("1q-qvm")
    qc.qam.noise_model = noise_model

    # bell state program (doesn't matter)
    p = Program()
    p += RESET()
    p += H(0)
    p += CNOT(0, 1)
    p.wrap_in_numshots_loop(10000)

    # Z experiment
    sz = ExperimentSetting(in_state=sZ(0), out_operator=sZ(0))
    e = Experiment(settings=[sz], program=p)

    results = qc.calibrate(e)

    # Z expectation value should just be 1 - 2 * readout_error
    np.isclose(results[0].expectation, 0.9, atol=0.01)
    assert results[0].total_counts == 20000 
开发者ID:rigetti,项目名称:pyquil,代码行数:24,代码来源:test_quantum_computer.py

示例9: test_qc_calibration_2q

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [as 别名]
def test_qc_calibration_2q(forest):
    # noise model with 95% symmetrized readout fidelity per qubit
    noise_model = asymmetric_ro_model([0, 1], 0.945, 0.955)
    qc = get_qc("2q-qvm")
    qc.qam.noise_model = noise_model

    # bell state program (doesn't matter)
    p = Program()
    p += RESET()
    p += H(0)
    p += CNOT(0, 1)
    p.wrap_in_numshots_loop(10000)

    # ZZ experiment
    sz = ExperimentSetting(in_state=sZ(0) * sZ(1), out_operator=sZ(0) * sZ(1))
    e = Experiment(settings=[sz], program=p)

    results = qc.calibrate(e)

    # ZZ expectation should just be (1 - 2 * readout_error_q0) * (1 - 2 * readout_error_q1)
    np.isclose(results[0].expectation, 0.81, atol=0.01)
    assert results[0].total_counts == 40000 
开发者ID:rigetti,项目名称:pyquil,代码行数:24,代码来源:test_quantum_computer.py

示例10: test_measure_observables

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [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

示例11: test_measure_observables_many_progs

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [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

示例12: test_measure_observables_symmetrize_calibrate

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [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

示例13: test_measure_observables_calibrated_symmetric_readout

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [as 别名]
def test_measure_observables_calibrated_symmetric_readout(forest, use_seed):
    # expecting the result +1 for calibrated readout
    qc = get_qc("1q-qvm")
    if use_seed:
        qc.qam.random_seed = 0
        np.random.seed(0)
        num_simulations = 1
    else:
        num_simulations = 100
    expt1 = ExperimentSetting(TensorProductState(plusX(0)), sX(0))
    expt2 = ExperimentSetting(TensorProductState(plusY(0)), sY(0))
    expt3 = ExperimentSetting(TensorProductState(plusZ(0)), sZ(0))
    p = Program()
    p.wrap_in_numshots_loop(2000)
    p.define_noisy_readout(0, p00=0.99, p11=0.80)
    tomo_expt = Experiment(settings=[expt1, expt2, expt3], program=p)

    expectations = []
    for _ in range(num_simulations):
        expt_results = list(measure_observables(qc, tomo_expt))
        expectations.append([res.expectation for res in expt_results])
    expectations = np.array(expectations)
    results = np.mean(expectations, axis=0)
    np.testing.assert_allclose(results, 1.0, atol=2e-2) 
开发者ID:rigetti,项目名称:pyquil,代码行数:26,代码来源:test_operator_estimation.py

示例14: test_expectations_sic0

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [as 别名]
def test_expectations_sic0(forest, use_seed):
    qc = get_qc("1q-qvm")
    if use_seed:
        qc.qam.random_seed = 0
        np.random.seed(0)
        num_simulations = 1
    else:
        num_simulations = 100
    expt1 = ExperimentSetting(SIC0(0), sX(0))
    expt2 = ExperimentSetting(SIC0(0), sY(0))
    expt3 = ExperimentSetting(SIC0(0), sZ(0))
    tomo_expt = Experiment(settings=[expt1, expt2, expt3], program=Program())

    results_unavged = []
    for _ in range(num_simulations):
        measured_results = []
        for res in measure_observables(qc, tomo_expt, n_shots=2000):
            measured_results.append(res.expectation)
        results_unavged.append(measured_results)

    results_unavged = np.array(results_unavged)
    results = np.mean(results_unavged, axis=0)
    expected_results = np.array([0, 0, 1])
    np.testing.assert_allclose(results, expected_results, atol=2e-2) 
开发者ID:rigetti,项目名称:pyquil,代码行数:26,代码来源:test_operator_estimation.py

示例15: test_rotation_programs

# 需要导入模块: from pyquil import paulis [as 别名]
# 或者: from pyquil.paulis import sZ [as 别名]
def test_rotation_programs():
    """
    Testing the generation of post rotations
    """
    test_term = sZ(0) * sX(20) * sI(100) * sY(5)
    rotations_to_do = [RX(np.pi / 2, 5), RY(-np.pi / 2, 20)]
    test_rotation_program = get_rotation_program(test_term)
    # Since the rotations commute, it's sufficient to test membership in the program,
    # without ordering. However, it's true that a more complicated rotation could be performed,
    #  where the elements would not be free to be permuted. We ignore this possibility, for now.
    assert len(rotations_to_do) == len(test_rotation_program)
    for rotation in test_rotation_program:
        assert rotation in rotations_to_do 
开发者ID:rigetti,项目名称:grove,代码行数:15,代码来源:test_estimation.py


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