Skip to content

model.is_equivalent() not functional for full TP models #600

@juangmendoza19

Description

@juangmendoza19

Describe the bug
the comparator method for OpModels "is_equivalent()" does not work for 'full TP' models

To Reproduce
from pygsti.modelpacks import smq1Q_XY as std
std.target_model("full TP").is_equivalent(std.target_model("full TP"))

Expected behavior
The code above should yield True. Instead it yields the error:

RuntimeError Traceback (most recent call last)
Cell In[9], line 1
----> 1 std.target_model("full TP").is_equivalent(std.target_model("full TP"))

File ~/Documents/AMS-gitlab/fogi-automated-model-selection/AMS-2qubit/updatedpyGSTi/pyGSTi/pygsti/models/model.py:2392, in OpModel.is_equivalent(self, other_model, rtol, atol)
2390 mmg = self.create_modelmember_graph()
2391 other_mmg = other_model.create_modelmember_graph()
-> 2392 return mmg.is_equivalent(other_mmg, rtol, atol)

File ~/Documents/AMS-gitlab/fogi-automated-model-selection/AMS-2qubit/updatedpyGSTi/pyGSTi/pygsti/modelmembers/modelmembergraph.py:115, in ModelMemberGraph.is_equivalent(self, other, rtol, atol)
99 def is_equivalent(self, other, rtol=1e-5, atol=1e-8):
100 """Comparator between two ModelMemberGraph objects for structure and values.
101
102 Parameters
(...) 113 True if similar_to AND parameter vectors match
114 """
--> 115 return self._dfs_comparison(other, True, rtol, atol)

File ~/Documents/AMS-gitlab/fogi-automated-model-selection/AMS-2qubit/updatedpyGSTi/pyGSTi/pygsti/modelmembers/modelmembergraph.py:159, in ModelMemberGraph._dfs_comparison(self, other, check_params, rtol, atol)
157 for lbl, node1 in self.mm_nodes[mm_type].items():
158 node2 = other.mm_nodes[mm_type][lbl]
--> 159 if not dfs_compare(node1, node2):
160 return False
162 # If here, everything checks out

File ~/Documents/AMS-gitlab/fogi-automated-model-selection/AMS-2qubit/updatedpyGSTi/pyGSTi/pygsti/modelmembers/modelmembergraph.py:138, in ModelMemberGraph._dfs_comparison..dfs_compare(node1, node2)
136 def dfs_compare(node1, node2):
137 if check_params:
--> 138 if not node1.mm.is_equivalent(node2.mm, rtol, atol): return False
139 else:
140 if not node1.mm.is_similar(node2.mm, rtol, atol): return False

File ~/Documents/AMS-gitlab/fogi-automated-model-selection/AMS-2qubit/updatedpyGSTi/pyGSTi/pygsti/modelmembers/modelmember.py:868, in ModelMember.is_equivalent(self, other, rtol, atol)
864 if len(self.submembers()) != len(other.submembers()): return False
865 for sm1, sm2 in zip(self.submembers(), other.submembers()):
866 # Technically calling is_equivalent here is extra type check work,
867 # but this is safer in case is_equivalent is overloaded in derived classes
--> 868 if not sm1.is_equivalent(sm2): return False
870 return True

File ~/Documents/AMS-gitlab/fogi-automated-model-selection/AMS-2qubit/updatedpyGSTi/pyGSTi/pygsti/modelmembers/modelmember.py:860, in ModelMember.is_equivalent(self, other, rtol, atol)
835 """
836 Comparator returning whether two ModelMembers are equivalent.
837
(...) 856 True if structure AND parameter vectors match
857 """
858 if not self.is_similar(other): return False
--> 860 if not _np.allclose(self.to_vector(), other.to_vector(), rtol=rtol, atol=atol):
861 return False
863 # Recursive check on submembers

File ~/Documents/AMS-gitlab/fogi-automated-model-selection/AMS-2qubit/updatedpyGSTi/pyGSTi/pygsti/modelmembers/povms/complementeffect.py:142, in ComplementPOVMEffect.to_vector(self)
137 def to_vector(self):
138 msg = """
139 ComplementPOVMEffect.to_vector() should never be called.
140 Use use TPPOVM.to_vector() instead.
141 """
--> 142 raise RuntimeError(msg)

RuntimeError:
ComplementPOVMEffect.to_vector() should never be called.
Use use TPPOVM.to_vector() instead.
Environment (please complete the following information):

  • pyGSTi version 0.9.13.1
  • python version 3.13.5
  • OS MacOS Sequoia 15.5

Metadata

Metadata

Labels

bugA bug or regression

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions