PartitionedSum

Struct PartitionedSum 

Source
pub struct PartitionedSum<const W: usize, B = HostPartition<W>> { /* private fields */ }
Expand description

A PauliSum split across the partitions of a PartitionRuntime, held across calls so a driver scatters and gathers once.

Between calls every partition’s sum holds only keys of its own partition and shares one hash and bucket count with its peers (PartitionedSum::assert_invariants). B is where a partition lives: host memory by default, a CUDA device for gpu::GpuPartitionedSum.

Implementations§

Source§

impl<const W: usize, B> PartitionedSum<W, B>

Source

pub fn num_partitions(&self) -> usize

Partitions this sum is split across.

Source

pub fn rows(&self) -> &PartitionRows<W>

The rows deciding which partition a key belongs to.

Source

pub fn runtime(&self) -> &Arc<PartitionRuntime>

The runtime this sum runs on, for handing to another PartitionedSum.

Source

pub fn enable_trace(&mut self)

Start recording a PartitionTrace on every later propagation; idempotent.

Source

pub fn take_trace(&mut self) -> Option<PartitionTrace>

Drain the per-layer records, or None if tracing was never enabled; tracing stays enabled.

Source§

impl<const W: usize, B: PartitionStorage<W>> PartitionedSum<W, B>

Source

pub fn len(&self) -> usize

Terms in the whole sum, summed over partitions.

Source

pub fn is_empty(&self) -> bool

Whether every partition is empty.

Source

pub fn bits(&self) -> u8

The bucket bits every partition currently holds.

Source

pub fn num_qubits(&self) -> usize

Qubits the sum is over.

Source§

impl<const W: usize> PartitionedSum<W>

Source

pub fn scatter( sum: PauliSum<W>, config: &PartitionConfig, ) -> Result<Self, TopologyError>

Splits sum across the partitions config places, by the default rows (PartitionRowPolicy::Seeded at the sum’s own hash seed); other rows go through scatter_with.

§Errors

TopologyError if config cannot be resolved or a pool cannot be built.

§Panics

In debug builds, if the partition rows are not independent of the sum’s hash rows.

Source

pub fn scatter_with(sum: PauliSum<W>, options: ScatterOptions<W>) -> Self

scatter onto a caller-built runtime, split by the rows options names; at P = 1 the scatter changes nothing.

§Panics

If the rows do not name the runtime’s partition count, or as PartitionRows::cut. In debug builds, if the rows are not independent of the sum’s hash rows, which costs load balance but not correctness.

Source

pub fn propagate<T>( &mut self, circuit: &Circuit<W>, policy: &T, direction: Direction, )
where T: TruncationPolicy<W> + ?Sized,

Propagates through circuit under policy, in place; see propagate_with.

Source

pub fn propagate_with<T>( &mut self, circuit: &Circuit<W>, policy: &T, direction: Direction, options: PropagateOptions, )
where T: TruncationPolicy<W> + ?Sized,

Propagates through circuit under policy with explicit PropagateOptions, as propagate_with does unpartitioned.

The per-layer DEBUG log line comes once per partition, tagged partition r/P, from that partition’s own thread.

§Panics

If options fail PropagateOptions::validate, or a channel’s preparation declines, as the unpartitioned engine does. Before the first layer, above one partition, unless policy.supports_partitioned() — exact TopN is not yet supported partitioned. A panic in any partition is re-raised on the calling thread.

Source

pub fn gather(&self) -> PauliSum<W>

Merges the partitions back into one sum on the calling thread, leaving self intact.

Source

pub fn into_gathered(self) -> PauliSum<W>

gather by value — no clone of the parts.

Source

pub fn partition(&self, r: usize) -> &PauliSum<W>

Partition r’s share of the sum.

§Panics

If r is not a partition of this sum.

Source

pub fn expectation_product(&self, basis: &ProductBasis<W>) -> Complex64

⟨ψ|O|ψ⟩ in the product state basis, the partitions’ own values added in rank order.

Source

pub fn assert_invariants(&self)

Checks every invariant a partitioned sum holds between calls, in O(terms); release builds skip the per-partition structural check.

§Panics

If a partition’s sum is internally inconsistent, holds a key of another partition, or disagrees with partition 0 about the hash rows, the bucket count or the qubit count.

Auto Trait Implementations§

§

impl<const W: usize, B> Freeze for PartitionedSum<W, B>

§

impl<const W: usize, B = HostPartition<W>> !RefUnwindSafe for PartitionedSum<W, B>

§

impl<const W: usize, B> Send for PartitionedSum<W, B>
where B: Send,

§

impl<const W: usize, B> Sync for PartitionedSum<W, B>
where B: Sync,

§

impl<const W: usize, B> Unpin for PartitionedSum<W, B>
where B: Unpin,

§

impl<const W: usize, B = HostPartition<W>> !UnwindSafe for PartitionedSum<W, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,