-
Notifications
You must be signed in to change notification settings - Fork 30
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
Majorana pool #114
Merged
Merged
Majorana pool #114
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
48febad
added Majorana pool function
JamesB-1qbit 8611c49
added majorana uccgsd pool, changed test function
JamesB-1qbit a708ec2
removed spurious import
JamesB-1qbit c743aaf
improved module description
JamesB-1qbit ca2203e
improved test description
JamesB-1qbit 97a8ffe
fixes for PR review
JamesB-1qbit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
tangelo/toolboxes/ansatz_generator/_unitary_majorana_cc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Copyright 2021 Good Chemistry Company. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Utililty functions to generate pool of FermionOperators obtained from individual MajoranaOperators in | ||
unitary coupled cluster expansions.""" | ||
|
||
from openfermion.transforms.opconversions.conversions import get_fermion_operator | ||
from openfermion import MajoranaOperator | ||
from numpy import integer | ||
|
||
from tangelo.toolboxes.molecular_computation.molecule import SecondQuantizedMolecule | ||
|
||
|
||
def majorana_uccsd_list(molecule: SecondQuantizedMolecule = None, n_electrons: int = None, n_sos: int = None): | ||
JamesB-1qbit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Construct a list of FermionOperator corresponding to the individual Majorana modes in the UCCSD ansatz | ||
|
||
Args: | ||
molecule (SecondQuantizedMolecule): The molecule to generate the Majorana pool from: Default None | ||
n_electrons (int): The number of active electrons: Default None | ||
n_sos (int): The number of active spin orbitals: Default None | ||
|
||
Returns: | ||
list: The list of FermionOperator for each Majorana operator in a UCCD pool""" | ||
|
||
if molecule is not None: | ||
n_active_electrons = molecule.n_active_electrons | ||
n_active_sos = molecule.n_active_sos | ||
elif isinstance(n_electrons, (int, integer)) and isinstance(n_sos, (int, integer)): | ||
n_active_electrons = n_electrons | ||
n_active_sos = n_sos | ||
else: | ||
raise ValueError("SecondQuantized mol or ints n_electrons/n_sos must be provided") | ||
|
||
def majorana_uccsd_generator(): | ||
JamesB-1qbit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for i in range(n_active_electrons): | ||
for k in range(n_active_electrons, n_active_sos): | ||
yield (2*i, 2*k) | ||
yield (2*i+1, 2*k+1) | ||
for j in range(i+1, n_active_electrons): | ||
for l in range(k+1, n_active_sos): | ||
yield (2*i, 2*j+1, 2*k+1, 2*l+1) | ||
yield (2*i+1, 2*j, 2*k+1, 2*l+1) | ||
yield (2*i+1, 2*j+1, 2*k, 2*l+1) | ||
yield (2*i+1, 2*j+1, 2*k+1, 2*l) | ||
yield (2*i+1, 2*j, 2*k, 2*l) | ||
yield (2*i, 2*j+1, 2*k, 2*l) | ||
yield (2*i, 2*j, 2*k+1, 2*l) | ||
yield (2*i, 2*j, 2*k, 2*l+1) | ||
pool_list = [get_fermion_operator(MajoranaOperator(term)) for term in majorana_uccsd_generator()] | ||
JamesB-1qbit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return pool_list | ||
|
||
|
||
def majorana_uccgsd_list(molecule: SecondQuantizedMolecule = None, n_sos: int = None): | ||
JamesB-1qbit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Construct a list of FermionOperator corresponding to the individual Majorana modes in the UCCGSD ansatz | ||
|
||
Args: | ||
molecule (SecondQuantizedMolecule): The molecule to generate the Majorana pool from: Default None | ||
n_sos (int): The number of active spin orbitals: Default None | ||
|
||
Returns: | ||
list: The list of FermionOperator for each Majorana operator in a UCCD pool""" | ||
JamesB-1qbit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if molecule is not None: | ||
n_active_sos = molecule.n_active_sos | ||
elif isinstance(n_sos, (int, integer)): | ||
n_active_sos = n_sos | ||
else: | ||
raise ValueError("SecondQuantized mol or int n_sos must be provided") | ||
|
||
def majorana_uccgsd_generator(): | ||
for i in range(n_active_sos): | ||
for j in range(i+1, n_active_sos): | ||
yield (2*i, 2*j) | ||
yield (2*i+1, 2*j+1) | ||
for k in range(j+1, n_active_sos): | ||
for l in range(k+1, n_active_sos): | ||
yield (2*i, 2*j+1, 2*k+1, 2*l+1) | ||
yield (2*i+1, 2*j, 2*k+1, 2*l+1) | ||
yield (2*i+1, 2*j+1, 2*k, 2*l+1) | ||
yield (2*i+1, 2*j+1, 2*k+1, 2*l) | ||
yield (2*i+1, 2*j, 2*k, 2*l) | ||
yield (2*i, 2*j+1, 2*k, 2*l) | ||
yield (2*i, 2*j, 2*k+1, 2*l) | ||
yield (2*i, 2*j, 2*k, 2*l+1) | ||
pool_list = [get_fermion_operator(MajoranaOperator(term)) for term in majorana_uccgsd_generator()] | ||
JamesB-1qbit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return pool_list |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think you can just say "The arguments for the pool function" as the type is already clear in the docs.
It is not obvious why you're choosing to extend the functionality here. What was the rationale behind supporting dictionaries? Ideally I'd pick one or the other, and stay pythonic: one way to do things (and less code to maintain). If you have an opinion about what we should keep, that would be great.
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 changed the type required to dictionary. I added the functionality because the
get_majorana_uccgsd_pool
function requires either aSecondQuantizedMolecule
orn_sos
. If left as a tuple, it would require the user to supply(None, number_of_spin_orbitals)
to use the latter choice. The dictionary would be{"n_sos": number_of_spin_orbitals}
.