Skip to main content

Parameters

Struct Parameters 

Source
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

Source

pub fn new(num_slots: usize) -> Self

Declare num_slots slots with no links yet.

Build from explicit links over a vector of num_slots entries.

Source

pub fn with_names<I, S>(self, names: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Name the slots, in slot order. Names are what OpenQASM input declarations carry and what export emits.

§Panics

Panics if names is not exactly num_slots long.

Source

pub fn name_of(&self, slot: usize) -> Option<&str>

Name of slot, or None when the set is positional only.

Source

pub fn slot_of(&self, name: &str) -> Option<usize>

Slot a name refers to.

Source

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.

Source

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.

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.

Source

pub fn num_slots(&self) -> usize

Length of the value vector bind expects.

Source

pub fn is_empty(&self) -> bool

True when no instruction is linked. A set may still declare slots.

Source

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.

Source

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.

Source

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.

Source

pub fn bind_into( &self, template: &Circuit, values: &[f64], out: &mut Circuit, ) -> Result<()>

Bind into an existing circuit, reusing its allocations.

out is overwritten with template and then patched, so a sweep can hold one buffer across every point instead of allocating per binding.

§Errors

Same conditions as bind.

Source

pub fn values(&self, circuit: &Circuit) -> Result<Vec<f64>>

Read the angle each slot currently holds in circuit.

§Errors

Same conditions as validate, which this runs first because a link pointing at a non-angle gate has no value to read.

Trait Implementations§

Source§

impl Clone for Parameters

Source§

fn clone(&self) -> Parameters

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Parameters

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Parameters

Source§

fn default() -> Parameters

Returns the “default value” for a type. Read more
Source§

impl Eq for Parameters

Source§

impl PartialEq for Parameters

Source§

fn eq(&self, other: &Parameters) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Parameters

Auto Trait Implementations§

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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

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

Source§

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

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V