Skip to content

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

Merged
merged 36 commits into from
May 26, 2025
Merged

ML-MIPT #389

merged 36 commits into from
May 26, 2025

Conversation

WandaHou
Copy link
Contributor

@WandaHou WandaHou commented May 16, 2025

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.

@WandaHou WandaHou closed this May 16, 2025
@WandaHou WandaHou reopened this May 16, 2025
@WandaHou
Copy link
Contributor Author

WandaHou commented May 17, 2025

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')
Copy link
Contributor

@eliottrosenberg eliottrosenberg May 17, 2025

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.

Copy link
Contributor

@eliottrosenberg eliottrosenberg left a 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.
Copy link
Collaborator

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?

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.

requirements.txt Outdated
black
torch>=1.9.0
Copy link
Collaborator

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)

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 removed the torch installation, and using numpy to save collected data.

Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Contributor Author

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):
Copy link
Collaborator

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.

Copy link
Contributor Author

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=[]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add docstring.

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 added docstring.



def collect_data(
eng: cg.Engine,
Copy link
Collaborator

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

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 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]:
Copy link
Collaborator

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?

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 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
Copy link
Collaborator

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.

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.

measurements = torch.cat([
torch.tensor(r[0].measurements['m']).to(int)
for r in result])
torch.save(
Copy link
Collaborator

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?

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’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
Copy link
Collaborator

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.

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 added Apache copyright header with year 2025.

@WandaHou
Copy link
Contributor Author

@dstrain115 All the issues should be addressed now—let me know if there’s anything else I should update!

Copy link
Collaborator

@dstrain115 dstrain115 left a 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.


## Dependencies

- Cirq >= 0.13.0
Copy link
Collaborator

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.

- Cirq >= 0.13.0
- Cirq-Google >= 0.13.0
- NumPy >= 1.19.0
- PyTorch >= 1.9.0 (for data collection)
Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Collaborator

@dstrain115 dstrain115 left a 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.
Copy link
Collaborator

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.

@WandaHou
Copy link
Contributor Author

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

@dstrain115
Copy link
Collaborator

Could be a flaky test. I re-ran it.

@eliottrosenberg
Copy link
Contributor

@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.

@WandaHou
Copy link
Contributor Author

Hi, just want to make sure, should I do further action to push this into the main branch?

@dstrain115 dstrain115 merged commit 00b51f6 into quantumlib:master May 26, 2025
5 checks passed
@eliottrosenberg
Copy link
Contributor

@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.

@eliottrosenberg
Copy link
Contributor

Actually, I guess you never made a notebook for the docs folder, so never mind.

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.

3 participants