pub struct Parameters { /* private fields */ }Expand description
Parameter slots over the rotation angles of a circuit.
A slot may drive several instructions (weight sharing): bind
writes one angle to each, and the adjoint gradient accumulates their
contributions into one entry. Arity is declared at construction rather than
inferred from the links, so a value vector of the wrong length is rejected
even when the trailing slots carry no link.
Bindable gates are Rx, Ry, Rz, Rzz, P, and PauliRot, the Gate
variants carrying a rotation angle.
Implementations§
Source§impl Parameters
impl Parameters
Sourcepub fn from_links(links: Vec<ParamLink>, num_slots: usize) -> Self
pub fn from_links(links: Vec<ParamLink>, num_slots: usize) -> Self
Build from explicit links over a vector of num_slots entries.
Sourcepub fn with_names<I, S>(self, names: I) -> Self
pub fn with_names<I, S>(self, names: I) -> Self
Sourcepub fn name_of(&self, slot: usize) -> Option<&str>
pub fn name_of(&self, slot: usize) -> Option<&str>
Name of slot, or None when the set is positional only.
Sourcepub fn pinned_to(self, circuit: &Circuit) -> Self
pub fn pinned_to(self, circuit: &Circuit) -> Self
Record the gate kind and targets each link points at, so a later
validate against an edited circuit fails loudly
rather than binding the wrong gates.
Sourcepub fn all_rotations(circuit: &Circuit) -> Self
pub fn all_rotations(circuit: &Circuit) -> Self
Give every bindable gate its own slot, in circuit order. The common case for a variational ansatz where each rotation is independent.
Sourcepub fn link(&mut self, instruction: usize, slot: usize)
pub fn link(&mut self, instruction: usize, slot: usize)
Record that instruction reads slot.
§Panics
Panics if slot is not below the declared slot count. Slot bounds are
fixed when the set is constructed, so an out-of-range slot is a caller
bug rather than bad input.
pub fn links(&self) -> &[ParamLink]
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
True when no instruction is linked. A set may still declare slots.
Sourcepub fn validate(&self, circuit: &Circuit) -> Result<()>
pub fn validate(&self, circuit: &Circuit) -> Result<()>
Check every link against circuit without binding.
A declared slot that no instruction reads is accepted: OpenQASM allows an
input the body never uses, and a sweep may range over a superset of the
circuit’s parameters. Use unread_slots to report
them.
§Errors
Returns PrismError::InvalidParameter when a link points past the end
of the instruction stream, at a non-gate instruction, or at a gate
carrying no angle.
Sourcepub fn unread_slots(&self) -> Vec<usize>
pub fn unread_slots(&self) -> Vec<usize>
Declared slots that no instruction reads, whose bound values are discarded. Legal, but usually a mistake worth surfacing.
Sourcepub fn bind(&self, template: &Circuit, values: &[f64]) -> Result<Circuit>
pub fn bind(&self, template: &Circuit, values: &[f64]) -> Result<Circuit>
Write values into a copy of template.
§Errors
Returns PrismError::InvalidParameter when values.len() differs from
num_slots, when any value is not finite, or when
validate rejects the links.
Trait Implementations§
Source§impl Clone for Parameters
impl Clone for Parameters
Source§fn clone(&self) -> Parameters
fn clone(&self) -> Parameters
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Parameters
impl Debug for Parameters
Source§impl Default for Parameters
impl Default for Parameters
Source§fn default() -> Parameters
fn default() -> Parameters
impl Eq for Parameters
Source§impl PartialEq for Parameters
impl PartialEq for Parameters
impl StructuralPartialEq for Parameters
Auto Trait Implementations§
impl Freeze for Parameters
impl RefUnwindSafe for Parameters
impl Send for Parameters
impl Sync for Parameters
impl Unpin for Parameters
impl UnsafeUnpin for Parameters
impl UnwindSafe for Parameters
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more