Create an Gateset.__ini__ option to accept classically controlled operations#267
Closed
NoureldinYosri wants to merge 266 commits intomasterfrom
Closed
Create an Gateset.__ini__ option to accept classically controlled operations#267NoureldinYosri wants to merge 266 commits intomasterfrom
NoureldinYosri wants to merge 266 commits intomasterfrom
Conversation
Context: Constructing circuit using Circuit.from_moment instead of passing all the moments to Circuit() can improve the construction performance of Circuit as being suggested by NoureldinYosri@. Also did some minor improvements of imports.
…uli_strings``` method (quantumlib#7416) [PR quantumlib#7236](quantumlib#7236) adds the feature to measure groups of qubit-wise-commuting Pauli operators simultaneously. However, the current implementation generates a separate readout circuit for each individual Pauli operator within a group. This leads to non-simultaneous measurements, which is corrected in this PR.
Merge single qubit gates for symbolized circuits. It is a updated version of quantumlib#7149 where tag_transformers and symbolize transformers are already merged. --------- Co-authored-by: eliottrosenberg <61400172+eliottrosenberg@users.noreply.github.com>
Problem: QVM notebooks use function that is not in stable cirq. This causes failures in nightly builds of cirq docs. Solution: Force cirq upgrade if running with stable cirq. Fixes b/425769714
…antumlib#7383) Fixes quantumlib#7238 1. Create a flag in `DecomposeContext` to configure extraction of terminal gates' global phases into distinct GlobalPhaseGates. a. This flag defaults to False for backward compatibility. 2. Instrument the terminal decomposition gates (X, Y, Z, CZ) to check this flag and extract global phase if it exists. a. Added some convenience methods in GlobalPhaseGate to help. b. Updated some unrelated existing code to use these convenience methods for clarity. 3. Update `ControlledGate.decompose` to attempt decompose the subgate before attempting the brute-force approach. a. This is what ultimately simplifies the decomposition result. b. Step 2 also allowed removal of the entire CZPowGate instanceof block there, since it was about extracting global phase. 4. Add unit tests for each change. --------- Co-authored-by: Noureldin <noureldinyosri@gmail.com>
quantumlib#7390) Fixes quantumlib#6777 I checked that with the current PR, the circuit depth after transpiler matches that obtained by Qiskit. The runtime is slow due `merge_single_qubit_gates_to_phased_x_and_z`. I wrote a different implementation for the special case used by the Shannon decomposition. With this, the runtime is halved. I believe `merge_single_qubit_gates_to_phased_x_and_z` can be optimized too. --------- Co-authored-by: Noureldin <noureldinyosri@google.com>
In order to keep using unit-style input, I have hacked the _resolve_parameters_ function a little bit. Assume all inputs should either be tunit value or sympy.Symbol. (I.e. no sympy expression is allowed). I have to add this since we don't have SymbolFunc or ExprFunc in cirq world.
The following quantum virtual machine notebooks were updated to use the new `willow_pink` processor by default: - quantum_virtual_machine.ipynb - qvm_basic_example.ipynb - qvm_builder_code.ipynb - qvm_stabilizer_example.ipynb Small fixups in other reviewed notebooks. Related to b/395705720
Add FreqMap and AnalogTrajectory into cirq_google.experiments.
In this PR, two major differences compared with Trond did before.
1. `AnalogTrajectory` initialized with classmethod so that the class
member is always full_trajectory
2. Add the resolving ability in the `FreqMap` so that we can provide the
symbol into it and plot it with resolver like `pulse_plot`
New usage example
```py
traj1 = (20 * tu.ns, {"q0_1": 5 * tu.GHz}, {})
traj2 = (sympy.Symbol("t1"), {"q0_2": 8 * tu.GHz}, {})
traj3 = (
40 * tu.ns,
{"q0_0": 8 * tu.GHz, "q0_1": None, "q0_2": None},
{("q0_0", "q0_1"): 5 * tu.MHz, ("q0_1", "q0_2"): 8 * tu.MHz},
)
trajs = [traj1, traj2, traj3]
analog_traj = AnalogTrajectory.from_sparse_trajecotry(trajs)
analog_traj.plot(resolver={"t1": 50*tu.ns})
```
…#7439) Problem: QVM notebooks would use the last stable cirq_google if imported before package upgrade. Solution: Import cirq_google only after its possible upgrade. Fixes b/425769714
There were two nits that I didn't address in the original PR and I do here. For the `for` loop calling `merged_ops.extend()`, I couldn't rewrite it entirely as: ``` merged_ops.extend(_transform_single_qubit_operations_to_phased_x_and_z(qubit_ops, atol=atol) for qubit_ops in pending_ops.values()) ``` because mypy complained about type mismatch: `merged_ops.extend` expects an iterator over `Operation`, but `_transform_single_qubit_operations_to_phased_x_and_z` returns a list of operations, and so with the `for` loop it is an iterator over lists. Co-authored-by: Noureldin <noureldinyosri@google.com>
Problem: Internal documentation build does not support python3.11 yet. Solution: Allow installation for Python 3.10 so that docs build can use latest development releases. Related to quantumlib#6648
…irements/deps (quantumlib#7451) Updates the requirements on [ruff](https://github.com/astral-sh/ruff) to permit the latest version. Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…on-updates group (quantumlib#7449) Bumps the actions-version-updates group with 1 update: [github/codeql-action](https://github.com/github/codeql-action). Updates `github/codeql-action` from 3.28.11 to 3.29.2 Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Remove cirq-rigetti tests from ci-daily.yml - Remove cirq-rigetti tests from ci.yml - Hardcode exclusion of cirq_rigetti in cirq-core unit tests - Drop cirq-rigetti requirements from dev.env.txt - Exclude cirq-rigetti from typecheck Partially implements quantumlib#7297
- Bump the non-security group in /cirq-web/cirq_web with 7 updates - Bump @types/node from 22.15.29 to 24.0.8 in /cirq-web/cirq_web - Rebuild Cirq-web bundle files --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Bump mypy from 1.16.0 to 1.16.1 in /dev_tools/requirements/deps - Let us unify version specs for types-requests and requests --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…st (quantumlib#7459) Avoid possible KeyError in `test_process_pauli_measurement_results_raises_error_on_missing_calibration` Problem: Random Pauli strings generated in the test may not contain all qubits as is assumed in the `empty_calibration_result_dict` key. Solution: Make dictionary with the qubits present in Pauli strings. Fixes spurious test failure ``` pytest --randomly-seed=532866775 \ cirq-core/cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py \ -k test_process_pauli_measurement_results_raises_error_on_missing_calibration ``` Also fix - unnecessarily repeated list construction - unintentional dropping of circuits in a loop - Nit - sync docstring with function arguments
…7440) No change in the effective code. A batch of ~50 files. Modified files pass ruff check --select=ANN201 Partially implements quantumlib#4393
I came across a couple of typos in transformers, so I ask the code assistant to help identify more of them and update all here. --------- Co-authored-by: Pavol Juhas <juhas@google.com>
Adds `max_concurrent_jobs` to the utility function [Engine.get_sampler](https://github.com/dyates/Cirq/blob/b8ca4844ef80102aa83ace1093552f25c02b101a/cirq-google/cirq_google/engine/engine.py#L580) to allow setting the [same field in the `ProcessSampler`]((https://github.com/quantumlib/Cirq/blob/4c7e393eb9fcefcba0c3c509e32cc354197cf014/cirq-google/cirq_google/engine/processor_sampler.py#L37)). This field throttles the number concurrent jobs that are sent to the backend (via `run_batch`). --------- Co-authored-by: Pavol Juhas <juhas@google.com>
- This PR adds the ability to add tags to Moment objects. - tags in Moments function similar to tags in operations, in that they can be any hashable object and are lost if the circuit undergoes transformation, such as by a transformer.
- This is a nice-to-have feature for cirq_google protos, since tests and simulations often use noisy circuits and these could be serialized as well. - This would primarily be used for testing and storage since hardware does not (purposely) execute noise channels.
the cirq RB sequences were often 2-3 times bigger than they should, this is because for historical reasons the cliffords were written as products of X/Z or X/Y gates. In this PR I merge these gates into a single PhasedXZGate which is the same as we do internally. --------- Co-authored-by: Pavol Juhas <pavol.juhas@gmail.com>
First step towards fixing quantumlib#7454. This PR just adds the `tags` attribute to `AbstractCircuit`, along with some of the logic (e.g. `__eq__`, `_json_dict_`, etc). After this we have to add support in the proto serialization itself. Partially implements quantumlib#7454 --------- Co-authored-by: Pavol Juhas <pavol.juhas@gmail.com>
…ntumlib#7466) Fixing MS gate inverse is not implemented correctly (Issue quantumlib#7432) The MS gate has a theta entanglement angle parameter in it's signature, with a 0.25 default value. The problems that need to be corrected here is that when implementing the inverse MS gate the theta parameter is not applied, and instead implicitly its default value is being used when specifying inverse of MS in terms of MS. Code and tests were updated. --------- Co-authored-by: Michael Hucka <mhucka@caltech.edu>
- Make `list_all_notebooks` work from any directory and always return a sorted list of absolute notebook paths. - Determine changed notebooks w/r to the merge base with main, so we only test notebook changes made in our branch. Fixes quantumlib#4458
- Serialize CalibrationTag as a tag rather than use a custom token index field. - This tag was not converted over to the new Tag message since I didn't think anyone was still using it.
Add minimum test methods so these files contain pytest tests. This simplifies test specification at the internal test framework. Related to b/465462872
This renames the workflow file to be the same as used in our other repos, and makes minor updates to the workflow. Compared to previous versions, this also removes the debug parameter and the uploading of SARIF files because we have never used it anyway.
Save test report for scheduled and merge-queue runs. To be used for tracking unit test durations. Related to b/467133647
…umlib#7285) ionq results api can return a list of results or a single result, so this change allows for either a list or single element to be returned from the results endpoint --------- Co-authored-by: Michael Hucka <mhucka@caltech.edu> Co-authored-by: mhucka <mhucka@google.com>
…uantumlib#7793) Fix quantumlib#7784 --------- Co-authored-by: Shashwat Kumar <kshashwat@google.com> Co-authored-by: Pavol Juhas <juhas@google.com>
1. Fix docs path in snippet test and exclude md under hardware and google 2. Fix exec error in md files Partially implements quantumlib#7787 --------- Co-authored-by: Pavol Juhas <juhas@google.com>
List configs
Using the `Engine`
```
engine = cirq_google.get_engine('my-project')
processor_id = 'my-processor'
run_configs = engine.list_configs(
processor_id=processor_id, device_config_revision=Run(id="abc"),
)
snapshot_configs = engine.list_configs(
processor_id=processor_id, device_config_revision=Snapshot(id="xyz")
)
```
Using the processor
```
processor = engine.get_processor('new_processor')
configs = processor.list_configs(device_config_revision=Snapshot(id='snap_id'))
```
---------
Co-authored-by: Michael Qian <michaelbq@google.com>
The `Pytest Ubuntu 3.11` job is required for a PR merge to main, thus every new `main` commit will have test report data. No need to save the report again in scheduled runs. Related to b/467133647
…mlib#7805) The conditions in `_can_add_op_at` are already checked in the while loop. There is no `AbstractDevice` so I removed the check and the note. I also handled the case when `end_moment_index > len(self._moments)`. `earliest_available_moment` references from `insert` are guaranteed to have `end_moment_index` between `0` and `len(self._moments)`, but `earliest_available_moment` is also exposed publicly.
Problem: The CI test "Isolated pytest Ubuntu" may still fail when cirq-core in the repository is copied with intermediate build files. Solution: Use a dedicated copy of cirq-core sources for installation in each module test including when testing cirq-core itself. Also use `logging` instead of `print` in the `cloned_env` fixture as `logging.info` is easier to recover from parallel pytest runs (run pytest with the `--log-level=info` option). Follow-up to quantumlib#6603
…mlib#7808) Provide pytest-benchmark for `has_stabilizer_effect` optimization for PhasedXZGate. Related to quantumlib#7797 and quantumlib#7807
…s_stabilizer_effect (quantumlib#7807) part of quantumlib#7797 this PR reduces the overall runtime of `cirq.has_stabilizer_effect` by 9.7x going down from 120.3s to 12.4s on the benchmark created by Eliott
…7775) After confirming with higher levels of our org that we have the budget for it, I configured customized larger GitHub-hosted runners for the Quantumlib organization. These new runners are 8-core runners for Linux and Windows. (GitHub offers even larger runners, but let's see first how much using 8-cores will speed up the workflows in case there are some other bottlenecks that prevent us from gaining any further advantages.) By contrast, some of the workflows can also make use of `ubuntu-slim` runners, which are faster to start and cheaper to run. As I understand it, those slim runners have only 1 core, so I looked for jobs that don't do things that can be parallelized. The slim runners take longer to run the jobs, but they're priced at 1/8 the cost per minute of the regular runners, and the particular jobs they're being used for are not bottlenecks; thus, the longer execution of these small jobs doesn't affect the overall workflow time. GitHub offers a macos-15-large runner with 12 cores. They're about 10x the price of regular runners, so we want to apply them carefully. Finally, I found that the `pytest -n auto` flag does not make full use of the available vCPUS. It seems to use only 1/2 of the total available. So to make full use of the runners, I changed to `-n logical` to use the number of processors available. Demonstration of the speed improvements: first, a run from yesterday without the changes: Total duration: 12m 18s Now a run (this PR) with the changes: Total duration: 9m 2s --------- Co-authored-by: Pavol Juhas <juhas@google.com>
Scans forward from a given insert location and inserts an operation into the latest possible moment. If no moment is available, inserts the operation in a new moment. Fixes quantumlib#7611
Use analytical formula for the PhasedXZGate unitary resulting in about 6-fold decrease in calculation time. For Eliott's test colab this improves the speed of - `CZGaugeTransformer.as_sweep` by 25% (30 to 23s) - `merge_single_qubit_gates_to_phxz_symbolized` by 15% (77 to 66s) - `merge_single_qubit_moments_to_phxz` by 40% (29 to 17s) Also add pytest benchmarks for `PhasedXZGate` unitary and for the transformation chain in Eliott's colab. Partially implements quantumlib#7797
… real measurement circuits (quantumlib#7801) There is an inconsistency on qubits measurements in readout circuits and measurement circuits. The measurement circuits always measure the full circuit set of qubits, while the qubits being measured in readout/calibration circuits are based only on the qubits present in the Pauli strings. In this PR, I have updated the circuit generation to only measure the qubits relevant to the Pauli group being processed.
…lib#7813) - Avoid conversion of a one-element numpy array to float which throws TypeError in numpy-2.4.0 (was a DeprecationWarning before). - Also run notebook tests with `PIP_CONFIG_FILE=/dev/null` environment. Notebook tests run in a temporary virtual environment to simulate generic colab experience. Here we make them more isolated from local pip settings. --------- Co-authored-by: Michael Hucka <mhucka@google.com>
- Updates `actions/checkout` from 6.0.0 to 6.0.1 - Updates `actions/upload-artifact` from 5.0.0 to 6.0.0 - Updates `codecov/codecov-action` from 5.5.1 to 5.5.2 - Updates `actions/setup-node` from 6.0.0 to 6.1.0 - Updates `github/codeql-action` from 4.31.6 to 4.31.9 - Updates `actions/stale` from 10.1.0 to 10.1.1 Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Bump black[jupyter] from 25.11.0 to 25.12.0. - Bump mypy from 1.19.0 to 1.19.1 - Bump ruff from 0.14.7 to 0.14.10 - Pick up lint found by newer version of ruff, ie, fix ruff ISC004 - implicit-string-concatenation-in-collection-literal --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Bump `@webgpu/types` from 0.1.66 to 0.1.68 - Bump `@vitest/coverage-v8` from 4.0.14 to 4.0.16 - Bump `jsdom` from 27.2.0 to 27.4.0 - Bump `puppeteer` from 24.31.0 to 24.34.0 - Bump `three` from 0.181.2 to 0.182.0 - Bump `@types/three` from 0.181.0 to 0.182.0 - Bump `vite` from 7.2.6 to 7.3.0 - Bump `vitest` from 4.0.14 to 4.0.16 - Bump @types/node from 24.10.1 to 25.0.3 - Rebuild Cirq-web bundle files --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Modifies the config file to the flat format described [here](https://eslint.org/docs/latest/use/configure/migration-guide#start-using-flat-config-files). Also, `.eslintrc.json` has been deprecated in eslint 9, [being replaced by `eslint.config.js`](https://eslint.org/docs/latest/use/migrate-to-9.0.0#-new-default-config-format-eslintconfigjs). Opted to use CommonJS here because it's cleaner, matches up with the [gts README example](https://github.com/google/gts#working-with-eslint) and we shouldn't need to migrate for a while. There are some stricter lint rules introduced by the Typescript updates: ``` @typescript-eslint/no-unused-expressions @typescript-eslint/no-wrapper-object-types ``` that I also patched up in the code. --------- Co-authored-by: Pavol Juhas <juhas@google.com>
- check/pylint - enforce pylint for benchmarks - pylint - add missing copyright notice - check/mypy - enforce type check for benchmarks - Skip type-check for ASV benchmark scripts Not worth fixing as these will be replaced by pytest-benchmark-s. Related to quantumlib#7796
**Description** Implemented the `drop_diagonal_before_measurement` transformer . This transformer identifies diagonal gates (Z, S, T, CZ, etc.) that are immediately followed by measurements. Since diagonal gates commute with the computational basis measurement, they can be removed without affecting the outcome probabilities. **Implementation Details:** 1. **Pre-processing:** Runs `eject_z` first to push Z gates as far right as possible (handling the Z-CZ commutation case described in the issue). 2. **Safety Logic:** Uses strict safety checks. A diagonal gate is only removed if **ALL** qubits it acts on are being measured. - *Example:* `CZ(q0, q1)` followed by `Measure(q0)` is NOT removed (to preserve `q1`'s phase). - *Example:* `CZ(q0, q1)` followed by `Measure(q0), Measure(q1)` IS removed. **Testing:** Added `diagonal_optimization_test.py` covering: - Single qubit removal (Z, S chains). - Multi-qubit safety (CZ removal vs retention). - Commutation blocking (Z blocked by X). - The specific use cases mentioned in the issue. Fixes quantumlib#4935 --------- Co-authored-by: Pavol Juhas <juhas@google.com>
Compare set and frozenset items in a sorted order. Fall back to exact equality for sets that cannot be sorted. Fixes quantumlib#6376 --------- Co-authored-by: Pavol Juhas <juhas@google.com>
…ransformer. (quantumlib#7822) Check measurement and control key commutativity before swapping two operations. Fixes quantumlib#7472 --------- Co-authored-by: Pavol Juhas <juhas@google.com>
…umlib#7830) Problem: Internal mutants test showed that tests pass if the first set-like argument to approx_eq is not sorted. That is because the first argument in test cases happens to have sorted order. Solution: Also test with the first argument of unsorted order. Related to quantumlib#6376 and quantumlib#7792
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.