Skip to main content

Quantinuum's open source emulator for hybrid quantum computation

Project description

Selene Logo

Selene

Selene is a quantum computer emulation platform written primarily in Rust with a python frontend.

Selene is built with flexibility in mind. This includes:

  • A plugin system for the addition of additional components including simulators, error models, quantum runtimes to be provided within Selene or as third party plugins
  • Support for custom input formats and device APIs through the selene-core build system.

What's included

Out of the box, Selene provides first-class support for the HUGR ecosystem, including execution of Guppy programs in an emulation environment, making use of our open-source compiler. You can find many examples of guppy usage in our unit tests.

Selene provides a range of simulators, including:

  • Statevector simulation using QuEST and the quest-sys crate.
  • Stabilizer simulation using Stim
  • Coinflip simulation with customisable bias
  • Classical Replay, for running pre-recorded measurements without direct simulation
  • Quantum Replay, for running pre-recorded measurements with postselection-based simulation

Error models that are currently provided include:

  • An 'ideal' error model which adds no noise to simulations
  • A depolarizing error model which adds noise to qubit initialisation, measurement, and single- and two-qubit gates

And we offer two example quantum runtimes, including:

  • Simple, which executes the program as-is, without any modifications
  • SoftRZ, which elides Z rotations through RXY gates, providing the same observable behaviour with fewer quantum operations

Usage example

Although examples are provided in our tests folder, here is a quick walkthrough to get you started with Selene, HUGR and Guppy.

  • First, we define the guppy program that we're interested in emulating:
from guppylang import guppy
from guppylang.std.quantum import *
from hugr.qsystem.result import QsysShot, QsysResult

@guppy
def main() -> None:
    # allocate 10 qubits
    qubits = array(qubit() for _ in range(10))

    # prepare the 10-qubit GHZ state (|0000000000> + |1111111111>)/sqrt(2)
    h(qubits[0])
    for i in range(9):
        cx(qubits[i], qubits[i+1])

    # measure all qubits
    ms = measure_array(qubits)

    # report measurements to the results stream
    result("measurements", ms)

compiled_hugr = main.compile()
  • Then we compile the resulting HUGR Envelope to LLVM IR or bitcode using the HUGR-QIS compiler
from selene_sim import build
runner = build(compiled_hugr)
  • Then we can utilise run or run_shots on the resulting selene instance, choosing a simulator (in this case Quest or Stim) and an error model (in this case DepolarizingErrorModel) to run the program.
from selene_sim import Quest, Stim
# run a single shot with Quest, the statevector simulator
shot = QsysShot(runner.run(simulator=Quest(), n_qubits=10))
print(shot)

# run a single shot with Stim, the stabilizer simulator
shot = QsysShot(runner.run(simulator=Stim(), n_qubits=10))
print(shot)

# run_shots runs efficient multi-shot simulations
# n_processes provides multi-processing across shots
# deterministic results can be achieved by providing a random seed
shots = QsysShot(runner.run(
    simulator=Stim(random_seed=5),
    n_qubits=10,
    n_shots=100,
    n_processes=8
))
print(shots)
  • As well as simulators, we can customise the emulation by providing an error model, such as the depolarizing error model:
from selene_sim import DepolarizingErrorModel
error_model = DepolarizingErrorModel(
    random_seed=12478918,
    p_init=1e-3,
    p_meas=1e-2,
    p_1q=1e-5,
    p_2q=1e-6,
)

shots = QsysResult(runner.run_shots(
    simulator=Stim(
        random_seed=10
    ), 
    error_model=error_model,
    n_qubits=10,
    n_shots=20,
    n_processes=4,
))
print(shots)
  • And/or a runtime, such as the SoftRZRuntime, which elides physical RZ gates through subsequent RXY gates:
from selene_sim import SoftRZRuntime

shots = QsysResult(runner.run_shots(
    simulator=Stim(),
    runtime=SoftRZRuntime(),
    error_model=error_model,
    n_qubits=10,
    n_shots=20
))
print(shots)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

selene_sim-0.2.0rc5-py3-none-win_amd64.whl (2.8 MB view details)

Uploaded Python 3Windows x86-64

selene_sim-0.2.0rc5-py3-none-manylinux_2_28_x86_64.whl (4.4 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

selene_sim-0.2.0rc5-py3-none-manylinux_2_28_aarch64.whl (4.4 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

selene_sim-0.2.0rc5-py3-none-macosx_11_0_x86_64.whl (4.0 MB view details)

Uploaded Python 3macOS 11.0+ x86-64

selene_sim-0.2.0rc5-py3-none-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file selene_sim-0.2.0rc5-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for selene_sim-0.2.0rc5-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 7b8136d626152e2ca3b296c6f89f0438b4619d97cbd7af100a2dde240836310b
MD5 f7d72589b22b9be1e857f7c90c7bcf87
BLAKE2b-256 668497f9316dc9e127d6817d31fd2fc3a6955e6456fb48d50192bbf637f095f0

See more details on using hashes here.

File details

Details for the file selene_sim-0.2.0rc5-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for selene_sim-0.2.0rc5-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3706ece62f8f74faf7a41a915afdcf3e0b75f053d2736d607a41712b02e3b2a5
MD5 c8cc5e115723eddfade49e883d296d27
BLAKE2b-256 47d306954c89f3bf715b99649cf68c782305b86ccb467d91ffdfe431992cc4d8

See more details on using hashes here.

File details

Details for the file selene_sim-0.2.0rc5-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for selene_sim-0.2.0rc5-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 61ac4e018837f4581c560ce3990cf95c4814b129a7911183ff6fa9229b9debcb
MD5 5e0ac19dcc0eacad18b44d1eafaf4413
BLAKE2b-256 69bf7c6bea3b7298072a26cd663b87b737ad7f47d0b2f036df4256211fb375d8

See more details on using hashes here.

File details

Details for the file selene_sim-0.2.0rc5-py3-none-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for selene_sim-0.2.0rc5-py3-none-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 fd91d5f6adeb4fc6a8647794938ef888374c88bea168a37ad3fb9ae5e5c02ba2
MD5 f7eee457d9b79d1717c6584a8ff8a7f2
BLAKE2b-256 bb3c1845c281ac70864cc48338adf27bfc5f78abc1f0f63fc1843b2c55aa941c

See more details on using hashes here.

File details

Details for the file selene_sim-0.2.0rc5-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for selene_sim-0.2.0rc5-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 62da9755399f303b87fffdde0ed1364ddca5fcd49a7314e3586ff958eb4f7120
MD5 7f2b1f4b15a99070a033e5e8a4776d18
BLAKE2b-256 5603569737570b705e69fa694253639eeec5e8ce9f5c9eb12320c067c6b090e6

See more details on using hashes here.

Supported by

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