pyGSTi
pyGSTi copied to clipboard
Fiducial generation does not work with pspec-generated explicit models
Describe the bug When attempting to generate fiducials based on a target model generated from a processor specification, I get a matrix size error.
To Reproduce
import pygsti
import pygsti.algorithms.fiducialselection as fidsel
pspec = pygsti.processors.QubitProcessorSpec(1, ['Gxpi2', 'Gypi2'])
target_model = pygsti.models.create_explicit_model(pspec)
prepFiducials, measFiducials = fidsel.find_fiducials(target_model)
gives
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [4], in <cell line: 6>()
4 pspec = pygsti.processors.QubitProcessorSpec(1, ['Gxpi2', 'Gypi2'])
5 target_model = pygsti.models.create_explicit_model(pspec)
----> 6 prepFiducials, measFiducials = fidsel.find_fiducials(target_model)
File ~/repos/pyGSTi/pygsti/algorithms/fiducialselection.py:100, in find_fiducials(target_model, omit_identity, eq_thresh, ops_to_omit, force_empty, max_fid_length, algorithm, algorithm_kwargs, verbosity)
97 Identity = _np.identity(target_model.dim, 'd')
99 for gate in fidOps:
--> 100 if frobeniusdist_squared(target_model.operations[gate], Identity) < eq_thresh:
101 fidOps.remove(gate)
103 availableFidList = _circuits.list_all_circuits(fidOps, 0, max_fid_length)
File ~/repos/pyGSTi/pygsti/tools/optools.py:154, in frobeniusdist_squared(a, b)
133 def frobeniusdist_squared(a, b):
134 """
135 Returns the square of the frobenius distance between gate or density matrices.
136
(...)
152 The resulting frobenius distance.
153 """
--> 154 return _mt.frobeniusnorm_squared(a - b)
File ~/repos/pyGSTi/pygsti/modelmembers/operations/denseop.py:237, in DenseOperatorInterface.__sub__(self, x)
--> 237 def __sub__(self, x): return self._ptr - x
ValueError: operands could not be broadcast together with shapes (2,2) (4,4)
Expected behavior I expected the fiducial sequences to be generated.
Environment (please complete the following information):
- pyGSTi version [0.9.10.1]
- python version [3.10.4]
- OS [MacOS 12.3.1]
Additional context
Note that this issue appears to be due to something going on with the shape method on StaticUnitaryOp
objects:
print(target_model.operations[('Gxpi2','0')].shape)
gives (2,2)
, but
print(target_model.operations[('Gxpi2','0')].to_dense().shape)
gives (4,4)
(expected).
TL;DR: Use the line target_model = pygsti.models.create_explicit_model(pspec, ideal_gate_type='TP')
instead.
More details: Building a model from pspecs defaults to storing the operations as unitaries. However, fiducial/germ selection algorithms expect the model to be superoperators, and we actually usually use the TP parameterization most of the time (although other superoperator parameterizations like 'full'
should also work).
Probably the only necessary bugfix here is a better error message.
@sserita , thank you! This makes sense to me. Are there any other switches that I should be aware of to get the pspec-created explicit models to behave the same as the expression-created explicit models?
No I think the default gate parameterization is the biggest difference. Technically the expression-created models have a "full"
parameterization, but for fid/germ selection, "TP"
is the better parameterization (so if you are using the expression-created model function, I would actually recommend using the gate_type="TP"
kwarg as well).
An error message has been added to suggest the correct model parameterization, will be included in the next release.
Closed as this is now in 0.9.11 release