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

complex NumpyJSONEncoder fix #227

Merged
merged 4 commits into from
Jun 9, 2016
Merged

complex NumpyJSONEncoder fix #227

merged 4 commits into from
Jun 9, 2016

Conversation

damazter
Copy link
Contributor

@damazter damazter commented Jun 9, 2016

This pull request fixes an issue that I didn't bother to write, because the fix was shorter than writing the issue. But in Short, when you have a complex parameters that gets logged at the start of the measurement loop, it crashes because the complex value cannot be JSON Serialized

Changes proposed in this pull request:
Add a numpy encoder for complex numbers

I did not run any tests yet, because I don't yet know how to do that. Any explanation on that would be appreciated
EDIT: I see something happening
EDIT2: I see that one test failed, but I cannot understand why, I don't think this it has anything to do with this pull request
EDIT3: I know it is bad practice to keep editing posts, but most of you are sleeping anyway

@alexcjohnson
@giulioungaretti

@damazter
Copy link
Contributor Author

damazter commented Jun 9, 2016

I think I added a test to the tests, but I am not sure I did this correctly

@damazter
Copy link
Contributor Author

damazter commented Jun 9, 2016

and for realism sake:
http://journals.aps.org/prl/abstract/10.1103/PhysRevLett.108.078101

I don't know if a negative bending modulus makes sense, but it would surely make for a special ponytail

@giulioungaretti
Copy link
Contributor

@damazter! Just a quick answer before I look into it for real! Did you
check the documentation for testing and found it not helpful ? There is a
part that explains how to run tests. Not that I don't want to help you here
but just wondering if we need to make better documentation:)

On Thu, 9 Jun 2016 at 05:15, damazter [email protected] wrote:

and for realism sake:
http://journals.aps.org/prl/abstract/10.1103/PhysRevLett.108.078101

I don't know if a negative bending modulus makes sense, but it would
surely make for a special ponytail


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/qdev-dk/Qcodes/pull/227#issuecomment-224790414, or mute
the thread
https://github.com/notifications/unsubscribe/ACkcN402M1JknKG-mAJNsdBjaTv7e7Lcks5qJ4VJgaJpZM4IxkcP
.

@damazter
Copy link
Contributor Author

damazter commented Jun 9, 2016

@giulioungaretti
I have some problems running the tests locally (even for the current master branch)
I get a queue.empty error for test_instrument_server.py
Then I get
WARNING:root:ServerManager did not respond to halt signal, terminated
and then nothing.

Hence this has nothing to do with my current pull request, seeing that the tests with travis have passed
So I think this pull request can be evaluating regardless of my inaptitude to run the tests.

@alexcjohnson
Copy link
Contributor

@damazter I'm quite interested in your test failure... any more info you can provide on your platform, complete console output, would be great - but maybe lets diagnose this on slack rather than in this PR as you're right that it's independent. You did a fine job of writing tests for the new code. 🌟

But we should also probably talk about the code itself!

  • As per this comment from @MatthieuDartiailh we should probably change complex (and all the numpy types) into numbers abstract classes
  • Turning a complex number into a length-2 list stops the encoding from failing, and preserves the information if you already know that the value is a single complex number - but it doesn't tell you that it's complex, nor will the value be complex when you read it back in. Can we do something along the lines of the SO post that @MerlinSmiles pointed to in fix: JSON dump fails on numpy int, float and array types #198 and make complex numbers into dicts? Something with "magic" key(s) that tell us not to interpret it as a regular dict when we read it back in, like:
    {'__dtype__': 'complex', 're': 1, 'im': 2}
    or perhaps just
    {'__re__': 1, '__im__': 2}?

@damazter
Copy link
Contributor Author

damazter commented Jun 9, 2016

@alexcjohnson
I choose the first representation, seems like a good idea.
Using numbers.Complex as well now.
I have testing problems on both my windows 10 machines.
I also don't understand why the travis checks are failing, the errors seem to have nothing to do with my changes.

@alexcjohnson
Copy link
Contributor

Great, thanks!

Those are intermittent failures known to show up on Travis - you're OK.

Now that you have numbers.Complex in there can you include both numpy and built-in complex types in the test?

The last step to make this reversible with a JSONDecoder subclass (or just an object_hook). If you don't have a particular need to bring things back in now I'd be OK with making this an issue and deferring it, or you can build it into this PR - your call.

@damazter
Copy link
Contributor Author

damazter commented Jun 9, 2016

@alexcjohnson
Well, that was interesting, this code failed hard for build-in complex types. (it had in infinite recursive loop)
Hence I changed the representation to make floats out of the real and imaginary parts. I don't think python has a type for Gaussian integers.

Making a decoder is not something that I would know how to do, so I will make an issue for that, for now

@alexcjohnson
Copy link
Contributor

Haha, tests to the rescue! 🐅

Pretty crazy, I guess it makes sense that real is effectively a subclass of complex but... it's also rather annoying!

💃 once there's an issue for the decoder.

@damazter
Copy link
Contributor Author

damazter commented Jun 9, 2016

My first contribution into the QCodes core, took me long enough 🎉

@damazter damazter merged commit db3a71e into master Jun 9, 2016
@damazter damazter deleted the complex_fix branch June 9, 2016 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants