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

Expand string initializations #177

Closed
babbush opened this issue Jan 19, 2018 · 10 comments
Closed

Expand string initializations #177

babbush opened this issue Jan 19, 2018 · 10 comments

Comments

@babbush
Copy link
Contributor

babbush commented Jan 19, 2018

As discussed in #122 it would be helpful if sums of FermionOperators and QubitOperators could be initialized from their string representation so that
my_fermion_operator - FermionOperator(str(my_fermion_operator)) = 0 and
my_qubit_operator - QubitOperator(str(qubit_operator)) = 0.
This should be easy for a beginner to implement.

@max-radin
Copy link
Contributor

I'll work on implementing this. I'm new to OpenFermion and would like to get familiar with the code.

@kevinsung
Copy link
Collaborator

I had this issue in mind while completing #194 so I did it in a way that made this task easy to incorporate. Basically you just fill in the body of _long_string_init in ops/_symbolic_operator.py. @max-radin, are you okay with doing it this way?

@max-radin
Copy link
Contributor

Yes that makes sense to me. I have written some code for long string initialization in FermionOperator that I can move into _long_string_init.

@kevinsung
Copy link
Collaborator

kevinsung commented Jan 31, 2018

Great. Keep in mind that the task now is basically to reverse-engineer the __str__ method of SymbolicOperator, which now uses the attributes action and action_string. You may want to take advantage of the method _parse_string. Let me know if you have any questions.

babbush pushed a commit that referenced this issue Feb 5, 2018
…#201)

* Implemented long string initialization and tests for SymbolicOperator (#177)

* Added support for complex coefficients in SymbolicOperator long string initialization

* Refactored SymbolicOperator._long_string_init

* Updated author list

* Update NOTICE

* Update README.rst
@babbush
Copy link
Contributor Author

babbush commented Feb 5, 2018

Closed by #201

@babbush babbush closed this as completed Feb 5, 2018
@babbush
Copy link
Contributor Author

babbush commented Feb 27, 2018

my_operator = FermionOperator('1.7 [3^ 2] - 8 [4^]')
seems to throw an error whereas
my_operator = FermionOperator('1.7 [3^ 2] + 8 [4^]')
and
my_operator = FermionOperator('1.7 [3^ 2] -8 [4^]')
and
my_operator = FermionOperator('1.7 [3^ 2] + -8 [4^]')
do not. I guess subtraction is not supported as expected? @max-radin can you assist with this?

@babbush babbush reopened this Feb 27, 2018
@babbush
Copy link
Contributor Author

babbush commented Feb 27, 2018

Also, it seems to always assume numbers are complex, for instance
my_operator = FermionOperator('-1.7 [3^ 2] + 8.0 [4^]') print(my_operator)
returns
(-1.7+0j) [3^ 2] + (8+0j) [4^]

@babbush
Copy link
Contributor Author

babbush commented Feb 27, 2018

Also, I am not sure how one is supposed to provide complex coefficients.
my_operator = FermionOperator('(2.3 + 1.7j) [3^ 2]')
throws an error.

@max-radin
Copy link
Contributor

Yes I'll fix these issues shortly. Evidently, the complex initializer does not support white space, so you'd have to write '(2.3+1.7j) [3^ 2]'.

@babbush
Copy link
Contributor Author

babbush commented Feb 27, 2018

Thanks Max! I think we should try to be flexible with respect to the white space.

max-radin added a commit to max-radin/OpenFermion that referenced this issue Feb 28, 2018
philipp-q pushed a commit to philipp-q/OpenFermion that referenced this issue Sep 2, 2020
…quantumlib#201)

* Implemented long string initialization and tests for SymbolicOperator (quantumlib#177)

* Added support for complex coefficients in SymbolicOperator long string initialization

* Refactored SymbolicOperator._long_string_init

* Updated author list

* Update NOTICE

* Update README.rst
philipp-q pushed a commit to philipp-q/OpenFermion that referenced this issue Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants