Skip to content

Error Generator Propagation Module #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 112 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from 109 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
d3b5fe9
Added Propagation Code for EOC Error Generators
Feb 29, 2024
fdd689d
stim integration to pygsti
ashenmill Mar 18, 2024
9faef8a
Added Single Error Per Gate non Markovianity
ashenmill Mar 20, 2024
3f5d569
Fixed a bug in the non-markovianity code, added tutorial
ashenmill Mar 20, 2024
582787d
added layer defined errors
ashenmill Mar 20, 2024
f8d8d19
Merge branch 'develop' into feature-Propagatable-ErrorGens
sserita May 6, 2024
d19a57d
Initial commit porting over LFH code
Jun 6, 2024
5d84f78
Merge remote-tracking branch 'origin/feature-Propagatable-ErrorGens' …
Jun 7, 2024
b4a1b66
Started refactor to use dictionaries
ashenmill Jun 7, 2024
2508fef
Merge branch 'feature-Propagatable-ErrorGens' of https://github.com/p…
ashenmill Jun 7, 2024
0797425
Merge remote-tracking branch 'origin/feature-Propagatable-ErrorGens' …
Jun 7, 2024
7a5d94c
Fixed a bug in the translation code
ashenmill Jun 7, 2024
c2a8411
Merge remote-tracking branch 'origin/feature-Propagatable-ErrorGens' …
Jun 7, 2024
19a4220
Start refactors on cumulant expansion code
Jun 10, 2024
486b690
Analytic Propagation
ashenmill Jul 8, 2024
89b3fb5
Update lfhforwardsims.py
Jul 9, 2024
afef3af
Merge remote-tracking branch 'origin/feature-Propagatable-ErrorGens' …
Jul 9, 2024
0855e62
Relocate error generator propagation code
Jul 18, 2024
d537731
Merge remote-tracking branch 'origin/feature-faster-circuit-primitive…
Jul 23, 2024
3eda8c0
Initial Commit For Refactored/Reworked Error Generator Propagation
Oct 24, 2024
ad85a98
Patch broken BCH code path
Oct 24, 2024
7561277
Fix BCH bug
Oct 27, 2024
896bb9e
Attempt at completed error generator commutators
Oct 28, 2024
3d0764f
Generalize CompleteElementaryErrorgenBasis
Oct 29, 2024
27a47e9
Address basis element label ordering
Nov 5, 2024
d5f6a82
Bunch of fixes for error generator commutators
Nov 9, 2024
ac56635
Fix more errors in commutator code
Nov 9, 2024
c87500a
Random CPTP error generators
Nov 12, 2024
396c91b
Higher-order BCH Implementation
Nov 12, 2024
2424691
Support for implicit models
Nov 13, 2024
a4e811e
Menagerie of changes
Nov 13, 2024
3c68f94
Add the ability to truncate small terms in BCH
Nov 13, 2024
9bda6cd
Remove layerwise BCH implementation
Nov 18, 2024
d475c92
Unit tests
Nov 18, 2024
7efa90d
Caching and flexible errogen label types
Nov 19, 2024
ddcd9f1
Add caching for error generator coefficient dicts
Nov 20, 2024
9dcd6ae
Fix bugs introduced by new local label handling
Nov 20, 2024
e8ea6b8
Fix bugs introduced into EmbeddedOp
Nov 21, 2024
5b34194
Another EmbeddedOp bugfix
Nov 21, 2024
8406a42
Minor performance updates
Nov 21, 2024
4e64427
Error gen label hash cache
Nov 24, 2024
8767ea9
Make StateSpace more staticish
Nov 24, 2024
c8f0443
Rework circuit to stim tableau conversion
Nov 24, 2024
d2509a1
Coefficient dict performance tweaks
Nov 24, 2024
9da5f83
More Minor Tweaks
Nov 24, 2024
6eacb60
Minor bug fix
Nov 24, 2024
eaf54d7
Minor Refactors
Nov 24, 2024
b585a3e
Get rid of annoying non-determinism
Nov 24, 2024
693057c
Fifth order BCH
Nov 25, 2024
7d61350
Fix bug in circuit to stim conversion
Nov 26, 2024
bae42fd
Approximate Error Generator Probabilities
Dec 4, 2024
1653290
Checkpoint error generator composition implementation
Dec 19, 2024
b795bde
Another errorgen composition checkpoint
Dec 20, 2024
b948a18
S-H and S-S Compositions
Dec 20, 2024
0db5baf
Fix StateSpace bugs
Jan 4, 2025
4882e40
Error generator basis efficiency
Jan 4, 2025
7733720
Error generator matrix construction performance
Jan 5, 2025
4f1a8aa
Add fallback for sparse basis matrices
Jan 6, 2025
b47a9c6
Restrict specialization to unnormalized Paulis
Jan 6, 2025
d9e525b
S-C and S-A Compositions
Jan 16, 2025
668a548
Checkpoint C-H and C-S
Jan 17, 2025
cad9d3e
Minor typo fix
Jan 17, 2025
6348845
C-C Compositions
Jan 28, 2025
f7431f3
Checkpoint C-A Compositions
Jan 29, 2025
57684b3
A-C Compositions
Jan 30, 2025
57f8530
A-A Compositions
Jan 31, 2025
ea64716
Enable higher-order approximate stabilizer probs
Feb 5, 2025
f46c7e8
Minor bugfix
Feb 5, 2025
2b9ca21
Unit tests for errorgenproptools
Feb 5, 2025
6d58482
Cleanup unused code and debug statements
Feb 5, 2025
f4674ac
More unit tests
Feb 5, 2025
0f1ca5a
Clean up unneeded code
Feb 6, 2025
8a9c0f5
More Clean Up
Feb 6, 2025
ee64a04
Switch from dev to primary
Feb 6, 2025
0f208aa
third and fifth order BCH bugfix
Feb 9, 2025
d631f81
Restore previous dense error gen construction
Feb 9, 2025
c335b01
BCH approximation unit testing
Feb 9, 2025
86b4096
Additional propagation related unit tests
Feb 9, 2025
5188b1d
Minor tweak
Feb 9, 2025
ebe8b08
Spring cleaning and documentation updates
Feb 10, 2025
ef5c7be
Unit tests for random error generator gen
Feb 10, 2025
17d1f73
New test module for error generator bases
Feb 10, 2025
3ab4645
error generator label test module
Feb 11, 2025
6fe3677
Add in A-H and A-S compositions
Feb 11, 2025
99bafde
Unit test updates
Feb 11, 2025
f8c1e64
Random errorgen testing and bugfixes
Feb 12, 2025
53ccbd1
Add error generator input output map functionality
Feb 13, 2025
0e8d529
Cleanup unused code
Feb 13, 2025
e71fb77
Merge branch 'develop' into feature-errorgen-propagation-refactors
Feb 13, 2025
6d76c4a
LindbladErrorgenbugfix
Feb 13, 2025
1b51f77
Add stim dependency
Feb 13, 2025
39e8786
Errorgen Transform Map Unit Tests
Feb 13, 2025
c3d4f2a
python 3.8 compatibility
Feb 13, 2025
0498adb
Approximate pauli expectation value corrections
Feb 14, 2025
7d83da0
Local label support for EmbeddedErrorgen
Feb 14, 2025
c2e400b
Minor tweak to alpha_pauli
Feb 14, 2025
455103b
A bunch more unit tests
Feb 15, 2025
946a374
Still more testing additions
Feb 16, 2025
bc8aa0b
Clean up errant debugging
Feb 16, 2025
1544357
Misc updates and small fixes
Feb 16, 2025
2fc7d08
Checkpoint Tutorial Drafting
Feb 16, 2025
4a3506e
Finish errorgen propagation tutorial
Feb 17, 2025
d71b0f5
Temporarily disable LFH extras package
Feb 17, 2025
4a1598b
Patch random error generator rates
Feb 25, 2025
96d8311
One more random error generator patch
Feb 25, 2025
58180b1
Add ECR gate to stim conversions
Mar 5, 2025
c36ec21
Merge branch 'develop' into feature-errorgen-propagation-refactors
sserita Mar 18, 2025
b80f2d5
Finish merge for stim dependency
sserita Mar 18, 2025
2db13a1
Copyright update for new files.
sserita Mar 18, 2025
2b97517
Address Feedback
Mar 26, 2025
2f16d35
Minor test change
Apr 1, 2025
5c68539
Merge branch 'develop' into feature-errorgen-propagation-refactors
sserita Apr 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions pygsti/algorithms/randomcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,9 @@ def create_random_circuit(pspec, length, qubit_labels=None, sampler='Qeliminatio
1-element list consisting of a list of the relevant gate names (e.g., `lsargs` = ['Gi,
'Gxpi, 'Gypi', 'Gzpi']).

rand_state: RandomState, optional
A np.random.RandomState object for seeding RNG
rand_state: RandomState or int, optional (default None)
A np.random.RandomState object for seeding RNG. If an integer is passed in
this is used to set the seed for a newly constructed RNG.

Returns
-------
Expand All @@ -726,6 +727,8 @@ def create_random_circuit(pspec, length, qubit_labels=None, sampler='Qeliminatio
lsargs = []
if rand_state is None:
rand_state = _np.random.RandomState()
if isinstance(rand_state, int):
rand_state = _np.random.RandomState(rand_state)

if isinstance(sampler, str):

Expand Down
164 changes: 89 additions & 75 deletions pygsti/baseobjs/basis.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pygsti/baseobjs/basisconstructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def sizes(self, dim, sparse):
def std_matrices(matrix_dim):
"""
Get the elements of the matrix unit, or "standard", basis of matrix-dimension `matrix_dim`.
The matrices are ordered so that the row index changes the fastest.
The matrices are ordered so that the column index changes the fastest.

Constructs the standard basis spanning the density-matrix space given by
`matrix_dim` x `matrix_dim` matrices.
Expand Down
620 changes: 467 additions & 153 deletions pygsti/baseobjs/errorgenbasis.py

Large diffs are not rendered by default.

148 changes: 144 additions & 4 deletions pygsti/baseobjs/errorgenlabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,37 @@ class LocalElementaryErrorgenLabel(ElementaryErrorgenLabel):
"""
@classmethod
def cast(cls, obj, sslbls=None, identity_label='I'):
"""
Method for casting an object to an instance of LocalElementaryErrorgenLabel

Parameters
----------
obj : `LocalElementaryErrorgenLabel`, `GlobalElementaryErrorgenLabel`, str, tuple or list
Object to cast. If a `GlobalElementaryErrorgenLabel` then a value for the `sslbls`
argument should be passed with the full list of state space labels for the system.
Other castable options include:

-str: A string formatted as '<type>(<bel1>[,<bel2>])'. E.g. 'H(XX)' or
'C(X,Y)'
-tuple/list: These can be specified either in 'global-style' or 'local-style'.
- local-style: format is (<type>, <bel1>[,<bel2>])
- global-style:format is (<type>, (<bel1>,[<bel2>]), (<sslbls>))
Where sslbls above is specifically the subset of state space labels this error
generator acts on nontrivially. When specifying global-style tuple labels the sslbls kwarg of this method
which contains the complete set of state-space labels must also be specified.

sslbls : tuple or list, optional (default None)
A complete set of state space labels. Used when casting from a GlobalElementaryErrorgenLabel
or from a tuple of length 3 (wherein the final element is interpreted as the set of ssblbs the error
generator acts upon).

identity_label : str, optional (default 'I')
An optional string specifying the label used to denote the identity in basis element labels.

Returns
-------
LocalElementaryErrorgenLabel
"""
if isinstance(obj, LocalElementaryErrorgenLabel):
return obj
elif isinstance(obj, GlobalElementaryErrorgenLabel):
Expand Down Expand Up @@ -65,11 +96,37 @@ def cast(cls, obj, sslbls=None, identity_label='I'):
raise ValueError("Cannot convert %s to a local elementary errorgen label!" % str(obj))

def __init__(self, errorgen_type, basis_element_labels):
"""
Parameters
----------
errorgen_type : str
A string corresponding to the error generator sector this error generator label is
an element of. Allowed values are 'H', 'S', 'C' and 'A'.

basis_element_labels : tuple or list
A list or tuple of strings labeling basis elements used to label this error generator.
This is either length-1 for 'H' and 'S' type error generators, or length-2 for 'C' and 'A'
type.
"""
#TODO: Store non-standard identity labels with object so we don't need to specify this in
#support_indices.
self.errorgen_type = str(errorgen_type)
self.basis_element_labels = tuple(basis_element_labels)
self._hash = hash((self.errorgen_type, self.basis_element_labels))

def __hash__(self):
return hash((self.errorgen_type, self.basis_element_labels))
return self._hash

#pickle management functions
def __getstate__(self):
state_dict = self.__dict__
return state_dict

def __setstate__(self, state_dict):
for k, v in state_dict.items():
self.__dict__[k] = v
#reinitialize the hash
self._hash = hash((self.errorgen_type, self.basis_element_labels))

def __eq__(self, other):
return (self.errorgen_type == other.errorgen_type
Expand All @@ -80,6 +137,16 @@ def __str__(self):

def __repr__(self):
return str((self.errorgen_type, self.basis_element_labels))

def support_indices(self, identity_label='I'):
"""
Returns a sorted tuple of the elements of indices of the nontrivial basis
element label entries for this label.
"""
nonidentity_indices = [i for i in range(len(self.basis_element_labels[0]))
if any([bel[i] != identity_label for bel in self.basis_element_labels])]

return tuple(nonidentity_indices)


class GlobalElementaryErrorgenLabel(ElementaryErrorgenLabel):
Expand All @@ -91,7 +158,47 @@ class GlobalElementaryErrorgenLabel(ElementaryErrorgenLabel):

@classmethod
def cast(cls, obj, sslbls=None, identity_label='I'):
""" TODO: docstring - lots in this module """
"""
Method for casting an object to an instance of GlobalElementaryErrorgenLabel

Parameters
----------
obj : `GlobalElementaryErrorgenLabel`, `LocalElementaryErrorgenLabel`, tuple or list
Object to cast. If a `LocalElementaryErrorgenLabel` then a value for the `sslbls`
argument should be passed with the full list of state space labels for the system.
Other castable options include:

-str: Following formatting options are supported.
- A string formatted as '<type>(<bel1>[,<bel2>]:(<sslbls>))' where <sslbls>
is the subset of state-space labels this error generator acts on nontrivially
specified as a comma-separated list. E.g. 'H(XX:0,1)' or 'S(XIY):0,2'.
- A string formatted as <type><bel>:<sslbls>, where <sslbls>
is the subset of state-space labels this error generator acts on nontrivially
specified as a comma-separated list. E.g. 'HXX:0,1' or 'SIX:1'. Note this style
is only compatible with basis element label error generators, and this only H and S.
- A string formatted as <type><bel>. For this style the basis element label
is assumed to correspond to the entire state space, and as such the sslbls kwarg
for this method must also be specified. Like the previous example this is also
only compatible with H and S terms.
-tuple/list: These can be specified either in 'global-style' or 'local-style'.
- local-style: format is (<type>, <bel1>[,<bel2>])
- global-style:format is (<type>, (<bel1>,[<bel2>]), (<sslbls>))
Where sslbls above is specifically the subset of state space labels this error
generator acts on nontrivially. When specifying global-style tuple labels the sslbls kwarg of this method
which contains the complete set of state-space labels must also be specified.

sslbls : tuple or list, optional (default None)
A complete set of state space labels. Used when casting from a LocalElementaryErrorgenLabel
or from a tuple of length 2 (wherein the final element is interpreted as the set of ssblbs the error
generator acts upon).

identity_label : str, optional (default 'I')
An optional string specifying the label used to denote the identity in basis element labels.

Returns
-------
GlobalElementaryErrorgenLabel
"""
if isinstance(obj, GlobalElementaryErrorgenLabel):
return obj
elif isinstance(obj, LocalElementaryErrorgenLabel):
Expand All @@ -116,7 +223,7 @@ def cast(cls, obj, sslbls=None, identity_label='I'):
return cls.cast(LocalElementaryErrorgenLabel.cast(obj), sslbls, identity_label)
else: # no parenthesis, assume of form "HXX:Q0,Q1" or local label, e.g. "HXX"
if ':' in obj:
typ_bel_str, sslbl_str = in_parens.split(':')
typ_bel_str, sslbl_str = obj.split(':')
sslbls = [_to_int_or_strip(x) for x in sslbl_str.split(',')]
return cls(typ_bel_str[0], (typ_bel_str[1:],), sslbls)
else: # treat as a local label
Expand All @@ -132,6 +239,27 @@ def cast(cls, obj, sslbls=None, identity_label='I'):
raise ValueError("Cannot convert %s to a global elementary errorgen label!" % str(obj))

def __init__(self, errorgen_type, basis_element_labels, sslbls, sort=True):
"""
Parameters
----------
errorgen_type : str
A string corresponding to the error generator sector this error generator label is
an element of. Allowed values are 'H', 'S', 'C' and 'A'.

basis_element_labels : tuple or list
A list or tuple of strings labeling basis elements used to label this error generator.
This is either length-1 for 'H' and 'S' type error generators, or length-2 for 'C' and 'A'
type.

sslbls : tuple or list
A tuple or list of state space labels corresponding to the qudits upon which this error generator
is supported.

sort : bool, optional (default True)
If True then the input state space labels are first sorted, and then the used basis element labels
are sorted to match the order to the newly sorted state space labels.
"""

if sort:
sorted_indices, sslbls = zip(*sorted(enumerate(sslbls), key=lambda x: x[1]))
basis_element_labels = [''.join([bel[i] for i in sorted_indices]) for bel in basis_element_labels]
Expand All @@ -141,9 +269,21 @@ def __init__(self, errorgen_type, basis_element_labels, sslbls, sort=True):
self.sslbls = tuple(sslbls)
# Note: each element of basis_element_labels must be an iterable over
# 1-qubit basis labels of length len(self.sslbls) (?)
self._hash = hash((self.errorgen_type, self.basis_element_labels, self.sslbls))

def __hash__(self):
return hash((self.errorgen_type, self.basis_element_labels, self.sslbls))
return self._hash

#pickle management functions
def __getstate__(self):
state_dict = self.__dict__
return state_dict

def __setstate__(self, state_dict):
for k, v in state_dict.items():
self.__dict__[k] = v
#reinitialize the hash
self._hash = hash((self.errorgen_type, self.basis_element_labels, self.sslbls))

def __eq__(self, other):
return (self.errorgen_type == other.errorgen_type
Expand Down
Loading