Skip to main content

Implementation of the gate-by-gate sampling algorithm.

Project description

BGLS

build doctest pages-build-deployment Documentation Repository Unitary Fund

BGLS is a Python package that implements the Bravyi, Gosset, and Liu Sampling algorithm presented in How to simulate quantum measurement without computing marginals (Phys. Rev. Lett.) (arXiv) for Cirq circuits.

Quickstart

Installation

pip install bgls

Example

import cirq
import bgls

# Example circuit to run.
qubits = cirq.LineQubit.range(2)
circuit = cirq.Circuit(
    cirq.H.on(qubits[0]),
    cirq.CNOT.on(*qubits),
    cirq.measure(*qubits, key="z")
)

# Run the circuit with BGLS.
simulator = bgls.Simulator(
    initial_state=cirq.StateVectorSimulationState(qubits=qubits, initial_state=0),
    apply_op=cirq.protocols.act_on,
    compute_probability=bgls.born.compute_probability_state_vector,
)
results = simulator.run(circuit, repetitions=10)
print(results.histogram(key="z"))

Sample output:

Counter({0: 6, 3: 4})

Documentation

See more details and examples in the Documentation for BGLS.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bgls-0.2.0.tar.gz (19.0 kB view hashes)

Uploaded Source

Built Distribution

bgls-0.2.0-py3-none-any.whl (25.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page