pygsti.tools.listtools
Utility functions for working with lists
Module Contents
Functions
|
Remove duplicates from the list passed as an argument. |
|
Remove duplicates from the a list and return the result. |
A 0-based list of integers specifying which occurrence, i.e. enumerated duplicate, each list item is. |
|
|
Replace elements of t according to rules in alias_dict. |
|
Applies |
|
Applies alias_dict to the circuits in list_of_circuits. |
Iterate over all sorted (decreasing) partitions of integer n. |
|
|
Iterate over all partitions of integer n. |
|
Iterate over all partitions of integer n into nbins bins. |
|
Like itertools.product but returns the first modified (incremented) index along with the product tuple itself. |
|
Recursively replaces lists with tuples. |
- pygsti.tools.listtools.remove_duplicates_in_place(l, index_to_test=None)
Remove duplicates from the list passed as an argument.
Parameters
- llist
The list to remove duplicates from.
- index_to_testint, optional
If not None, the index within the elements of l to test. For example, if all the elements of l contain 2 tuples (x,y) then set index_to_test == 1 to remove tuples with duplicate y-values.
Returns
None
- pygsti.tools.listtools.remove_duplicates(l, index_to_test=None)
Remove duplicates from the a list and return the result.
Parameters
- literable
The list/set to remove duplicates from.
- index_to_testint, optional
If not None, the index within the elements of l to test. For example, if all the elements of l contain 2 tuples (x,y) then set index_to_test == 1 to remove tuples with duplicate y-values.
Returns
- list
the list after duplicates have been removed.
- pygsti.tools.listtools.compute_occurrence_indices(lst)
A 0-based list of integers specifying which occurrence, i.e. enumerated duplicate, each list item is.
For example, if lst = [ ‘A’,’B’,’C’,’C’,’A’] then the returned list will be [ 0 , 0 , 0 , 1 , 1 ]. This may be useful when working with DataSet objects that have collisionAction set to “keepseparate”.
Parameters
- lstlist
The list to process.
Returns
list
- pygsti.tools.listtools.find_replace_tuple(t, alias_dict)
Replace elements of t according to rules in alias_dict.
Parameters
- ttuple or list
The object to perform replacements upon.
- alias_dictdictionary
Dictionary whose keys are potential elements of t and whose values are tuples corresponding to a sub-sequence that the given element should be replaced with. If None, no replacement is performed.
Returns
tuple
- pygsti.tools.listtools.find_replace_tuple_list(list_of_tuples, alias_dict)
Applies
find_replace_tuple()
on each element of list_of_tuples.Parameters
- list_of_tupleslist
A list of tuple objects to perform replacements upon.
- alias_dictdictionary
Dictionary whose keys are potential elements of t and whose values are tuples corresponding to a sub-sequence that the given element should be replaced with. If None, no replacement is performed.
Returns
list
- pygsti.tools.listtools.apply_aliases_to_circuits(list_of_circuits, alias_dict)
Applies alias_dict to the circuits in list_of_circuits.
Parameters
- list_of_circuitslist
A list of circuits to make replacements in.
- alias_dictdict
A dictionary whose keys are layer Labels (or equivalent tuples or strings), and whose values are Circuits or tuples of labels.
Returns
list
- pygsti.tools.listtools.sorted_partitions(n)
Iterate over all sorted (decreasing) partitions of integer n.
A partition of n here is defined as a list of one or more non-zero integers which sum to n. Sorted partitions (those iterated over here) have their integers in decreasing order.
Parameters
- nint
The number to partition.
- pygsti.tools.listtools.partitions(n)
Iterate over all partitions of integer n.
A partition of n here is defined as a list of one or more non-zero integers which sum to n. Every partition is iterated over exacty once - there are no duplicates/repetitions.
Parameters
- nint
The number to partition.
- pygsti.tools.listtools.partition_into(n, nbins)
Iterate over all partitions of integer n into nbins bins.
Here, unlike in
partition()
, a “partition” is allowed to contain zeros. For example, (4,1,0) is a valid partition of 5 using 3 bins. This function fixes the number of bins and iterates over all possible length- nbins partitions while allowing zeros. This is equivalent to iterating over all usual partitions of length at most nbins and inserting zeros into all possible places for partitions of length less than nbins.Parameters
- nint
The number to partition.
- nbinsint
The fixed number of bins, equal to the length of all the partitions that are iterated over.