Skip to content
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

Fiducial generation does not work with pspec-generated explicit models #246

Closed
johnkgamble opened this issue May 25, 2022 · 5 comments
Closed
Labels
bug A bug or regression

Comments

@johnkgamble
Copy link
Contributor

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).

@johnkgamble johnkgamble added the bug A bug or regression label May 25, 2022
@sserita
Copy link
Contributor

sserita commented May 25, 2022

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.

@johnkgamble
Copy link
Contributor Author

@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?

@sserita
Copy link
Contributor

sserita commented May 27, 2022

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).

@sserita
Copy link
Contributor

sserita commented May 1, 2023

An error message has been added to suggest the correct model parameterization, will be included in the next release.

@sserita sserita added the fixed-but-not-in-release-yet Bug has been fixed, but isn't in an official release yet (just exists on a development branch) label May 1, 2023
@sserita
Copy link
Contributor

sserita commented May 17, 2023

Closed as this is now in 0.9.11 release

@sserita sserita closed this as completed May 17, 2023
@sserita sserita removed the fixed-but-not-in-release-yet Bug has been fixed, but isn't in an official release yet (just exists on a development branch) label Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug or regression
Projects
None yet
Development

No branches or pull requests

2 participants