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>
impl<T: FloatExt + Hash> LocalOps<T>
Sourcepub fn indices_keys(&self) -> Vec<usize>
pub fn indices_keys(&self) -> Vec<usize>
Returns the list of qubit indices that have explicitly assigned RankOneTwo.
Sourcepub fn try_interval(&self) -> (Option<usize>, Option<usize>)
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.
Sourcepub fn try_fit_interval(&self) -> Option<Self>
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 ifidx_to_matis non-empty.Noneifidx_to_matis empty, as there are no keys to determine an interval.
Sourcepub fn extract_padding(&self) -> Self
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.
Sourcepub fn set_interval(&self, interval: (usize, usize)) -> Self
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.
Sourcepub fn set_padding(&self, padding: RankOneTwo<T>) -> Self
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.
Sourcepub fn discard<I: IntoIterator<Item = usize>>(&self, indices: I) -> Self
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 ofusizeindices to remove.
§Arguments
indices: Any iterable overusizevalues (e.g., aVec, array, range, orHashSet).
§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);Sourcepub fn extend(&self, idx_to_mat: BTreeMap<usize, RankOneTwo<T>>) -> Self
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- ABTreeMap<usize, RankOneTwo<T>>containing new entries to insert.
§Returns
A new LocalOps with the merged map and updated interval.
Sourcepub fn force_update(&self, idx_to_mat: BTreeMap<usize, RankOneTwo<T>>) -> Self
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- ABTreeMap<usize, RankOneTwo<T>>containing entries to overwrite.
§Returns
A new LocalOps with the forcibly updated entries and recalculated interval.
Sourcepub fn swap(&self, i: usize, j: usize) -> Self
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.