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

Unable to load pulse defaults due to amp being a list #4162

Closed
jyu00 opened this issue Apr 15, 2020 · 4 comments
Closed

Unable to load pulse defaults due to amp being a list #4162

jyu00 opened this issue Apr 15, 2020 · 4 comments
Labels
bug Something isn't working mod: pulse Related to the Pulse module

Comments

@jyu00
Copy link
Contributor

jyu00 commented Apr 15, 2020

Information

  • Qiskit Terra version: 0.13.0
  • Python version:
  • Operating system:

What is the current behavior?

PulseDefaults.from_dict() would fail if the pulse defaults contain parametric pulse:

Traceback (most recent call last):
  File "mod1.py", line 18, in <module>
    new_defaults = PulseDefaults.from_dict(defaults_dict)
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/qiskit/validation/base.py", line 354, in from_dict
    data = cls.schema.load(dict_)
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/marshmallow/schema.py", line 723, in load
    data, many=many, partial=partial, unknown=unknown, postprocess=True
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/marshmallow/schema.py", line 897, in _do_load
    partial=partial,
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/marshmallow/schema.py", line 1098, in _invoke_load_processors
    partial=partial,
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/marshmallow/schema.py", line 1224, in _invoke_processors
    data = processor(data, many=many, **kwargs)
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/qiskit/validation/base.py", line 163, in make_model
    return self.model_cls(**data)
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/qiskit/validation/base.py", line 245, in _decorated
    return init_method(self, **kwargs, validate=False)
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/qiskit/providers/models/pulsedefaults.py", line 146, in __init__
    pulse_insts = [self.converter(inst) for inst in inst.sequence]
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/qiskit/providers/models/pulsedefaults.py", line 146, in <listcomp>
    pulse_insts = [self.converter(inst) for inst in inst.sequence]
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/qiskit/qobj/converters/pulse_instruction.py", line 312, in __call__
    return method(self, instruction)
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/qiskit/qobj/converters/pulse_instruction.py", line 476, in convert_parametric
    command = ParametricPulseShapes[instruction.pulse_shape].value(**instruction.parameters)
  File "/Users/jessieyu/.pyenv/versions/test_3.7.3/lib/python3.7/site-packages/qiskit/pulse/commands/parametric_pulses.py", line 295, in __init__
    self._amp = complex(amp)
TypeError: complex() first argument must be a string or a number, not 'list'

Steps to reproduce the problem

Call PulseDefaults.from_dict(defaults_dict) where defaults_dict contains a parametric pulse. For example

'cmd_def': [{'name': 'cx', 'qubits': [0, 1], 'sequence': [
{'ch': 'd0', 'name': 'parametric_pulse', 'parameters': {'amp': [-3.756271140650859e-17, -0.20448187691156458], 'beta': -0.2083529330072782, 'duration': 12, 'sigma': 3.0}, 'pulse_shape': 'drag', 't0': 0} ]}]

Existing pulse defaults do not have parametric pulses, but that's being introduced.

What is the expected behavior?

PulseDefaults.from_dict() loads correctly.

Suggested solutions

The marshmallow schema for the PulseQobjInstructionSchema has

parameters = DictParameters(valid_value_types=(int, float, bool, complex))

which is probably why marshmallow didn't convert amp from list to complex (the _deserialize() for DictParameters doesn't do any conversion)

Given marshmallow has already been removed for PulseQobjInstructionSchema, the solution can be to just ignore it and tell people to upgrade if they encounter this issue.

@jyu00 jyu00 added the bug Something isn't working label Apr 15, 2020
@jyu00
Copy link
Contributor Author

jyu00 commented Apr 15, 2020

@zachschoenfeld33
Copy link
Contributor

@jyu00 Is there also an issue to update this for the new version without marshmallow?

@jyu00
Copy link
Contributor Author

jyu00 commented Apr 15, 2020

@zachschoenfeld33 Yes there is a general issue open for marshmallow removal that I'm slowly chipping away: Qiskit/qiskit-ibmq-provider#553

@jakelishman
Copy link
Member

If I understand #7318 correctly, this technically isn't fixed, but the path being requested is obsolete. I'll close the issue now as stale, but if there's more to say, feel free to re-open.

@jakelishman jakelishman closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mod: pulse Related to the Pulse module
Projects
None yet
Development

No branches or pull requests

4 participants