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

Fixes indexing of circuits in local folding methods for Cirq, adds tests #10

Merged
merged 8 commits into from
Feb 21, 2020
Merged

Conversation

rmlarose
Copy link
Contributor

@rmlarose rmlarose commented Feb 16, 2020

Fixes #8

@rmlarose rmlarose changed the title Fixes indexing of circuits in local folding methods for Cirq to address #8, adds tests Fixes indexing of circuits in local folding methods for Cirq, adds tests Feb 16, 2020
@rmlarose
Copy link
Contributor Author

rmlarose commented Feb 16, 2020

Fixes #8 and #9 for local folding methods with Cirq.

Copy link
Contributor

@willzeng willzeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @rmlarose! Looks solid.

Had some small changes and then one suggestion about adding mutability for performance that would be good to get your thoughts on.

mitiq/folding_cirq.py Outdated Show resolved Hide resolved
mitiq/folding_cirq.py Outdated Show resolved Hide resolved

for _ in range(num_to_fold):
# TODO: This allows for gates to be folded more than once, and folded gates to be folded.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intuition is that gates should be allowed to be sampled more than once, but that one should not sample from the new folds. Do you agree @andreamari I think this change is made doing:

        moment_index = np.random.choice(len(circuit))
        gate_index = np.random.choice(len(circuit[moment_index]))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same intuition, not 100% sure though. I'll wait to hear Andrea's and other's thoughts, it's not too hard to change either way.

Copy link
Member

@andreamari andreamari Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intuition is that it is better to distribute the folding gates as much as possible along the circuit, so I think it is better not to sample the same gate of the original circuit (unless stretch >3) AND not to sample previous folds.

What is the optimal way of doing this I don't know. I need to think about.

[I edited this comment. Please ignore my previous version since I was wrong about the creation of new moments.]

mitiq/folding_cirq.py Outdated Show resolved Hide resolved
mitiq/folding_cirq.py Outdated Show resolved Hide resolved
mitiq/folding_cirq.py Outdated Show resolved Hide resolved
mitiq/folding_cirq.py Outdated Show resolved Hide resolved
mitiq/tests/test_folding_cirq.py Show resolved Hide resolved
mitiq/tests/test_folding_cirq.py Show resolved Hide resolved
@rmlarose
Copy link
Contributor Author

rmlarose commented Feb 20, 2020

Addresses all points except folding gates that have already been folded, as I don't think we've reached a consensus on this. (Have we?) I've kept the "TODO" notes about this in the file as points to address once we reach a conclusion.

I think the previous solution using **kwargs in the fold_method was more elegant, but this is a working version. Another possibility is to use *args.

Copy link
Contributor

@willzeng willzeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor final comments. Then likely is go to go

mitiq/folding_cirq.py Outdated Show resolved Hide resolved
mitiq/folding_cirq.py Outdated Show resolved Hide resolved
@willzeng
Copy link
Contributor

Additionally I opened #12 for discussion on resampling folded gates

Copy link
Member

@andreamari andreamari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure the methods: unitary_folding, fold_local, fold_gates_at_random, fold_gates_from_left,
should be public. What about if we make all the other ones, private methods? Just to create less confusion to the user. Moreover in this way they could all change circuits in place without problems, if necessary.
This is just a subjective idea, so feel free to ignore it.

mitiq/folding_cirq.py Outdated Show resolved Hide resolved
@andreamari
Copy link
Member

andreamari commented Feb 20, 2020

I just noticed that the method fold_moments is not compatible with fold_local (it cannot be passed as an argument). So maybe we could remove it and just focus on the local folding of individual gates. Alternatively we would need to implement something like fold_moments_at_random and fold_moments_from_left.

…put circuit, refactors test cases.

[WIP] Adds function for tracking moment indices to be used in fold_gates_at_random folding function.
Copy link
Contributor

@willzeng willzeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@willzeng willzeng merged commit 540f3d6 into unitaryfund:master Feb 21, 2020
willzeng added a commit that referenced this pull request Apr 17, 2020
# This is the 1st commit message:

simplify cirq getting started and add qiskit getting started

# This is the commit message #2:

add tests of qiskit getting started

# This is the commit message #3:

update qiskit example with conversions

# This is the commit message #4:

move seeds

# This is the commit message #5:

add doctests to main getting started

# This is the commit message #6:

better seed

# This is the commit message #7:

set seeds

# This is the commit message #8:

update

# This is the commit message #9:

qiskit name

# This is the commit message #10:

line

# This is the commit message #11:

update doc tests and remove redundant tests

# This is the commit message #12:

fix apidoc
rmlarose pushed a commit that referenced this pull request Apr 22, 2020
* # This is a combination of 12 commits.
# This is the 1st commit message:

simplify cirq getting started and add qiskit getting started

# This is the commit message #2:

add tests of qiskit getting started

# This is the commit message #3:

update qiskit example with conversions

# This is the commit message #4:

move seeds

# This is the commit message #5:

add doctests to main getting started

# This is the commit message #6:

better seed

# This is the commit message #7:

set seeds

# This is the commit message #8:

update

# This is the commit message #9:

qiskit name

# This is the commit message #10:

line

# This is the commit message #11:

update doc tests and remove redundant tests

# This is the commit message #12:

fix apidoc

* update getting started

* reformat testcode as block

* switch to make doctest

* include change to make doctest in workflow file

* add doctest to workflow

* test documentation in ci with doctest

* remove lines to prompt build

* revert to original ci file

* add new name run with pytest-sphinx

* add sphinx to install

* add cd

* add sphinx dependencies and extentions to ci

* purposefully introduce error to check ci build fails

* revert to passing build

* add documentation testing to readme

* remove README extra file

* update zne.py for new keep type default

* move random seed to test

* make test factories seed local

* make noise mitigation more clear

Co-authored-by: Nathan Shammah <nathan.shammah@gmail.com>
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.

Folding in Cirq for multi-qubit circuits
3 participants