LocalOps

Struct LocalOps 

Source
pub struct LocalOps<T: FloatExt + Hash> {
    pub interval: (usize, usize),
    pub padding: RankOneTwo<T>,
    pub idx_to_mat: BTreeMap<usize, RankOneTwo<T>>,
}
Expand description

Represents a tensor product of local 2×2 complex operators acting on specific qubit indices.

This structure encodes a sparse tensor product of single-qubit operators. Each mapped entry specifies a RankOneTwo<T> acting on a particular qubit index. The full operator is constructed as an ordered tensor product over a specified interval of qubit indices. Indices not explicitly mapped use the provided padding operator.

This is useful for compactly representing structured operators such as Kraus operators.

Fields§

§interval: (usize, usize)

Inclusive interval of qubit indices spanned by the tensor product: [start, end].

§padding: RankOneTwo<T>

Default RankOneTwo<T> used for unmapped qubit indices within the interval.

§idx_to_mat: BTreeMap<usize, RankOneTwo<T>>

Mapping from selected qubit indices to non-default local operators.

Implementations§

Source§

impl<T: FloatExt + Hash> LocalOps<T>

Source

pub fn indices_keys(&self) -> Vec<usize>

Returns the list of qubit indices that have explicitly assigned RankOneTwo.

Source

pub fn try_interval(&self) -> (Option<usize>, Option<usize>)

Returns the inclusive interval of explicitly assigned qubit indices, if any.

This is equivalent to (min_index, max_index) over the idx_to_mix map. Returns (None, None) if the map is empty.

Source

pub fn try_fit_interval(&self) -> Option<Self>

Returns a new LocalOps with its interval adjusted to match the minimum and maximum keys present in the idx_to_mat map.

This method is useful for automatically syncing the interval field with the actual span of explicitly defined qubit indices.

§Returns
  • Some(Self) with the updated interval if idx_to_mat is non-empty.
  • None if idx_to_mat is empty, as there are no keys to determine an interval.
Source

pub fn extract_padding(&self) -> Self

Returns a new LocalOps where all indices in the interval are explicitly filled.

For any index within self.interval that does not appear in idx_to_mat, this method inserts an entry with the padding value. The result is a fully populated BTreeMap with no missing indices in the defined interval.

Source

pub fn set_interval(&self, interval: (usize, usize)) -> Self

Returns a new LocalOps with the specified interval, leaving all other fields unchanged.

This method updates the interval field while cloning the existing padding and idx_to_mat map.

Source

pub fn set_padding(&self, padding: RankOneTwo<T>) -> Self

Returns a new LocalOps with the specified padding value, leaving the interval and index-to-mat map unchanged.

Source

pub fn discard<I: IntoIterator<Item = usize>>(&self, indices: I) -> Self

Returns a new LocalOps with the specified indices removed from idx_to_mat.

This method creates a copy of the current structure and removes any entries whose keys match the provided indices. The original interval and padding are preserved.

§Type Parameters
  • I: An iterable collection of usize indices to remove.
§Arguments
  • indices: Any iterable over usize values (e.g., a Vec, array, range, or HashSet).
§Returns

A new LocalOps with the specified indices removed from the map.

§Examples
//let pruned = original.discard(vec![1, 2, 4]);
//let pruned = original.discard([3, 5, 7]);
//let pruned = original.discard(0..=10);
Source

pub fn extend(&self, idx_to_mat: BTreeMap<usize, RankOneTwo<T>>) -> Self

Returns a new LocalOps with additional entries merged into idx_to_mat.

For each (index, RankOneTwo<T>) in the provided idx_to_mat map, if the index is not already present in the current map, it is inserted. Existing entries are left unchanged.

The resulting interval is updated to span the full range of indices in the combined map, unless the map becomes empty, in which case the original interval is retained.

§Arguments
  • idx_to_mat - A BTreeMap<usize, RankOneTwo<T>> containing new entries to insert.
§Returns

A new LocalOps with the merged map and updated interval.

Source

pub fn force_update(&self, idx_to_mat: BTreeMap<usize, RankOneTwo<T>>) -> Self

Returns a new LocalOps with the given entries forcibly updated.

For each (index, RankOneTwo<T>) in the provided map:

  • Any existing entry at that index is removed.
  • The new entry is inserted unconditionally.

The updated idx_to_mat map reflects all changes, and the interval is recomputed to span the full range of keys present in the new map (if non-empty).

§Arguments
  • idx_to_mat - A BTreeMap<usize, RankOneTwo<T>> containing entries to overwrite.
§Returns

A new LocalOps with the forcibly updated entries and recalculated interval.

Source

pub fn swap(&self, i: usize, j: usize) -> Self

Returns a new LocalOps with the values at two indices swapped.

If both indices exist in idx_to_mat, their values are swapped. If only one exists, its value is moved to the other index. If neither exist, the mapping is unchanged.

§Arguments
  • i - The first index.
  • j - The second index.

Trait Implementations§

Source§

impl<T: Clone + FloatExt + Hash> Clone for LocalOps<T>

Source§

fn clone(&self) -> LocalOps<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + FloatExt + Hash> Debug for LocalOps<T>

Source§

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

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

impl<T: Hash + FloatExt + Hash> Hash for LocalOps<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq + FloatExt + Hash> PartialEq for LocalOps<T>

Source§

fn eq(&self, other: &LocalOps<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq + FloatExt + Hash> Eq for LocalOps<T>

Source§

impl<T: FloatExt + Hash> StructuralPartialEq for LocalOps<T>

Auto Trait Implementations§

§

impl<T> Freeze for LocalOps<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for LocalOps<T>
where T: RefUnwindSafe,

§

impl<T> Send for LocalOps<T>
where T: Send,

§

impl<T> Sync for LocalOps<T>
where T: Sync,

§

impl<T> Unpin for LocalOps<T>
where T: Unpin,

§

impl<T> UnwindSafe for LocalOps<T>

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> 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> 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> 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 = 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.