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


Python gates.I属性代码示例

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


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

示例1: basis_state_preps

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import I [as 别名]
def basis_state_preps(*qubits):
    """
    Generate a sequence of programs that prepares the measurement
    basis states of some set of qubits in the order such that the qubit
    with highest index is iterated over the most quickly:
    E.g., for ``qubits=(0, 1)``, it returns the circuits::

        I_0 I_1
        I_0 X_1
        X_0 I_1
        X_0 X_1

    :param list qubits: Each qubit to include in the basis state preparation.
    :return: Yields programs for each basis state preparation.
    :rtype: Program
    """
    for prep in cartesian_product([I, X], repeat=len(qubits)):
        basis_prep = Program(Pragma("PRESERVE_BLOCK"))
        for gate, qubit in zip(prep, qubits):
            basis_prep.inst(gate(qubit))
        basis_prep.inst(Pragma("END_PRESERVE_BLOCK"))
        yield basis_prep 
开发者ID:rigetti,项目名称:grove,代码行数:24,代码来源:utils.py

示例2: test_mutation_free_estimation

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import I [as 别名]
def test_mutation_free_estimation():
    """
    Make sure the estimation routines do not mutate the programs the user sends.

    This is accomplished by a deep copy in `estimate_pauli_sum'.
    """
    prog = Program().inst(I(0))
    pauli_sum = sX(0)  # measure in the X-basis

    # set up fake QVM
    with patch("pyquil.api.QuantumComputer") as qc:
        # Mock the response
        qc.run.return_value = [[0], [1]]

    _, _, _ = estimate_locally_commuting_operator(prog,
                                                  pauli_sum=PauliSum([pauli_sum]),
                                                  variance_bound=1.0E-3,
                                                  quantum_resource=qc)

    # make sure RY(-pi/2) 0\nMEASURE 0 [0] was not added to the program the user sees
    assert prog.out() == 'I 0\n' 
开发者ID:rigetti,项目名称:grove,代码行数:23,代码来源:test_estimation.py

示例3: kron_eigs

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import I [as 别名]
def kron_eigs(ham: PauliSum, qubits: List[int]) -> np.array:
    """
    Calculate the eigenvalues of `ham` ordered as a tensorproduct
    on `qubits`. Each qubit should be acted on with the same operator
    by each term or not at all.
    """
    diag = np.zeros((2**len(qubits)))
    for term in ham:
        out = term.coefficient.real
        for qubit in qubits:
            if term[qubit] != 'I':
                out = np.kron([1, -1], out)
            else:
                out = np.kron([1, 1], out)
        diag += out

    return diag 
开发者ID:entropicalabs,项目名称:entropica_qaoa,代码行数:19,代码来源:measurelib.py

示例4: noise_model_dict

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import I [as 别名]
def noise_model_dict():
    return {
        "gates": [
            {
                "gate": "I",
                "params": (5.0,),
                "targets": (0, 1),
                "kraus_ops": [[[[1.0]], [[1.0]]]],
                "fidelity": 1.0,
            },
            {
                "gate": "RX",
                "params": (np.pi / 2.0,),
                "targets": (0,),
                "kraus_ops": [[[[1.0]], [[1.0]]]],
                "fidelity": 1.0,
            },
        ],
        "assignment_probs": {"1": [[1.0, 0.0], [0.0, 1.0]], "0": [[1.0, 0.0], [0.0, 1.0]]},
    } 
开发者ID:rigetti,项目名称:pyquil,代码行数:22,代码来源:conftest.py

示例5: test_kraus_application_relaxation

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import I [as 别名]
def test_kraus_application_relaxation():
    p = 0.372
    qam = PyQVM(
        n_qubits=1,
        quantum_simulator_type=ReferenceDensitySimulator,
        post_gate_noise_probabilities={"relaxation": p},
    )
    rho = _random_1q_density()
    qam.wf_simulator.density = rho
    qam.execute(Program(I(0)))

    final_density = np.array(
        [
            [rho[0, 0] + rho[1, 1] * p, np.sqrt(1 - p) * rho[0, 1]],
            [np.sqrt(1 - p) * rho[1, 0], (1 - p) * rho[1, 1]],
        ]
    )
    np.testing.assert_allclose(final_density, qam.wf_simulator.density) 
开发者ID:rigetti,项目名称:pyquil,代码行数:20,代码来源:test_reference_density.py

示例6: test_kraus_application_depolarizing

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import I [as 别名]
def test_kraus_application_depolarizing():
    p = 0.372
    qam = PyQVM(
        n_qubits=1,
        quantum_simulator_type=ReferenceDensitySimulator,
        post_gate_noise_probabilities={"depolarizing": p},
    )
    rho = _random_1q_density()
    qam.wf_simulator.density = rho
    qam.execute(Program(I(0)))

    final_density = (1 - p) * rho + (p / 3) * (
        qmats.X.dot(rho).dot(qmats.X)
        + qmats.Y.dot(rho).dot(qmats.Y)
        + qmats.Z.dot(rho).dot(qmats.Z)
    )
    np.testing.assert_allclose(final_density, qam.wf_simulator.density) 
开发者ID:rigetti,项目名称:pyquil,代码行数:19,代码来源:test_reference_density.py

示例7: bitstring_probs_to_z_moments

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import I [as 别名]
def bitstring_probs_to_z_moments(p: np.ndarray) -> np.ndarray:
    """
    Convert between bitstring probabilities and joint Z moment expectations.

    :param p: An array that enumerates bitstring probabilities. When
        flattened out ``p = [p_00...0, p_00...1, ...,p_11...1]``. The total number of elements must
        therefore be a power of 2. The canonical shape has a separate axis for each qubit, such that
        ``p[i,j,...,k]`` gives the estimated probability of bitstring ``ij...k``.
    :return: ``z_moments``, an np.array with one length-2 axis per qubit which contains the
        expectations of all monomials in ``{I, Z_0, Z_1, ..., Z_{n-1}}``. The expectations of each
        monomial can be accessed via::

            <Z_0^j_0 Z_1^j_1 ... Z_m^j_m> = z_moments[j_0,j_1,...,j_m]
    """
    zmat = np.array([[1, 1], [1, -1]])
    return _apply_local_transforms(p, (zmat for _ in range(p.ndim))) 
开发者ID:rigetti,项目名称:pyquil,代码行数:18,代码来源:noise.py

示例8: test_measure_observables

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

示例9: _random_2q_programs

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import I [as 别名]
def _random_2q_programs(n_progs=3):
    """Generate random programs that consist of single qubit rotations, a CZ, and single
    qubit rotations.
    """
    r = random.Random(52)

    def RI(qubit, angle):
        # throw away angle so we can randomly choose the identity
        return I(qubit)

    def _random_1q_gate(qubit):
        return r.choice([RI, RX, RY, RZ])(qubit=qubit, angle=r.uniform(0, 2 * pi))

    for _ in range(n_progs):
        prog = Program()
        prog += _random_1q_gate(0)
        prog += _random_1q_gate(1)
        prog += CZ(0, 1)
        prog += _random_1q_gate(0)
        prog += _random_1q_gate(1)
        yield prog 
开发者ID:rigetti,项目名称:pyquil,代码行数:23,代码来源:test_operator_estimation.py

示例10: test_measure_observables_many_progs

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

示例11: test_measure_observables_symmetrize

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

示例12: test_measure_observables_symmetrize_calibrate

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

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import I [as 别名]
def test_measure_bitstrings(forest):
    device = NxDevice(nx.complete_graph(2))
    qc_pyqvm = QuantumComputer(
        name="testy!", qam=PyQVM(n_qubits=2), device=device, compiler=DummyCompiler()
    )
    qc_forest = QuantumComputer(
        name="testy!",
        qam=QVM(connection=forest, gate_noise=[0.00] * 3),
        device=device,
        compiler=DummyCompiler(),
    )
    prog = Program(I(0), I(1))
    meas_qubits = [0, 1]
    sym_progs, flip_array = _symmetrization(prog, meas_qubits, symm_type=-1)
    results = _measure_bitstrings(qc_pyqvm, sym_progs, meas_qubits, num_shots=1)
    # test with pyQVM
    answer = [np.array([[0, 0]]), np.array([[0, 1]]), np.array([[1, 0]]), np.array([[1, 1]])]
    assert all([np.allclose(x, y) for x, y in zip(results, answer)])
    # test with regular QVM
    results = _measure_bitstrings(qc_forest, sym_progs, meas_qubits, num_shots=1)
    assert all([np.allclose(x, y) for x, y in zip(results, answer)]) 
开发者ID:rigetti,项目名称:pyquil,代码行数:23,代码来源:test_quantum_computer.py

示例14: CNOT_X_basis

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import I [as 别名]
def CNOT_X_basis(control, target) -> Program:
    """
    The CNOT in the X basis, i.e.

    ::

        CNOTX = |+X+| * I + |-X-| * Z

    where ``|+>`` and ``|->`` are the +/- eigenstate of the Pauli X operator, and ``*`` denotes a
    tensor product.

    :param control: qubit label
    :param target: qubit label
    :return: program
    """
    prog = Program()
    prog += H(control)
    prog += CZ(control, target)
    prog += H(control)
    return prog 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:22,代码来源:primitives.py

示例15: str_to_pauli_term

# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import I [as 别名]
def str_to_pauli_term(pauli_str: str, qubit_labels=None):
    """
    Convert a string into a :class:`~pyquil.paulis.PauliTerm`.

    >>> str_to_pauli_term('XY', [])

    :param str pauli_str: The input string, made of of 'I', 'X', 'Y' or 'Z'
    :param qubit_labels: The integer labels for the qubits in the string
        If None, default to the range of the length of pauli_str.
    :return: the corresponding PauliTerm
    :rtype: pyquil.paulis.PauliTerm
    """
    if qubit_labels is None:
        qubit_labels = [qubit for qubit in range(len(pauli_str))]

    pauli_term = PauliTerm.from_list(list(zip(pauli_str, qubit_labels)))
    return pauli_term 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:19,代码来源:utils.py


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