-
Notifications
You must be signed in to change notification settings - Fork 125
ML-MIPT #389
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
ML-MIPT #389
Conversation
Hi, this PR implements the measurement-induced entanglement experiment targeting Google’s superconducting quantum chip. It is part of our collaboration with the Berkeley (Ehud Altman) and Google Quantum AI (Pedram Roushan) teams, under the ML for MIPT project led by Yi-Zhuang You’s group at UCSD. All tests have passed. Please let me know if any changes are needed. Thank you for your time and review! |
def main() -> None: | ||
"""Main function to run the data collection.""" | ||
# Replace these with your specific engine and processor details | ||
eng = cg.get_engine('your-engine-id') |
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 is actually your GCP (Google Cloud) project ID.
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.
@dstrain115 do you want to take a look at this?
@WandaHou are you interested in making an .ipynb notebook in https://github.com/quantumlib/ReCirq/tree/master/docs to explain your experiment?
@@ -0,0 +1,8 @@ | |||
"""Cluster state measurement implementation at MIPT. |
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.
Could we change the folder name to be lower case, ie. "cluster_state_mipt" to be consistent with the other folders in recirq?
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.
Done.
requirements.txt
Outdated
black | ||
torch>=1.9.0 |
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.
Please add this to recirq/cluster_state_mipt/extra-requirements.txt instead so it is not installed for all modules.
(If we still need this, see above comments)
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 have removed the torch installation, and using numpy to save collected data.
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.
Let's remove this from the requirements then.
@@ -0,0 +1,119 @@ | |||
import cirq # type: ignore | |||
import cirq_google as cg # type: ignore | |||
import numpy as np # type: ignore |
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.
Why is this annotated # type: ignore? You should be able to configure mypy to not follow external packages if that's the issue.
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.
Got it, # type: ignore is removed.
import cirq_google as cg # type: ignore | ||
import numpy as np # type: ignore | ||
|
||
def get_two_qubits_6x6(d=6): |
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.
Please add a docstring for this function.
Also explain what d is (and maybe change it to a more descriptive name).
If d is the size of the grid, then also change the name of the function, since it is only 6x6 if d=6.
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.
“d” here refers to the spatial separation of the probe qubit pair. In our experiment, it can take values of 3, 4, 5, or 6 in a 6x6 grid. I’ve added a docstring to clarify this.
[np.array(qubits_matrix).flatten()]+[np.array(anc_pair_set).flatten() for anc_pair_set in anc_pairs])) | ||
return qubits_matrix, probe_qubits, anc_pairs, all_qubits | ||
|
||
def get_circuit(qubits_matrix, theta, phi, probe_qubits, basis=[0,0], anc_pairs=[]): |
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.
Please add docstring.
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 have added docstring.
|
||
|
||
def collect_data( | ||
eng: cg.Engine, |
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.
nit: recommend engine instead of eng.
Avoid abbreviations, as per:
https://google.github.io/styleguide/pyguide.html#316-naming
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 have changed it to engine and also in other places.
theta_range = np.linspace(0, np.pi/2, 11) | ||
phi = np.pi*(5/4) | ||
|
||
for d in [5]: |
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.
Why is this a for loop if it only has one value?
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 this to "for d in [3, 4, 5, 6]:" to iterate over different probe qubit distances.
for d in [5]: | ||
qubits_matrix, probe_qubits, anc_pairs, all_qubits = get_two_qubits_6x6(d=d) | ||
for theta_idx in range(len(theta_range)): | ||
for i in range(5): # iterations |
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.
nit: rather than "for i in range(5): # iterations" use "for iterations in range(5):" to be self-documenting.
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.
Done.
measurements = torch.cat([ | ||
torch.tensor(r[0].measurements['m']).to(int) | ||
for r in result]) | ||
torch.save( |
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.
Are we importing all of pytorch just to save a file? Do we really need pytorch to save a matrix to a file?
Could we, instead, use cirq's json serialization instead, for example?
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’ve changed the code to use NumPy for saving the data. Previously, we used PyTorch because the next step in the research involved applying machine learning methods to detect quantum entanglement. However, since we’re now only presenting the circuit construction, I switched to NumPy to eliminate the need for installing PyTorch.
@@ -0,0 +1,119 @@ | |||
import cirq # type: ignore |
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.
All of these files need to have an Apache copyright header. See other files in ReCirq for an example.
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 have added Apache copyright header with year 2025.
@dstrain115 All the issues should be addressed now—let me know if there’s anything else I should update! |
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.
LGTM after the last comments.
recirq/cluster_state_mipt/README.md
Outdated
|
||
## Dependencies | ||
|
||
- Cirq >= 0.13.0 |
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.
nit: These dependencies are pretty old (older than the reCirq requirements), so we probably don't need to specify them here, as installing the module via pip will satisfy these.
recirq/cluster_state_mipt/README.md
Outdated
- Cirq >= 0.13.0 | ||
- Cirq-Google >= 0.13.0 | ||
- NumPy >= 1.19.0 | ||
- PyTorch >= 1.9.0 (for data collection) |
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.
Remove if we no longer need this.
requirements.txt
Outdated
black | ||
torch>=1.9.0 |
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.
Let's remove this from the requirements then.
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.
LGTM, thanks for doing the changes!
@@ -0,0 +1,8 @@ | |||
"""Cluster state measurement implementation at MIPT. |
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 even init.py are supposed to have copyright notice.
It is telling me: The failing test, test_size_independence_muinf, in the recirq/kpz/experiment_test.py file is caused by the np.isclose assertion for kurtosis. What do you suggest me to do next step? @dstrain115 |
Could be a flaky test. I re-ran it. |
@WandaHou I think that's my fault for writing a non-deterministic test. I can fix it by passing a fixed seed to the random number generator. |
Hi, just want to make sure, should I do further action to push this into the main branch? |
@WandaHou I know I'm a little late in pointing this out, but you probably also want to update this file to add your work to the table of contents on the website: https://github.com/quantumlib/ReCirq/blob/master/docs/_index_included.yaml. |
Actually, I guess you never made a notebook for the |
This pull request adds code for studying cluster states and measurement-induced entanglement in quantum systems using Cirq. The implementation targets a 6×6 qubit grid with ancilla qubits for readout error mitigation and includes support for circuit construction and data collection.
Key components include:
• Cluster state circuit generation with Hadamard, CZ, and single-qubit rotations
• Basis rotations for measurement in X, Y, Z bases with configurable probe qubits
• Distance-dependent entanglement measurements between probe qubits
• Data collection framework with randomized compiling for error mitigation
The code uses Google’s Cirq framework and is designed to run on quantum processors through Cirq-Google. It builds circuits on a fixed 6×6 qubit grid, with a configurable probe separation distance (d = 3–6) and support for various measurement bases, enabling the study of entanglement properties in cluster states.
The testing framework ensures parameter validation and circuit structure without requiring actual quantum execution, making it suitable for CI/CD pipelines while preserving the ability to run on real quantum hardware.