pyGSTi icon indicating copy to clipboard operation
pyGSTi copied to clipboard

densitymx_slow does not work

Open aristaeus opened this issue 1 year ago • 4 comments

Describe the bug The densitymx_slow implementation does not work. At pygsti/evotypes/densitymx_slow/opreps.py:177,

class OpRepStandard(OpRepDenseSuperop):
    def __init__(self, name, basis, state_space):
        ...
        super(OpRepStandard, self).__init__(superop, state_space)

The issue is that OpRepDenseSuperof.__init__ doesn't have that signature;

class OpRepDenseSuperop(OpRep):
    def __init__(self, mx, basis, state_space):
        ...

To Reproduce Steps to reproduce the behavior:

  1. Install pygsti without cython
  2. Try and run a circuit
  3. :(

Expected behavior Ideally we would get the fast cython implementation working. However, while setting up a new user it would be nice for the slow fallback to work so we can get something out.

aristaeus avatar May 14 '24 08:05 aristaeus

I had the same issue. This is the error message I got when trying to create a model:

File c:\Users\k0426\anaconda3\envs\working_env_new\Lib\site-packages\pygsti\models\modelconstruction.py:1847, in create_cloud_crosstalk_model(processor_spec, custom_gates, depolarization_strengths, stochastic_error_probs, lindblad_error_coeffs, depolarization_parameterization, stochastic_parameterization, lindblad_parameterization, evotype, simulator, independent_gates, independent_spam, errcomp_type, implicit_idle_mode, basis, verbosity) 1713 """ 1714 Create a n-qudit "cloud-crosstalk" model. 1715 (...) 1840 CloudNoiseModel 1841 """ 1843 modelnoise = _build_modelnoise_from_args(depolarization_strengths, stochastic_error_probs, lindblad_error_coeffs, 1844 depolarization_parameterization, stochastic_parameterization, 1845 lindblad_parameterization, allow_nonlocal=True) -> 1847 return _create_cloud_crosstalk_model(processor_spec, modelnoise, custom_gates, evotype, 1848 simulator, independent_gates, independent_spam, errcomp_type, 1849 implicit_idle_mode, basis, verbosity)

File c:\Users\k0426\anaconda3\envs\working_env_new\Lib\site-packages\pygsti\models\modelconstruction.py:1876, in _create_cloud_crosstalk_model(processor_spec, modelnoise, custom_gates, evotype, simulator, independent_gates, independent_spam, errcomp_type, implicit_idle_mode, basis, verbosity) 1873 printer = _VerbosityPrinter.create_printer(verbosity) 1875 #Create static ideal gates without any noise (we use modelnoise further down) -> 1876 gatedict = _setup_local_gates(processor_spec, evotype, None, custom_gates, 1877 ideal_gate_type=('static standard', 'static clifford', 'static unitary'), 1878 basis=basis) 1879 stencils = _collections.OrderedDict() 1881 # (Note: global idle is now processed with other processorspec gates) 1882 1883 # SPAM

File c:\Users\k0426\anaconda3\envs\working_env_new\Lib\site-packages\pygsti\models\modelconstruction.py:1475, in _setup_local_gates(processor_spec, evotype, modelnoise, custom_gates, ideal_gate_type, basis) 1473 ideal_gate = ideal_gates.get(name, None) 1474 if ideal_gate is None: -> 1475 ideal_gate = _op.create_from_unitary_mx(U, ideal_gate_type, basis, stdname, evotype, state_space=None) 1476 ideal_gates[name] = ideal_gate 1477 noiseop = modelnoise.create_errormap(key, evotype, ideal_gate.state_space, target_labels=None)

File c:\Users\k0426\anaconda3\envs\working_env_new\Lib\site-packages\pygsti\modelmembers\operations_init_.py:59, in create_from_unitary_mx(unitary_mx, op_type, basis, stdname, evotype, state_space) 57 try: 58 if typ == 'static standard' and stdname is not None: ---> 59 op = StaticStandardOp(stdname, basis, evotype, state_space) 60 elif typ == 'static clifford': 61 op = StaticCliffordOp(U, None, basis, evotype, state_space)

File c:\Users\k0426\anaconda3\envs\working_env_new\Lib\site-packages\pygsti\modelmembers\operations\staticstdop.py:58, in StaticStandardOp.init(self, name, basis, evotype, state_space) 55 basis = _Basis.cast(basis, state_space.dim) # basis for Hilbert-Schmidt (superop) space 57 evotype = _Evotype.cast(evotype) ---> 58 rep = evotype.create_standard_rep(name, basis, state_space) 59 _LinearOperator.init(self, rep, evotype)

File c:\Users\k0426\anaconda3\envs\working_env_new\Lib\site-packages\pygsti\evotypes\evotype.py:136, in Evotype.create_standard_rep(self, standard_name, super_basis, state_space) 135 def create_standard_rep(self, standard_name, super_basis, state_space): --> 136 return self.module.OpRepStandard(standard_name, super_basis, state_space)

File c:\Users\k0426\anaconda3\envs\working_env_new\Lib\site-packages\pygsti\evotypes\densitymx_slow\opreps.py:177, in OpRepStandard.init(self, name, basis, state_space) 174 state_space = _StateSpace.cast(state_space) 175 assert(superop.shape[0] == state_space.dim) --> 177 super(OpRepStandard, self).init(superop, state_space)

TypeError: OpRepDenseSuperop.init() missing 1 required positional argument: 'state_space'

KangHaiYue avatar May 14 '24 08:05 KangHaiYue

Thanks for reporting this and for identifying a hole in our testing! This should be a quick fix, I'll have something on develop for you in the next day or so hopefully. We'll also add some tests in an environment without Cython to ensure we catch things like this in the future.

sserita avatar May 14 '24 16:05 sserita

I believe this is a one-line fix. It will be merged into develop shortly, and we are planning a hotfix release soon, but if you want to try the change locally and let me know if you run into other issues, you are certainly welcome to.

We go from: https://github.com/sandialabs/pyGSTi/blob/fd0ce69dfdf9a58b1a3886105ed6dd576df500f0/pygsti/evotypes/densitymx_slow/opreps.py#L177

to: https://github.com/sandialabs/pyGSTi/blob/c77f57dc748f699fccc6578e4d37283997126ed9/pygsti/evotypes/densitymx_slow/opreps.py#L177

sserita avatar May 14 '24 22:05 sserita

Thanks! I suspected this was the change required, but I'm not familiar enough with the code to be confident.

aristaeus avatar May 15 '24 00:05 aristaeus

Closing as this was merged into develop with #439. The fixed-but-not-in-release tag will remain until the 0.9.12.3 release, which will include this fix.

sserita avatar May 20 '24 13:05 sserita