pub struct ResourceManager { /* private fields */ }Expand description
Tracks compiler-visible logical qubits and temporary ancillary-resource leases.
A manager is created from one circuit and must remain synchronized with that
circuit. It separates resource selection from mutation: Self::preview
returns a side-effect-free candidate, while Self::commit reserves the
selected qubits and adds any planned pre-layout logical ancillas to the
circuit. The caller must satisfy the lease’s restoration contract before
calling Self::release.
The manager records contracts and resource ownership only. It does not analyze quantum state or prove that a consuming transform restored leased qubits correctly.
Implementations§
Source§impl ResourceManager
impl ResourceManager
Sourcepub fn from_circuit(
circuit: &Circuit,
policy: ResourcePolicy,
limits: ResourceLimits,
) -> Result<Self, ResourceError>
pub fn from_circuit( circuit: &Circuit, policy: ResourcePolicy, limits: ResourceLimits, ) -> Result<Self, ResourceError>
Creates a pre-layout resource manager for the circuit’s current qubits.
Existing circuit qubits are registered as input resources. They are not
assumed to be clean at an arbitrary compiler boundary, but may later be
borrowed for a dirty request when permitted by ResourcePolicy.
The returned manager must be used with this circuit as both evolve.
§Errors
Returns ResourceError::CapacityExceeded when the input circuit
already exceeds limits, or ResourceError::CounterOverflow if an
internal manager identifier cannot be allocated.
Sourcepub fn preview(
&self,
request: &ResourceRequest,
) -> Result<ResourcePlan, ResourceError>
pub fn preview( &self, request: &ResourceRequest, ) -> Result<ResourcePlan, ResourceError>
Returns a side-effect-free resource preview for an algorithm candidate.
Preview and commit are separate so a planner can compare feasible algorithms without mutating the circuit or reserving resources. A clean request may plan fresh logical ancillas before layout. A dirty request only reuses registered resources and never plans fresh qubits.
Qubits listed in ResourceRequest::excluded are never selected. The
returned plan is tied to this manager’s current revision and becomes
stale after a successful commit, release, or phase transition.
§Errors
Returns ResourceError::InvalidRequest for malformed requests,
ResourceError::InsufficientResources when the active policy cannot
satisfy the request, ResourceError::CapacityExceeded when new clean
qubits would exceed the configured total, or
ResourceError::QubitIdOverflow when no new logical identifier can
be represented.
Sourcepub fn commit(
&mut self,
circuit: &mut Circuit,
plan: ResourcePlan,
) -> Result<ResourceLease, ResourceError>
pub fn commit( &mut self, circuit: &mut Circuit, plan: ResourcePlan, ) -> Result<ResourceLease, ResourceError>
Commits a previously previewed resource selection.
The plan must come from this manager’s current revision. Successful
commits add any planned clean logical qubits to circuit atomically,
reserve all selected qubits, and return a lease that must later be passed
to Self::release. While the lease is active, its qubits cannot be
selected by another plan.
§Errors
Returns ResourceError::ForeignPlan for a plan created by another
manager, ResourceError::StalePlan for an outdated preview, or a
consistency, phase, capacity, or counter error when the commit cannot
be applied atomically.
Sourcepub fn release(&mut self, lease: &ResourceLease) -> Result<(), ResourceError>
pub fn release(&mut self, lease: &ResourceLease) -> Result<(), ResourceError>
Releases a completed ancillary-resource lease.
The consuming algorithm must satisfy its restoration contract before calling this method. The manager records that contract but cannot prove the algorithm’s quantum semantics. Released qubits remain registered and may satisfy later requests; releasing a lease does not remove qubits from the circuit.
§Errors
Returns ResourceError::UnknownLease when the lease belongs to
another manager, has already been released, or does not match the
active record. Returns a consistency or counter error if internal
indexes cannot be updated safely.
Sourcepub fn enter_post_layout(
&mut self,
circuit: &Circuit,
) -> Result<(), ResourceError>
pub fn enter_post_layout( &mut self, circuit: &Circuit, ) -> Result<(), ResourceError>
Enters the phase where all reusable logical ancillary qubits must already be backed by a layout mapping.
The transition is one-way and requires an idle, consistent manager. After this call, previews may reuse existing compiler-allocated ancillas but may not plan fresh logical qubits.
§Errors
Returns ResourceError::InvalidPhase unless the manager is currently
pre-layout, or a consistency or idle error when the circuit is not at a
valid layout boundary.
Sourcepub fn verify_consistency(&self, circuit: &Circuit) -> Result<(), ResourceError>
pub fn verify_consistency(&self, circuit: &Circuit) -> Result<(), ResourceError>
Checks that the circuit and all resource-manager indexes agree.
This verifies structural bookkeeping only. It does not inspect quantum state or establish that active consumers will satisfy their restoration contracts.
§Errors
Returns ResourceError::CircuitResourceMismatch when a circuit
qubit, resource record, or lease index is inconsistent.
Sourcepub fn verify_idle(&self, circuit: &Circuit) -> Result<(), ResourceError>
pub fn verify_idle(&self, circuit: &Circuit) -> Result<(), ResourceError>
Checks resource indexes and requires every temporary lease to be released.
Compiler stages should use this at boundaries where no algorithm may retain temporary ancillary resources, including before entering post-layout and after resource-consuming transformations complete.
§Errors
Returns the consistency errors documented by
Self::verify_consistency, or ResourceError::ActiveLeaseRemaining
while any lease remains active.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ResourceManager
impl RefUnwindSafe for ResourceManager
impl Send for ResourceManager
impl Sync for ResourceManager
impl Unpin for ResourceManager
impl UnsafeUnpin for ResourceManager
impl UnwindSafe for ResourceManager
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.impl<T, U> Imply<T> for U
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.