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>
impl<const W: usize, B> PartitionedSum<W, B>
Sourcepub fn num_partitions(&self) -> usize
pub fn num_partitions(&self) -> usize
Partitions this sum is split across.
Sourcepub fn rows(&self) -> &PartitionRows<W>
pub fn rows(&self) -> &PartitionRows<W>
The rows deciding which partition a key belongs to.
Sourcepub fn runtime(&self) -> &Arc<PartitionRuntime>
pub fn runtime(&self) -> &Arc<PartitionRuntime>
The runtime this sum runs on, for handing to another PartitionedSum.
Sourcepub fn enable_trace(&mut self)
pub fn enable_trace(&mut self)
Start recording a PartitionTrace on every later propagation; idempotent.
Sourcepub fn take_trace(&mut self) -> Option<PartitionTrace>
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>
impl<const W: usize, B: PartitionStorage<W>> PartitionedSum<W, B>
Source§impl<const W: usize> PartitionedSum<W>
impl<const W: usize> PartitionedSum<W>
Sourcepub fn scatter(
sum: PauliSum<W>,
config: &PartitionConfig,
) -> Result<Self, TopologyError>
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.
Sourcepub fn scatter_with(sum: PauliSum<W>, options: ScatterOptions<W>) -> Self
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.
Sourcepub fn propagate<T>(
&mut self,
circuit: &Circuit<W>,
policy: &T,
direction: Direction,
)where
T: TruncationPolicy<W> + ?Sized,
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.
Sourcepub fn propagate_with<T>(
&mut self,
circuit: &Circuit<W>,
policy: &T,
direction: Direction,
options: PropagateOptions,
)where
T: TruncationPolicy<W> + ?Sized,
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.
Sourcepub fn gather(&self) -> PauliSum<W>
pub fn gather(&self) -> PauliSum<W>
Merges the partitions back into one sum on the calling thread, leaving self intact.
Sourcepub fn into_gathered(self) -> PauliSum<W>
pub fn into_gathered(self) -> PauliSum<W>
gather by value — no clone of the parts.
Sourcepub fn expectation_product(&self, basis: &ProductBasis<W>) -> Complex64
pub fn expectation_product(&self, basis: &ProductBasis<W>) -> Complex64
⟨ψ|O|ψ⟩ in the product state basis, the partitions’ own values added in rank order.
Sourcepub fn assert_invariants(&self)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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