Simulators

BraketSimulators.jl provides two types of simulators: StateVectorSimulator for pure state simulation (without noise) and DensityMatrixSimulator for noisy simulation. Each type is parameterized by an element type (which should be a Julia Complex type, such as ComplexF64) and an array type (so that we can specialize for GPU arrays, for example).

Each simulator can be initialized with a qubit_count and shots value. You may query the properties of a simulator to learn what gate types, result types, and other operations it supports.

BraketSimulator.StateVectorSimulatorType
StateVectorSimulator{T, S<:AbstractVector{T}} <: AbstractSimulator

Simulator representing a pure state evolution of a statevector of type S, with element type T. State vector simulators should be used to simulate circuits without noise.

source
BraketSimulator.DensityMatrixSimulatorType
DensityMatrixSimulator{T, S<:AbstractMatrix{T}} <: AbstractSimulator

Simulator representing evolution of a density matrix of type S, with element type T. Density matrix simulators should be used to simulate circuits with noise.

source
BraketSimulator.evolve!Function
evolve!(svs::StateVectorSimulator{T, S<:AbstractVector{T}}, operations::Vector{Instruction}) -> StateVectorSimulator{T, S}

Apply each operation of operations in-place to the state vector contained in svs.

Effectively, perform the operation:

$\left| \psi \right\rangle \to \hat{A} \left| \psi \right\rangle$

for each operation $\hat{A}$ in operations.

source
evolve!(dms::DensityMatrixSimulator{T, S<:AbstractMatrix{T}}, operations::Vector{Instruction}) -> DensityMatrixSimulator{T, S}

Apply each operation of operations in-place to the density matrix contained in dms.

Effectively, perform the operation:

$\hat{\rho} \to \hat{A}^\dag \hat{\rho} \hat{A}$

for each operation $\hat{A}$ in operations.

source
BraketSimulator.simulateFunction
simulate(simulator::AbstractSimulator, circuit_ir::Union{OpenQasmProgram, Program}, shots::Int; kwargs...) -> GateModelTaskResult

Simulate the evolution of a state vector or density matrix using the passed-in simulator. The instructions to apply (gates and noise channels) and measurements to make are encoded in circuit_ir. Supported IR formats are OpenQASMProgram (OpenQASM3) and Program (JAQCD). Returns a GateModelTaskResult containing the individual shot measurements (if shots > 0), final calculated results, circuit IR, and metadata about the task.

source
simulate(simulator::AbstractSimulator, circuit_irs::Vector{<:Union{Program, OpenQasmProgram}}, shots::Int; max_parallel::Int=min(32, Threads.nthreads()), inputs=Dict{String,Float64}(), kwargs...) -> Vector{GateModelTaskResult}

Simulate the evolution of a batch of state vectors or density matrices using the passed in simulator. The instructions to apply (gates and noise channels) and measurements to make are encoded in circuit_irs. Supported IR formats are OpenQASMProgram (OpenQASM3) and Program (JAQCD).

The simulation of the batch is done in parallel using threads. The keyword argument max_parallel specifies the number of evolutions to simulate in parallel – the default value is whichever of 32 and Threads.nthreads() is smaller. This is to avoid overwhelming the thread scheduler with too many small tasks waiting to run, as each evolution is itself threaded. This value may change in the future.

The inputs keyword argument can be a Dict{String} or a Vector{Dict{String}}. In the first case, the same input values are applied to all circuit_irs. In the second, the length of the inputs must be the same as the length of circuit_irs, and the n-th inputs is applied to the n-th circuit_irs.

Returns a Vector{GateModelTaskResult}, each element of which contains the individual shot measurements (if shots > 0), final calculated results, corresponding circuit IR, and metadata about the task.

source
BraketSimulator.expectationFunction
expectation(svs::StateVectorSimulator, observable::Observables.Observable, targets::Int...) -> Float64

Compute the exact (shots=0) expectation value of observable applied to targets given the evolved state vector in svs. In other words, compute

$\langle \psi | \hat{O} | \psi \rangle$.

source
expectation(dms::DensityMatrixSimulator, observable::Observables.Observable, targets::Int...) -> Float64

Compute the exact (shots=0) expectation value of observable applied to targets given the evolved density matrix in dms. In other words, compute

$\mathrm{Tr}\left(\hat{O}\hat{\rho}\right)$.

source
BraketSimulator.probabilitiesFunction
probabilities(svs::StateVectorSimulator) -> Vector{Float64}

Compute the observation probabilities of all amplitudes in the state vector in svs.

source
BraketSimulator.propertiesFunction
properties(svs::StateVectorSimulator) -> GateModelSimulatorDeviceCapabilities

Query the properties and capabilities of a StateVectorSimulator, including which gates and result types are supported and the minimum and maximum shot and qubit counts.

source
properties(svs::DensityMatrixSimulator) -> GateModelSimulatorDeviceCapabilities

Query the properties and capabilities of a DensityMatrixSimulator, including which gates and result types are supported and the minimum and maximum shot and qubit counts.

source