Skip to content

Bugfix reparameterize #480

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 36 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
627ec20
povm convert fixed for fullTP->GLND, missing CPTPLND considerations
juangmendoza19 Jul 16, 2024
484fe3e
full TP -> GLND reparam now avoids dumb-gauge, minimizes 2norm
juangmendoza19 Aug 8, 2024
6365db8
bypass our changes if reparam is not full TP -> GLND
juangmendoza19 Aug 16, 2024
246623e
removed magic numbers, adapted for arbitrary number of qubits
juangmendoza19 Aug 22, 2024
d4fd818
removed temp files
juangmendoza19 Aug 22, 2024
167d742
removed magic numbers from povm convert, and added a check if there i…
juangmendoza19 Aug 23, 2024
c6ec19f
commented povm file
juangmendoza19 Sep 4, 2024
2bf56d6
commented state file
juangmendoza19 Sep 4, 2024
0ec92dd
started implementing CPTPLND compatibility with set_all_parameterization
juangmendoza19 Sep 26, 2024
b769193
added support for converting to and from many other models. Tested th…
juangmendoza19 Dec 17, 2024
e8232b3
made cptp_penalty an optional argument, made it 1e-7 accross all inst…
juangmendoza19 Dec 17, 2024
5425f61
Merge remote-tracking branch 'origin/develop' into bugfix-reparameterize
juangmendoza19 Dec 18, 2024
d70fe7d
using proper warning library, started unit tests
juangmendoza19 Jan 3, 2025
51d75a5
unit test for process matrices in reparameterization added
juangmendoza19 Jan 6, 2025
d39ea28
fixed assert syntax
juangmendoza19 Jan 6, 2025
32970ff
fixed small bug in errgen parameter counting, now forward sim tests a…
juangmendoza19 Feb 20, 2025
6786b14
fixed warning bug in povm convert code
juangmendoza19 Feb 20, 2025
933425b
added proper criteria to test parameterization change
juangmendoza19 Feb 20, 2025
a737603
added comment to remember to add more tests in the future
juangmendoza19 Feb 20, 2025
16c7259
added param counting back to unit test
juangmendoza19 Feb 21, 2025
60e2673
removed incorrect formula use for errgen model unit test
juangmendoza19 Feb 21, 2025
abaff72
Merge branch 'develop' into bugfix-reparameterize
juangmendoza19 Feb 21, 2025
ad4b6ad
removed check for old cvxpy
juangmendoza19 Feb 21, 2025
7825c1b
added unit tests for parameterization changes starting from a GLND model
juangmendoza19 Feb 21, 2025
18b9294
implemented Corey's requests for the PR
juangmendoza19 Feb 24, 2025
482e86e
implemented Stefan's PR requests and cleaned up init.py s a little
juangmendoza19 May 22, 2025
085188f
accepted label code from develop, although I believe it is still caus…
juangmendoza19 May 22, 2025
d962130
applied many PR change requests made by Riley
juangmendoza19 May 23, 2025
e645650
final Riley PR suggestion regarding nontrivial singular vectors
juangmendoza19 May 23, 2025
a3d879f
fixed some parenthesis for multiplications in test file
juangmendoza19 May 26, 2025
5c1c42f
removed debug print
juangmendoza19 May 26, 2025
d449c05
fixed problem with SV masking shape
juangmendoza19 May 26, 2025
f94ce11
changed perturbation value that computes SPAM physical subspace. Any …
juangmendoza19 May 27, 2025
9d7b4cf
cleaned up some leftover debugging code
juangmendoza19 May 27, 2025
c90803d
compactified code for non trivial vectors
juangmendoza19 May 27, 2025
9cb066c
removed null space vectors from svd to make dimensions match
juangmendoza19 May 27, 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
10 changes: 5 additions & 5 deletions pygsti/modelmembers/povms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def convert(povm, to_type, basis, ideal_povm=None, flatten_structure=False, cp_p
#It is often the case that there are more error generators than physical degrees of freedom in the POVM
#We define a function which finds linear comb. of errgens that span these degrees of freedom.
#This has been called "the trivial gauge", and this function is meant to avoid it
def calc_physical_subspace(dense_ideal_povm, epsilon = 1e-9):
def calc_physical_subspace(dense_ideal_povm, epsilon = 1e-4):

degrees_of_freedom = (dense_ideal_povm.shape[0] - 1) * dense_ideal_povm.shape[1]
errgen = _LindbladErrorgen.from_error_generator(povm.state_space.dim, parameterization=to_type)
Expand Down Expand Up @@ -578,11 +578,11 @@ def calc_physical_subspace(dense_ideal_povm, epsilon = 1e-9):
J[:,i] = vectorized_povm

_,S,Vt = _np.linalg.svd(J)

#Only return nontrivial singular vectors
non_zero_mask = _np.abs(S) > 1e-13
non_trivial_vecs = Vt[non_zero_mask]
non_trivial_vecs = non_trivial_vecs.reshape(-1, Vt.shape[1]) # Reshape to ensure it's 2D
return non_trivial_vecs
Vt = Vt[S > 1e-13, :].reshape((-1, Vt.shape[1]))
return Vt


phys_directions = calc_physical_subspace(dense_ideal_povm)

Expand Down
8 changes: 3 additions & 5 deletions pygsti/modelmembers/states/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def convert(state, to_type, basis, ideal_state=None, flatten_structure=False, cp

#GLND for states suffers from "trivial gauge" freedom. This function identifies
#the physical directions to avoid this gauge.
def calc_physical_subspace(ideal_prep, epsilon = 1e-9):
def calc_physical_subspace(ideal_prep, epsilon = 1e-4):
errgen = _LindbladErrorgen.from_error_generator(2**(2*num_qubits), parameterization=to_type)
num_errgens = errgen.num_params

Expand All @@ -289,10 +289,8 @@ def calc_physical_subspace(ideal_prep, epsilon = 1e-9):
_,S,Vt = _np.linalg.svd(J)

#Only return nontrivial singular vectors
non_zero_mask = _np.abs(S) > 1e-13
non_trivial_vecs = Vt[non_zero_mask]
non_trivial_vecs = non_trivial_vecs.reshape(-1, Vt.shape[1]) # Reshape to ensure it's 2D
return non_trivial_vecs
Vt = Vt[S > 1e-13, :].reshape((-1, Vt.shape[1]))
return Vt

phys_directions = calc_physical_subspace(dense_state)

Expand Down
4 changes: 2 additions & 2 deletions pygsti/models/explicitmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ def convert_members_inplace(self, to_type, categories_to_convert='all', labels_t
for lbl, prep in self.preps.items():
if labels_to_convert == 'all' or lbl in labels_to_convert:
ideal = ideal_model.preps.get(lbl, None) if (ideal_model is not None) else None
self.preps[lbl] = _state.convert(prep, to_type, self.basis, spam_cp_penalty, ideal, flatten_structure)
self.preps[lbl] = _state.convert(prep, to_type, self.basis, ideal, flatten_structure, cp_penalty=spam_cp_penalty)
if any([c in categories_to_convert for c in ('all', 'povms')]):
for lbl, povm in self.povms.items():
if labels_to_convert == 'all' or lbl in labels_to_convert:
ideal = ideal_model.povms.get(lbl, None) if (ideal_model is not None) else None
self.povms[lbl] = _povm.convert(povm, to_type, self.basis, spam_cp_penalty, ideal, flatten_structure)
self.povms[lbl] = _povm.convert (povm, to_type, self.basis, ideal, flatten_structure, cp_penalty=spam_cp_penalty)

self._clean_paramvec() # param indices were probabaly updated
if set_default_gauge_group:
Expand Down
8 changes: 4 additions & 4 deletions test/unit/objects/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,15 @@ def setUpClass(cls):
cls.gatestring1 = ('Gx', 'Gy')
cls.gatestring2 = ('Gx', 'Gy', 'Gy')
cls._expected_probs = {
cls.gatestring1: np.transpose(cls._model.povms['Mdefault']['0'].to_dense()) @
cls.gatestring1: (np.transpose(cls._model.povms['Mdefault']['0'].to_dense()) @
cls._model['Gy'].to_dense() @
cls._model['Gx'].to_dense() @
cls._model.preps['rho0'].to_dense().reshape(-1)[0],
cls.gatestring2: np.transpose(cls._model.povms['Mdefault']['0'].to_dense()) @
cls._model.preps['rho0'].to_dense()).reshape(-1)[0],
cls.gatestring2: (np.transpose(cls._model.povms['Mdefault']['0'].to_dense()) @
cls._model['Gy'].to_dense() @
cls._model['Gy'].to_dense() @
cls._model['Gx'].to_dense() @
cls._model.preps['rho0'].to_dense().reshape(-1)[0]
cls._model.preps['rho0'].to_dense()).reshape(-1)[0]
}
# TODO expected dprobs & hprobs

Expand Down
Loading
Loading