-
Notifications
You must be signed in to change notification settings - Fork 369
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
spin indexing #219 #224
spin indexing #219 #224
Conversation
…d the decoder shifter accordinly
…ing mathematica code. it was giving wrong operators before, now the operators are fine but signs are wonky
…to count qubit/fermion labels from 1 instead of 0
…ht) as a tool to append the same code intance several times
…sts for symbolicBinary. minor mods for python3 comp.
…ode, added an error if qubit index in a code is out of bounds
@conta877 let me know when you are ready for review. |
I'm ready for input. (not review). Is this the way we want to proceed?
…On Feb 27, 2018 17:04, "Ryan Babbush" ***@***.***> wrote:
@conta877 <https://github.com/conta877> let me know when you are ready
for review.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#224 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AV-mvIdinJMhSH-MbcgMEJ4SE04333jhks5tZKYvgaJpZM4SVmSG>
.
|
I think so. It would be good hear from at least two of either: |
I also think integration of this into transforms should be a separate pull
request so that can discuss.
…On Feb 27, 2018 17:41, "Ryan Babbush" ***@***.***> wrote:
I think so. It would be good hear from at least two of either:
@ncrubin <https://github.com/ncrubin> @kevinsung
<https://github.com/kevinsung> @jarrodmcc <https://github.com/jarrodmcc>
to make sure they agree since all three seemed to have opinions...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#224 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AV-mvK0oaSbwWPjVKtLWUTJrKcpUWUgSks5tZK7SgaJpZM4SVmSG>
.
|
This looks fine to me. |
I think this type of re-order will work well for most of the use cases I'm
thinking of.
I know you said you'd clean up the docstring and unused parameter stuff
after we agreed on the style, but I wanted to make sure I mentioned
something slightly more subtle, as it looks like when an order function is
passed a copy of the modified operator is returned, whereas when no order
function is passed, a reference to the original is returned. I feel like
this could lead to slightly unexpected behavior in some cases. In my
opinion it's okay to make the reorder function parameter not optional. If
they don't want to reorder it, why risk unexpected behavior by letting them
call it.
…On Tue, Feb 27, 2018 at 7:22 PM, Kevin J. Sung ***@***.***> wrote:
This looks fine to me.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#224 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHXFPLrtYejXViHpiLyGJ5FWmT5MRcGFks5tZMZzgaJpZM4SVmSG>
.
|
thats a really good point! I'll modify it to make the order function a
must.
On Feb 27, 2018 21:19, "Jarrod" <notifications@github.com> wrote:
I think this type of re-order will work well for most of the use cases I'm
thinking of.
I know you said you'd clean up the docstring and unused parameter stuff
after we agreed on the style, but I wanted to make sure I mentioned
something slightly more subtle, as it looks like when an order function is
passed a copy of the modified operator is returned, whereas when no order
function is passed, a reference to the original is returned. I feel like
this could lead to slightly unexpected behavior in some cases. In my
opinion it's okay to make the reorder function parameter not optional. If
they don't want to reorder it, why risk unexpected behavior by letting them
call it.
On Tue, Feb 27, 2018 at 7:22 PM, Kevin J. Sung ***@***.***> wrote:
This looks fine to me.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#224 (comment)
,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/
AHXFPLrtYejXViHpiLyGJ5FWmT5MRcGFks5tZMZzgaJpZM4SVmSG>
.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#224 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AV-mvDWH2iyLTtu97fmx1_nSPJeSGOBzks5tZOHZgaJpZM4SVmSG>
.
|
is it worth having a separate place for the order functions or should they be put in somewhere else? up_then_down looks very lonely there right now. |
I suggest that for now, we keep both the functions |
I would agree that until we have more functions of this type (if we make
them) they should just go alongside the functions they are meant to be used
with for clarity instead of their own file.
…On Wed, Feb 28, 2018 at 3:27 PM, Kevin J. Sung ***@***.***> wrote:
I suggest that for now, we keep both the functions reorder and
up_then_down in the same file, either utils/_operator_utils.py or
transforms/conversion.py. I don't feel very strongly though.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#224 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHXFPIyorES8CmKNT4OIOmrEL_UmDE0wks5tZeDpgaJpZM4SVmSG>
.
|
ready for review |
Thank you @conta877! In addition to the inline comments I have two general things:
|
@@ -290,3 +290,61 @@ def save_operator(operator, file_name=None, data_directory=None, | |||
with open(file_path, 'wb') as f: | |||
marshal.dump((operator_type, dict(zip(tm.keys(), | |||
map(complex, tm.values())))), f) | |||
|
|||
|
|||
def reorder(Operator, order_function,num_modes=None, reverse=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I would use lowercase to conform with our general style (operator
instead of Operator
). We generally use lowercase for variables.
src/openfermion/utils/__init__.py
Outdated
@@ -21,7 +21,8 @@ | |||
|
|||
from ._operator_utils import (count_qubits, eigenspectrum, fourier_transform, | |||
get_file_path, inverse_fourier_transform, | |||
is_identity, load_operator, save_operator) | |||
is_identity, load_operator, save_operator, | |||
reorder,up_then_down) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed a space. Please run the PEP 8 linter.
@kevinsung thanks for the review! - I caught a bug putting in the reverse test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one last thing I noticed.
@@ -15,8 +15,6 @@ | |||
|
|||
import marshal | |||
import numpy | |||
import os | |||
import time | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for removing time
, but I think os
is in fact used in the saving operation; apparently we don't have a test for that line right now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops! I got tricked by pycharm. will add it back
Thanks @conta877 ! It turns out we did have that test (your pycharm is not crazy) but it passed due to namespace pollution from the |
active_indices=None, | ||
spin_indexing="even-odd"): | ||
def get_molecular_hamiltonian(self,occupied_indices=None, | ||
active_indices=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this spacing seems to be inconsistent with pep8. No?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. I'm failing at pep8ing with this commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured we had given you enough trouble. Perhaps clean it up on the next PR if you're feeling charitable ;-)
* fixed bohr/angstrom confusion in function description * translations from mathematica to python arxiv1712.07067 * work on those notimplementeds * WIP: decoder class adittion * modified decoder class. extractor implemented * no need for pauliaction function * introduction of symbolic binary class - no more decoder class * minor bugs fixed, applies binary rules to input now * started programming the BinaryCode class, work in progress * added count qubit function in binary operator, modified code.py * fixed morning brain bugs * implemented concatination and appending, not yet documented and debugged * added _shift function to symbolicBinary and integer addition. modified the decoder shifter accordinly * radd imul, NOT TESTED! - just copy paste should work? * fixed small bugs, added default codes, created transform * fixed the multiplication error and modified the transform code following mathematica code. it was giving wrong operators before, now the operators are fine but signs are wonky * fixed the transform and all the places where we accidentally started to count qubit/fermion labels from 1 instead of 0 * bug fixes: ordering matters to detect which terms should cancel * fixed code appending, introduced the integer multiplication (left+right) as a tool to append the same code intance several times * modified the multiply by 0 and 1 behavior in SymbolicBinary. added tests for symbolicBinary. minor mods for python3 comp. * fixed the condition for code concatenation, fixed a bug in checksum_code, added an error if qubit index in a code is out of bounds * added comments to binary_operator, more test, evaluate function * started writing documentations and clipping lines, writing out numpy * merging with the merger * updating binary operator based on comments * updating the binary_ops * updates based on comments * init update * moved binaryop to first import * added names into notice and readme * started documentation in _code_operator.py, added parity code / (K=1) and (K=2) segment code / K=1 binary addressing code * encoders are sparse matrices now * added tests for code_operator * doc strings for the transform, fixed bug in the initialization of SymbolicBinary, made changes suggested by review, carried some of them over to files to be pulled later * updates based on pull request comments * merging changes with merger * fixing possible integer checking errors * cleaned version of transform function, needs testing and timing - seems to work so far * fixed BK transforms. indexing errors * added tests, pep8 and Ryan compliance mods * added some style to the functions file * renaming, re-structuring * renaming again * minor changes * pep8 * changed the symbolicBInary class * docstring cleanup * bug docstring fixes * bug fix in the evaluate method, pep8 the _binary_operator file * merge with upstream and additional tests to SymbolicBinary class * added weight-two segment code test, fixed bug with in the code appending by integer multiplication * added half-up code * bugs fixed in half-up code * corrected weight_one_segment_code and the interleaved_code, former half-up. Added tests for the codes. * get rid of heads * reordering function for the fermionOperator class. takes 0,1,2,3,4,.. -> 0,2,4,..,1,3,... * spin indexing within moleculardata * proper master reset * reverting spin_indexing to option 1 with arbitrary functions * moving reorder under operator_utils and making it symbolicOperator general * +1 bug fix * docstrings, variable changes, tests * coverage * put up_then_down with reorder * bug fixes, pep8 * adding os back
what do we think of something like this? #219
no docstrings or descriptions yet - I'll add them once everyones happy :)
created the order functions such that they take in the mode_idx and number of modes as arguments.
there is a lonely order_function (for up-then-down) under transforms/order_functions
here is a sample output:
this was quick prototyping haven't really tested it yet, please let me know if you spot bugs!