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

Add randomized clifford+T benchmarking circuits. #2118

Merged
merged 14 commits into from
Dec 15, 2023

Conversation

FarLab
Copy link
Contributor

@FarLab FarLab commented Dec 8, 2023

Description

This PR adds the feature requested here #1230.

closes #1230


License

  • I license this contribution under the terms of the GNU GPL, version 3 and grant Unitary Fund the right to provide additional permissions as described in section 7 of the GNU GPL, version 3.

Before opening the PR, please ensure you have completed the following where appropriate.

@FarLab FarLab added this to the 0.32.0 milestone Dec 8, 2023
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello @FarLab, thank you for submitting a PR to Mitiq! We will respond as soon as possible, and if you have any questions in the meantime, you can ask us on the Unitary Fund Discord.

Copy link

codecov bot commented Dec 11, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (6e9351d) 98.31% compared to head (5bdc4ee) 98.19%.
Report is 12 commits behind head on master.

Files Patch % Lines
mitiq/benchmarks/randomized_clifford_t_circuit.py 93.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2118      +/-   ##
==========================================
- Coverage   98.31%   98.19%   -0.12%     
==========================================
  Files          87       88       +1     
  Lines        4142     4166      +24     
==========================================
+ Hits         4072     4091      +19     
- Misses         70       75       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andreamari
Copy link
Member

The function compute_eavy_bitstrings is already in quantum_volume_circuits.py. So, if necessary, we can use that function instead of re-defining it in the new file.

Moreover, even if it was originally suggested in the issue, now I wonder if we should simply return the circuit without the associated heavy bitstrings. Heavy bitstrings are important for quantum volume circuits and I am not sure if the are important in this case. Moreover the user can always call the function compute_heavy_bitstrings() by themselves, if necessary.

So, I would suggest to simply don't consider heavy bitstrings in this new benchmark.

But please wait for a second opinion by @natestemen about this. I don't want to make you remove some code that other people think it is instead useful.

Further unrelated comment: please add the new function in the API docs in this file https://github.com/unitaryfund/mitiq/blob/master/docs/source/apidoc.md . You can look for the Benchmarks section in that file and see how other similar functions are listed.

natestemen and others added 3 commits December 12, 2023 09:09
co-authored-by: Farrokh Labib <farrokh@unitary.fund>
co-authored-by: Misty Wahl <misty@unitary.fund>
co-authored-by: Farrokh Labib <farrokh@unitary.fund>
co-authored-by: Misty Wahl <misty@unitary.fund>
co-authored-by: Farrokh Labib <farrokh@unitary.fund>
co-authored-by: Misty Wahl <misty@unitary.fund>
@FarLab
Copy link
Contributor Author

FarLab commented Dec 13, 2023

Thanks Andrea for your comments. I will probably remove the heavy bitstring function since it already exists. I will also add the function in the API docs.

@natestemen natestemen removed this from the 0.32.0 milestone Dec 14, 2023
Copy link
Member

@natestemen natestemen left a comment

Choose a reason for hiding this comment

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

Really nice work here Farrokh! A great first addition to Mitiq.

I've left a few small comments, but my biggest is a small concern that in order to appease mypy, we've made the code quite a bit more complicated by shifting everything to manipulating indices. I feel like a simpler approach would be to cast all the objects that get passed to np.random.choice as np.ndarrays. WDYT?


Returns:
A quantum circuit acting on ``num_qubits`` qubits.
A list of the heavy bitstrings for the returned circuit.
Copy link
Member

Choose a reason for hiding this comment

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

I think this line should be removed now that we don't return bitstrings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, will remove!

Comment on lines 57 to 62
oneq_idx_list = [
rnd_state.choice(list(range(len(oneq_cliffords)))) for _ in range(3)
]
twoq_idx_list = [
rnd_state.choice(list(range(len(twoq_cliffords)))) for _ in range(3)
]
Copy link
Member

Choose a reason for hiding this comment

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

I think the range functions here should be range(num_oneq_cliffords) and range(num_twoq_cliffords) respectively. I think the 3 might be a magic number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, you are right, that should not be 3 (which was probably hardcoded for some reason)

Comment on lines 57 to 62
oneq_idx_list = [
rnd_state.choice(list(range(len(oneq_cliffords)))) for _ in range(3)
]
twoq_idx_list = [
rnd_state.choice(list(range(len(twoq_cliffords)))) for _ in range(3)
]
Copy link
Member

Choose a reason for hiding this comment

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

If we have to keep all the indices, this is a little cleaner.

Suggested change
oneq_idx_list = [
rnd_state.choice(list(range(len(oneq_cliffords)))) for _ in range(3)
]
twoq_idx_list = [
rnd_state.choice(list(range(len(twoq_cliffords)))) for _ in range(3)
]
oneq_idx_list = rnd_state.choice(2, num_oneq_cliffords)
twoq_idx_list = rnd_state.choice(2, num_twoq_cliffords)

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 like this solution more that casting the objects that go into np.random.choice as np.ndarray. also, I think the 2 should be len(oneq_cliffords) and len(twoq_cliffords), right?

Copy link
Member

Choose a reason for hiding this comment

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

That's right!

)


def test_generate_model_circuit_with_seed():
Copy link
Member

Choose a reason for hiding this comment

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

I think this test name is copied from another file, and I know we use it in other places, but I think we can make it a little more descriptive of what the actual intention is. Maybe something like test_seed_circuit_equality? I don't love that name either, but I'm sure we can come up something better than "model circuit".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test_seed_circuit_equality sounds good to me. we can change it if we find a better name :)

Comment on lines 6 to 12
"""Tests for quantum volume circuits. The Cirq functions that do the main work
are tested here:
cirq-core/cirq/contrib/quantum_volume/quantum_volume_test.py

Tests below check that generate_quantum_volume_circuit() works as a wrapper and
fits with Mitiq's interface.
"""
Copy link
Member

Choose a reason for hiding this comment

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

comment needs removal, or updating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

num_twoq_cliffords=2,
num_t_gates=2,
return_type=return_type,
seed=3,
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove this line just so it's running the test with random circuit each time.

Suggested change
seed=3,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree

Copy link
Member

@natestemen natestemen left a comment

Choose a reason for hiding this comment

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

One small comment needs updating, and we'll need to add a line into mitiq/benchmarks/__init__.py to make these functions importable like

from mitiq.benchmarks import generate_random_clifford_t_circuit

Once those two things are done, we are good to go!

# This source code is licensed under the GPL license (v3) found in the
# LICENSE file in the root directory of this source tree.

"""Functions for generating rotated randomized benchmarking circuits."""
Copy link
Member

Choose a reason for hiding this comment

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

Needs update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, I will update these two last points now

…in mitiq/benchmarks/__init__.py to make the functions importable
@@ -14,3 +14,4 @@
)
from mitiq.benchmarks.w_state_circuits import generate_w_circuit
from mitiq.benchmarks.qpe_circuits import generate_qpe_circuit
from mitiq.benchmarks import generate_random_clifford_t_circuit
Copy link
Member

Choose a reason for hiding this comment

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

We need to add the full path here so that when importing this from mitiq.benchmarks is possible. I think it's going to look something like this (there might be a formatting change, I'm not 100% sure).

Suggested change
from mitiq.benchmarks import generate_random_clifford_t_circuit
from mitiq.benchmarks.randomized_clifford_t_circuit import (
generate_random_clifford_t_circuit,
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, als checked the formatting and it didn't complain :)

@@ -241,8 +267,15 @@ See Ref. {cite}`Czarnik_2021_Quantum` for more details on these methods.
:members:
```

#### Randomized Clifford+T benchmarking Circuits
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#### Randomized Clifford+T benchmarking Circuits
#### Randomized Clifford+T Circuits

Copy link
Member

@natestemen natestemen 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 Farrokh! Can't wait to do some more testing with these circuits!

🚢

@FarLab FarLab merged commit e2fb5cd into master Dec 15, 2023
14 of 16 checks passed
@FarLab FarLab deleted the fl-random_clifford_t_circuits branch December 15, 2023 19:28
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.

Add a function to generate random Clifford-plus-T circuits.
3 participants