How to use the qsharp.Pauli function in qsharp

To help you get started, we’ve selected a few qsharp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / iqsharp / src / Python / qsharp-core / qsharp / tomography.py View on Github external
if qt is None:
        raise ImportError("This function requires QuTiP.")
    if qi is None:
        raise ImportError("This function requires QInfer.")

    print("Preparing tomography model...")
    state_basis = qi.tomography.pauli_basis(1)
    prior = qi.tomography.BCSZChoiDistribution(state_basis)
    model = qi.tomography.TomographyModel(prior.basis)

    updater = qi.SMCUpdater(model, n_particles, prior)

    print("Performing tomography...")
    for idx_experiment in range(n_measurements):
        prep = qsharp.Pauli.sample()
        meas = qsharp.Pauli.sample()

        # Convert into a QuTiP object by using the standard transformation
        # between state and process tomography.
        qobj = 2.0 * qt.tensor(
            projector(prep.as_qobj()).trans(), projector(meas.as_qobj())
        )
        expparams = np.array(
            [(model.basis.state_to_modelparams(qobj),)],
            dtype=model.expparams_dtype
        )

        datum = 1 - operation.simulate(prep=prep, meas=meas)

        updater.update(datum, expparams)

    return {
github microsoft / iqsharp / src / Python / qsharp-core / qsharp / tomography.py View on Github external
"""
    if qt is None:
        raise ImportError("This function requires QuTiP.")
    if qi is None:
        raise ImportError("This function requires QInfer.")

    print("Preparing tomography model...")
    state_basis = qi.tomography.pauli_basis(1)
    prior = qi.tomography.BCSZChoiDistribution(state_basis)
    model = qi.tomography.TomographyModel(prior.basis)

    updater = qi.SMCUpdater(model, n_particles, prior)

    print("Performing tomography...")
    for idx_experiment in range(n_measurements):
        prep = qsharp.Pauli.sample()
        meas = qsharp.Pauli.sample()

        # Convert into a QuTiP object by using the standard transformation
        # between state and process tomography.
        qobj = 2.0 * qt.tensor(
            projector(prep.as_qobj()).trans(), projector(meas.as_qobj())
        )
        expparams = np.array(
            [(model.basis.state_to_modelparams(qobj),)],
            dtype=model.expparams_dtype
        )

        datum = 1 - operation.simulate(prep=prep, meas=meas)

        updater.update(datum, expparams)