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

[BUG] ql.save_platform() converts float to string on S4g current parameters #660

Closed
1 task done
paulqili opened this issue Jan 9, 2024 · 1 comment
Closed
1 task done
Assignees
Labels
bug Something isn't working

Comments

@paulqili
Copy link
Contributor

paulqili commented Jan 9, 2024

Expected behavior

The ql.save_platform() line should save the dac currents in float format in the runcard

Actual behavior

see image below:

image

Additional information

This is actually a bug of PyYAML library described in yaml/pyyaml#173

There are some cases that PyYAML dumps floats in scientific notation, but in incorrect format. For example, instead of 4.0e5, 4e5 is stored. Then when reading back the entry is retrieved as string, since it doesn't pass the regex check for floats.

System Information

new-qblox-firmaware branch

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.

HOW will the task be done? Add sub-issues if necessary.

We have to edit the regex pattern of the loader of PyYAML

Instead of doing runcard = yaml.safe_load(stream=file) we should do

loader = yaml.SafeLoader
loader.add_implicit_resolver(
    u'tag:yaml.org,2002:float',
    re.compile(u'''^(?:
     [-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+]?[0-9]+)?
    |[-+]?(?:[0-9][0-9_]*)(?:[eE][-+]?[0-9]+)
    |\\.[0-9_]+(?:[eE][-+][0-9]+)?
    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*
    |[-+]?\\.(?:inf|Inf|INF)
    |\\.(?:nan|NaN|NAN))$''', re.X),
    list(u'-+0123456789.'))

runcard = yaml.load(file, loader)

Alternatively, we can use a different library. Internet suggests using ruamle.yaml which is a fork of PyYAML and has this bug fixed.

https://yaml.readthedocs.io/en/latest/overview/

@paulqili paulqili added the bug Something isn't working label Jan 9, 2024
Copy link

linear bot commented Jan 9, 2024

@fedonman fedonman assigned fedonman and unassigned fedonman Jan 9, 2024
@visagim visagim self-assigned this Jan 10, 2024
@visagim visagim closed this as completed Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants