-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Extract BufferedDM/SV/MPS from ActOnDM/SV/MPSArgs #4979
Conversation
@95-martin-orion this is ready if you want to review. If it's too big I can break into pieces, but really it's just moving some code around, doing the same thing three times. I added a fairly detailed description above. |
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 seems pretty reasonable - not a whole lot happening here, but #4827 paints a good picture of how it leads towards a cleaner structure in the future.
backward_inds = [conj_pfx + forward_ind for forward_ind in forward_inds] | ||
return partial_trace.to_dense(forward_inds, backward_inds) | ||
|
||
def to_numpy(self) -> np.ndarray: | ||
"""An alias for the state vector.""" | ||
return self.state_vector() | ||
|
||
def apply_op(self, op: 'cirq.Operation', prng: np.random.RandomState): | ||
def apply_op(self, op: Any, axes: Sequence[int], prng: np.random.RandomState): |
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.
op
is an Any
again - where do we call this with non-Operations?
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 a good question. Two things here. First, nothing in the implementation requires an operation; it'll work for anything that implements unitary or mixture protocols. So it makes sense to bubble up that flexibility.
Second, I think this fits better with the way protocols are generally designed in cirq. In particular, note that as of this PR, all strategies for all simulators in _act_on_fallback_
now accept Any
. I was planning a future PR where we change the type of cirq.act_on
protocol to Any
as well. (I'm pretty sure I probably changed that the other direction a long time ago too--but that was back when all the simulators were implemented independently and we needed some structure). This function is called by MPS _act_on_fallback_
, so needs to support Any
in order for act_on
to be able to support it in the future. (Kind of related #4400)
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.
Also to note, this is a private type. If we ever make it public, then we can revisit whether some of these functions should be hidden. We could have a public apply_op(Operation)
and a private _apply_op(Any)
if that makes the API surface nicer.
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 will make it into the v0.14 release - if you see this before the checks complete, you can adjust the deprecation deadlines to v0.15, otherwise no big deal.
Creates a base class for all the quantum state classes created in #4979, and uses the inheritance to push the implementation of `ActOn<State>Args.kron`, `factor`, etc into the base class. Closes #4827 Resolves #3841 (comment) that's been bugging me for a year.
* Extract BufferedDensityMatrix from ActOnDensityMatrixArgs * state vector * clean up code * clean up code * clean up code * format * docs * test * coverage * improve state vector * improve state vector * replace deleted functions * replace deleted functions * replace deleted functions * replace deleted functions * lint * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * coverage * fix merge errors * Code review comments * Remove todo Co-authored-by: Orion Martin <[email protected]>
Creates a base class for all the quantum state classes created in quantumlib#4979, and uses the inheritance to push the implementation of `ActOn<State>Args.kron`, `factor`, etc into the base class. Closes quantumlib#4827 Resolves quantumlib#3841 (comment) that's been bugging me for a year.
* Extract BufferedDensityMatrix from ActOnDensityMatrixArgs * state vector * clean up code * clean up code * clean up code * format * docs * test * coverage * improve state vector * improve state vector * replace deleted functions * replace deleted functions * replace deleted functions * replace deleted functions * lint * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * coverage * fix merge errors * Code review comments * Remove todo Co-authored-by: Orion Martin <[email protected]>
Creates a base class for all the quantum state classes created in quantumlib#4979, and uses the inheritance to push the implementation of `ActOn<State>Args.kron`, `factor`, etc into the base class. Closes quantumlib#4827 Resolves quantumlib#3841 (comment) that's been bugging me for a year.
* Use Boolean Hamiltonian gates for QAOA example * Don't use deprecated function * More deprecation * Deprectate log_of_measurement_result input (#5100) Co-authored-by: Cirq Bot <[email protected]> * Improve support for recursively applying transformer primitives on circuit operations using `deep=True` (#5103) - Part of fixing #5039 - Fixes multiple bugs and improves support for `deep=True` flag in transformer primitives. * Add support for deep=True flag to remaining transformer primitives (#5106) * Add `assert_decompose_ends_at_default_gateset` to consistent protocols test to ensure all cirq gates decompose to default gateset (#5107) * Extract BufferedDM/SV/MPS from ActOnDM/SV/MPSArgs (#4979) * Extract BufferedDensityMatrix from ActOnDensityMatrixArgs * state vector * clean up code * clean up code * clean up code * format * docs * test * coverage * improve state vector * improve state vector * replace deleted functions * replace deleted functions * replace deleted functions * replace deleted functions * lint * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * coverage * fix merge errors * Code review comments * Remove todo Co-authored-by: Orion Martin <[email protected]> * Bugfixes in handling nested tags_to_ignore + deep=True in `cirq.map_moments` and `cirq.map_operations` transformer primitives (#5109) - Fixes a few more bugs in the handling of deep=True flag and nested operations to ignore using `tags_to_ignore` in `cirq.map_operations` and `cirq.map_moments` transformer primitives. Also added more tests. - Step towards fixing #5039 * Add `add_deep_support ` flag to `@cirq.transformer` decorator (#5108) * Add flag to @cirq.transformer decorator * Fix mypy type errors and remove typos * Rename add_support_for_deep to add_deep_support * Add support for deep=True to `cirq.drop_empty_moments` transformer (#5113) - Adds support to recursively run `cirq.drop_empty_moments` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of #5039 * Add support for deep=True to `cirq.drop_negligible_operations` transformer (#5114) - Adds support to recursively run `cirq.drop_negligible_operations` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of #5039 * Add support for deep=True to `cirq.stratified_circuit` transformer (#5117) - Adds support to recursively run `cirq.stratified_circuit` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of #5039 * Add support for deep=True to `cirq.synchronize_terminal_measurements` transformer (#5118) - Adds support to recursively run `cirq.synchronize_terminal_measurements` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of #5039 * Add support for deep=True to `cirq.expand_composite` transformer (#5119) - Adds support to recursively run `cirq.expand_composite` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Note that this does not rely on `preserve_structure` argument of `protocols.decompose` because the latter does not support handling nested circuit operations tagged with a no-compile tag (the added tests would fail if we rely on protocols.decompose(preserve_structure=True) instead transformer primitives). Hence, I would argue that we should deprecate the preserve_structure=True flag in protocols.decompose in-favour of this transformer. cc @95-martin-orion - Part of #5039 * Add support for deep=True to `cirq.eject_phased_paulis` transformer (#5116) - Adds support to recursively run `cirq.eject_phased_paulis` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of #5039 * Add support for deep=True to `cirq.align_left` and `cirq.align_right` transformers (#5112) - Adds support to recursively run `cirq.align_left` and `cirq.align_right` transformers on circuits wrapped inside a circuit operation by setting `deep=True` in transformer context. - Part of #5039 * Add support for deep=True to `cirq.eject_z` transformer (#5115) - Adds support to recursively run `cirq.eject_z` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of #5039 * Add support for deep=True to cirq.merge_k_qubit_unitaries transformer (#5122) * Add support for deep=True to merge_single_qubit_gates* transformers (#5123) - Adds support to recursively run `cirq.merge_single_qubit_moments_to_phxz` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Also adds tests for `cirq.merge_single_qubit_gates_to_phxz` and `cirq.merge_single_qubit_gates_to_phased_x_and_z`, both of which automatically support deep=True flag after #5122 - Part of #5039 * Add support for deep=True to `cirq.optimize_for_target_gateset` transformer (#5124) - Adds support for `deep=True` flag to `cirq.optimize_for_target_gateset` which enables optimizing circuits preserving the sub-circuit structure (i.e. without unrolling circuit operations). - Part of #5039 * Bugfix in handling of deep=True flag in `cirq.merge_k_qubit_unitaries` transformer (#5125) - Fixes a bug in `cirq.merge_k_qubit_unitaries` due to which the transformer was applied recursively only on circuit operations satisfying `cirq.num_qubits(op) <= k and cirq.has_unitary(op)`. Fixed the bug and added more tests. - Part of #5039 * DeviceSpecification proto updates (#5056) Part of #5050 Since each gate has its own message now, target specification could potentially be moved inside gate messages (e.g. for 2-qubit gates) or disappear entirely and embed the target set in Cirq (e.g. measurement). This is lower priority since there are no major problems with the existing setup, so deferring this for now and get back to it before Cirq 1.0 if there's time. Micro-optimization: Leaving `GateSpecification` field numbers < 16 empty to allow for potential future common fields. @dstrain115 @maffoo * Add support for deep=True flag in `cg.optimized_for_sycamore` and `cg.SycamoreTargetGateset` transformers (#5126) - Adds support for deep=True flag in `sycamore_gateset.merge_swap_rzz_and_2q_unitaries` transformer - Updates `cg.optimized_for_sycamore` to call `cirq.optimize_for_target_gateset` with `deep=True` by default, such that the method preserves circuit structure by default (which corresponds to its old behavior). - Fixes #5039 * Rename TestDevice -> FakeDevice to avoid pytest confusion (#5066) Pytest tries to collect `TestDevice` as a test class, and fails with the following wraning: ``` cirq-core/cirq/circuits/circuit_dag_test.py:24 cirq-core/cirq/circuits/circuit_dag_test.py:24 /home/runner/work/Cirq/Cirq/cirq-core/cirq/circuits/circuit_dag_test.py:24: PytestCollectionWarning: cannot collect test class 'TestDevice' because it has a __init__ constructor (from: cirq-core/cirq/circuits/circuit_dag_test.py) class TestDevice(cirq.Device): ``` * Add iterator support for AbstractJob (#5136) - Add support for next() in AbstractJob - Changes __iter__ to return a generator, which will have support for iteration in for loops, as well as next(). - Also improve the iteration tests to be more thorough and accurate. Fixes: #5120 * Pin Jinja2 version for build_docs CI. (#5138) See CI failure here: #5134 * Bump cirq version to 0.15.0 (#5134) Bumps working version to v0.15.0 * Bump minimist from 1.2.5 to 1.2.6 in /cirq-web/cirq_ts (#5140) Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/substack/minimist/commit/7efb22a518b53b06f5b02a1038a88bd6290c2846"><code>7efb22a</code></a> 1.2.6</li> <li><a href="https://github.com/substack/minimist/commit/ef88b9325f77b5ee643ccfc97e2ebda577e4c4e2"><code>ef88b93</code></a> security notice for additional prototype pollution issue</li> <li><a href="https://github.com/substack/minimist/commit/c2b981977fa834b223b408cfb860f933c9811e4d"><code>c2b9819</code></a> isConstructorOrProto adapted from PR</li> <li><a href="https://github.com/substack/minimist/commit/bc8ecee43875261f4f17eb20b1243d3ed15e70eb"><code>bc8ecee</code></a> test from prototype pollution PR</li> <li>See full diff in <a href="https://github.com/substack/minimist/compare/1.2.5...1.2.6">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=minimist&package-manager=npm_and_yarn&previous-version=1.2.5&new-version=1.2.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/quantumlib/Cirq/network/alerts). </details> * Remove deprecated two_qubit_matrix_to_diagonal_and_operations and two_qubit_matrix_to_operations (#5102) see title. * Fix broken caching in CliffordGate and add test (#5142) Looks like copy-pasta errors to me. Also update a test to being parameterized and complete. * Cleanup docs/noise.ipynb in preparation for Cirq 1.0 launch (#5147) * Speed up a slow transformer test (#5146) This test was the slowest that we run, 45 seconds, so I cut down on the parameterized range. @tanujkhattar * Make pylint parallel (#5144) On my local machine this took pylint from 3 minutes to less than one. * [workflow] Preliminary timing information (#5021) Add a `RuntimeInfo` field to store timing information. Augment the `execute` loop to record some basic timing info. Provide a utility context manager to make it easier to record timing information. * Add docstring for `cirq.TRANSFORMER` public object (#5149) Adds docstring for `cirq.TRANSFORMER` public object. The api reference automatically creates a reference page for the public object, and currently inherits the docstring from the `Protocol` base class, which is irrelevant and the PR fixes it. * Base class for quantum states (#5065) Creates a base class for all the quantum state classes created in #4979, and uses the inheritance to push the implementation of `ActOn<State>Args.kron`, `factor`, etc into the base class. Closes #4827 Resolves #3841 (comment) that's been bugging me for a year. * Allow any object with supporting protocols to be the action in act_on (#5111) * Allow any object with supporting protocols to be the action in act_on * lint * Fix raiser is not callable. (#5155) Appears to have broken other PRs. https://github.com/quantumlib/Cirq/runs/5724527312?check_suite_focus=true * Corrected result.data implementation. (#5153) When looking into #4774 auto type promotion to objects raised a ValueError and was not tested. This PR fixes this and introduces the intended behavior as well as boosting performance slightly when qubit counts are < 64. * Support specific IonQ targets (qpu.generation) (#5141) * Support specific IonQ targets Allows for more specific backend targets. * fmt * Upgrade black to stable version with format stability guarantees (#5157) Version [22.1.0](https://black.readthedocs.io/en/latest/change_log.html#id1) is the first non-beta version of black and has a new [stability policy](https://black.readthedocs.io/en/stable/the_black_code_style/index.html#stability-policy). The last time we bumped the black version in #4753 we did not actually reformat any code, so we could do that here and just rely on incremental formatting going forward, or we could do a global reformat to bring things up to date as we did when we originally switched to black in #3516. I think the changes this time would be much less drastic than in the original switch. The main thing we've seen internally is tighter binding of the power operator, e.g. new black does `a**b + c**d` instead of `a ** b + c ** d`, which is a definite improvement. * Format cirq-core with latest version of black (#5159) Review: @dabacon * Clarify virtual tag docstring (#5161) Propose that instead of changing whether virtual tags are applied to noise models, we instead just clarify what it means to be virtual. Fixes: #2984 * Format cirq-google with latest version of black (#5160) Follow-up to #5157. Format code in cirq-google to ensure these formatting changes don't get mixed in with future logic changes. * Ignore large-scale formatting changes for git blame (#5162) Follow-up to #5159 and #5160. Ignore these large-scale formatting changes when goind git blame, as suggested by @dabacon. * Remove --pre from notebooks after release. (#5135) For review after #5134 * Update to pylint 2.13 (#5156) Review: @mpharrigan * Update educators/intro.ipynb in preparation for Cirq 1.0 launch (#5163) * Updated the educator intro notebook to remove deprecated items and introduce newly added concepts like gatesets and transformers. * Part of docs cleanup effort in preparation of Cirq 1.0 launch. * Disable broken symbols. (#5165) * Autoformat all of engine_client_test.py (#5164) ReviewL @dabacon * Allow specifying timeout_seconds when constructing an ionq Sampler (#5133) * Allow specifying timeout_seconds when constructing an ionq Sampler This allows users of tensorflow quantum to use a high timeout and https://github.com/tensorflow/quantum/blob/f10d36b64761a003fd542392767fa079d57df0aa/tensorflow_quantum/python/quantum_context.py\#L82-L101 to run highly parallel workloads that may take very long times per-job without flakiness. * fmt * Python map * Coverage * Remove reservation colab (#5168) - We no longer need this colab, as the UI now supports all reservation operations and is much easier. Fixes: #3588 * Add Google-specific variant for noise properties. (#5082) This PR provides an implementation of `SuperconductingQubitsNoiseProperties` for Google hardware. Now that SQNP is an abstract type, this is a prerequisite for re-enabling calibration-to-noise tools. This is part 3 of #4666; part 2 was #4964. Remaining steps include: - Reinstatement of calibration_to_noise_properties using new types - Reinstatement of compare_generated_noise_to_metrics using new types * Update docs/transform.ipynb based on new transformer framework. (#5154) Fixes #4960 This notebook provides a high level overview of all the newly added features to Cirq's transformer infrastructure. We can discuss whether we need more details docs on each of the specific topics -- I think a high level overview with links to reference pages of individual methods (i.e. the current PR) should be enough to close #4960, but I'm curious to hear what others think. * Enforce same control order in ControlledGate equality check (#5131) **Breaking Change** Changes ControlledGate equality check to enforce gates have same order. Fixes #5110 * Fix gates.ipynb formatting (#5175) - Move import cirq up into top block. - Clear outputs. * Cleaning up cirq/install docs (#5178) * Corrected virtual environment link. * Replaced Foxtail with Sycamore. * Fix docs/circuits.ipynb as part of docs cleanup for Cirq 1.0 (#5177) - Remove output - Move import to top - Minor changes to content (add `cirq.` prefix to many quoted words) - Remove broken link to devices.ipynb * Update simulator docs (#5182) Quick cleanup pass for simulator docs. Nontrivial changes: - include note for `seed` parameter of simulator - remove comments about modifying StepResult state (deprecated) - clarify pure/mixed state behaviors and advantages - external simulator focus: qsim++, qFlex-- Everything else is cleaning format and refreshing links. * Fix broken link from cirq/tutorials page as part of docs cleanup (#5174) Removes broken link from cirq/tutorials as part of docs cleanup. * Convert start.md to start.ipynb. (#5176) Converts `start.md` -> `start.ipyb`. This lets us run the code block and make the notebook runnable in colab by our users. * Update google concepts doc. (#5186) * Update google concepts doc. - Remove form for applying to EAP program. - Remove references to simulators. - Change images to remove simulators. - Remove dangling "Installing cirq". - Add commas and improve sentences in a few places. Co-authored-by: Matthew Neeley <[email protected]> * Fix docs/qubits.ipynb as part of docs cleanup for Cirq 1.0 (#5179) - Move import to top * Minor cleanup of QCS tutorial (#5184) @dstrain115 @MichaelBroughton @wcourtney * Link fix on start page. (#5191) Remove extra paranthesis. * Neutral atom update (#5192) Updates neutral atom tutorial to remove uses of deprecated device behavior. * Remove use of deprecated device behavior from quantum_volume_errors. (#5198) Title * Remove BooleanHamiltonian object (#5099) Now that v0.14 is released, delete deprecate object * Refactor qcs_notebook to use application default creds (#5045) Review: @95-martin-orion * Cirq web supports LineQubits (#5211) This would be to fix #5173 * Import new gapic generated code for quantum engine API (#5139) This is some very preliminary work to import new generated code for the quantum engine API. Of note is that the new code includes async support and is now using [proto-plus](https://github.com/googleapis/proto-plus-python) rather than the standard generated proto code for messages. * Fix basics (#5180) Cleans up basics.ipynb and removes mention of old devices behavior. * Deprecate `gate_set` parameter on engine classes. (#5207) Fixes #4995 Review: @verult * Tweak quantum walks doc (#5212) * Tweak quantum walks doc - Removed output cells and tweaked imports - Move print out of function. * Deprecate json_serializable_dataclass (#5208) Fixes #4460 * Fix error and add test for mutable pauli string (#5213) #4001 looks abandoned so this does the change and adds the test as requested. * Fix tutorials/state_histograms.ipynb as part of docs cleanup for Cirq 1.0 (#5206) * Cleared output * Fixed broken links * Minor improvements in content * Fix tutorials/heatmaps.ipynb as part of docs cleanup for Cirq 1.0 (#5205) * Cleared output * Fixed typos and broken links * Changed language to second person * Remove some 0.15 items from cirq.sim (#5137) This covers most of the deprecations for `cirq.sim` in 0.15. The two remaining ones have some challenges: * Removing `target_tensor` etc from the initializers and replacing with `initial_state`: The repr still emits `target_tensor` so it wouldn't round-trip. * Removing `log_of_measurement_results`: Same thing. Plus we forgot to deprecate it in a couple places. Also this closes #3898, as the pattern we used to deprecate `copy` without parameters works well. * Add Cynocracy to owners of cirq-ionq (#5145) @Cynocracy let me know if you want to remove any of the others, or keep them as is. * Fix educators/qaoa_ising.ipynb as part of docs cleanup for Cirq 1.0 (#5204) * Moved cirq import to top * Cleared output * Fixed typos in text * Improve documentation about writing type annotations (#5218) Fixes #4383 * customer_gates.ipynb - minor content cleanup (#5215) cc @tanujkhattar * Make _commutes_ consistent (#5217) - Requires atol to be a named parameter. - Also changes atol to be uniformly float around the codebase. (not sure why it would be int, are people using an atol=1?) - Technically a breaking change, but it's unlikely people are using this widely as most commutes do not even use atol. Fixes: #3695 * Fix numpy annotations np.array -> np.ndarray (#5227) `np.array` is not a valid type, but rather a factory function for creating arrays. The actual type is `np.ndarray`. This change reduces the number of `check/mypy --next` errors by >60% from 244 to 96 on my machine. * Delete the target_tensor parameter that was deprecated in 0.15 (#5225) A few simulators used either initial_state or target_tensor to initialize their ActOnArgs. We deprecated the latter in 0.15. This PR deletes those. Note that one follow-on change included here is that the repr functions needed to be changed to emit the field as `initial_state` too. (I wish I'd just called it `quantum_state` now, but oh well). @95-martin-orion I also went ahead and removed the buffer from the repr, since it is just noise. * Deprecate the ActOnArgs._on_* methods (#5224) Now that we have separated out the `QuantumStateRepresentation` from `ActOnArgs`, there is no need for the `_on_*` methods anymore. This PR deprecates those, adds deprecation tests, and updates any old test ActOnArgs to use the new QuantumStateRepresentation internally. @95-martin-orion * Allow specifying initial state vector in DensityMatrixSimulator (#5223) This changes how ActOnDensityMatrixArgs is constructed to allow specifying the initial state as a state vector or state tensor, or as a density matrix or density tensor. Some of this could perhaps be moved into `cirq.to_valid_density_matrix` if people think that is a better place. Currently `to_valid_density_matrix` only handles 1D state vectors or 2D density matrices, not 2x2x..2 tensors in either case, but if we have the qid_shape we can tell handle these unambiguously. Fixes #3958 * Unquote example code in ArithmeticOperation (#5230) Fixes #5228 (I hope) * Document CircuitOp optimizer best practices (#5221) Final item for #3634. With the new transformers, there is a clean pipeline for optimizing nested circuits and sending the (concise!) result to hardware for execution. * Remove the deprecated mutators in cirq/ops (#5201) Removes all the deprecated mutators. * Allow server-side warnings from IonQ (#5222) This will be used to notify users about deprecations and changes to the API without needing to update Cirq independently. * Fix educators/textbook_algorithms.ipynb as part of docs cleanup for Cirq 1.0 (#5199) * Fixes typos * Removes outputs * Move import to top * Fix qcvv/xeb_theory.ipynb as part of docs cleanup for Cirq 1.0 (#5202) * Moved import to top * Fixed broken link to quantum ai website * Minor improvements in text formatting * Cleaning up tutorials/variational_algorithm.ipynb (#5185) * Move cirq import to top * Remove outputs * Document CIRCUIT_TYPE and hide other typevars/aliases in circuits.py (#5229) Fixes #5150 (assuming this renders nicely on the docsite; how can I check that locally?) This adds an underscore prefix to hide some type aliases and type vars that are not part of the public interface of the module. Also adds a docstring to the `CIRCUIT_TYPE` variable, which is used in a few other places. * Make check scripts run pytest in parallel (#5143) The tests were made parallel in CI, but this updates the scripts to run in parallel. Respects if user overrides with different level of parallelism. * cirq-ionq: Retry non-standard cloudflare errors (#5237) * Add q helper function for constructing common qubit types. (#5181) * Add q helper function * fmt * Ignore static type errors in tests * Ignore intentional type errors * Fix Raises docstring * Fixes from review * Use *args * remove unused import * Unpin sympy and ignore sympy type errors (#5226) Fixes #5058 Review: @dabacon * Add calibration-to-noise pipeline (#5187) This PR reinstates the cirq_google utility for converting `Calibration` objects to noise properties. To create a simulator with behavior that mimics some `Calibration` "cal", the expected usage is: ```python noise_props = cg.noise_properties_from_calibration(cal) noise_model = cg.NoiseModelFromGoogleNoiseProperties(noise_props) simulator = cirq.Simulator(noise=noise_model) # will mimic noise from `calibration` ``` This is part 4 of #4666; part 3 was #5082. Remaining steps include: - Convenience methods for modifying noise properties - Reinstatement of compare_generated_noise_to_metrics using new types * Remove device from circuits (#5189) Removes v0.15 deprecation items for attaching devices to circuits. * Bump tensorflow-docs version (#5250) * Fix tutorials/qaoa.ipynb as part of docs cleanup for Cirq 1.0 (#5200) * Change example device from `cg.Bristlecone` (now deprecated) to `cg.Sycamore`. * Use new GridDeviceMetadata instead of deprecated device properties (like neighbors_of) * Move import to top * Clear outputs * Remove custom cirq_type (#5249) Custom `cirq_type` was deprecated in #4704 and not necessary for internal types. * Skip "magic trailing comma" when formatting with black (#5170) The "magic trailing comma" is a comma at the end of bracketed list that forces black to format the list entries on separate lines, even if they would fit on one line. For example, if you write: ```python foo(a, b,) ``` black will see that trailing comma and format this as: ```python foo( a, b, ) ``` But with the `skip-magic-trailing-comma` setting enabled this will format on a single line instead ```python foo(a, b) ``` IME the trailing commas are almost always unintentional, e.g. left over from other refactos, and result in wasted vertical space. I suggest we enable this flag. * Remove deprecated log_of_measurement_results parameters (#5233) * deprecate log_of_measurement_results * Fix test * coverage * Add empty ClassicalDataDictionaryStore.repr test * Add ActOnArgs test * Add tests * Add ActOnStabilizerArgs tests * nits * coverGE * format Co-authored-by: Cirq Bot <[email protected]> * Make the quantum state generic (#5255) * Migrate google/best_practices.md to google/best_practices.ipynb as part of docs cleanup for Cirq 1.0 (#5236) - Fixes bugs in code demonstrating use of circuit operations and compiling them using new transformers. Follow up of #5221 * Format cirq-google with skip-magic-trailing-comma (#5171) Review: @95-martin-orion * Format according to new black rules (#5259) Follow up by will add hash to .git-blame-ignore-revs * Ignore skip-magic-trailing-comma formatting with git blame (#5257) This adds a formatting commit to ignore when doing git blame. * Use sorted instead of set for random.sample (#5248) * Fix Docs: cirq/tutorials/educators/chemistry (#5251) * Convenience methods for modifying GoogleNoiseProperties (#5188) * Add override methods. * Mypy passes, weak typing * Resolved mypy conundrum * with_params * Deprecate Gateset.accept_global_phase_op (#5239) Deprecates Gateset.accept_global_phase_op **Breaking Change:** Changes the default value of `Gateset.accept_global_phase_op` from `True` to `False`. I can't think of any way to remove this parameter without eventually needing this breaking change. Currently all gatesets that are created allow global phase gates if they don't specify `accept_global_phase_op=False` explicitly. But the end goal is only to allow global phase gates if they're included in the `gates` list. So at some point in the transition the default behavior needs to break, and I can't think of a way of doing that via deprecation. Therefore I think we may as well do it now via this breaking change. Note that even though it's breaking, it isn't breaking in a bad way. Users who are adding global phase gates to things that suddenly don't accept them will just see an error that the gate is not in the gateset, and then go add it. It's much safer than breaking in the other direction in which we silently start allowing new gate types. Closes #4741 @tanujkhattar * Exclude TYPE_CHECKING from docs (#5261) This would be an attempt to fix #5231 * Add unit test Co-authored-by: Dax Fohl <[email protected]> Co-authored-by: Cirq Bot <[email protected]> Co-authored-by: Tanuj Khattar <[email protected]> Co-authored-by: Orion Martin <[email protected]> Co-authored-by: Cheng Xing <[email protected]> Co-authored-by: Matthew Neeley <[email protected]> Co-authored-by: Doug Strain <[email protected]> Co-authored-by: MichaelBroughton <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Dave Bacon <[email protected]> Co-authored-by: Matthew Harrigan <[email protected]> Co-authored-by: Jon Donovan <[email protected]> Co-authored-by: Matthew Neeley <[email protected]> Co-authored-by: Timo Eckstein <[email protected]> Co-authored-by: Dax Fohl <[email protected]>
* Extract BufferedDensityMatrix from ActOnDensityMatrixArgs * state vector * clean up code * clean up code * clean up code * format * docs * test * coverage * improve state vector * improve state vector * replace deleted functions * replace deleted functions * replace deleted functions * replace deleted functions * lint * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * coverage * fix merge errors * Code review comments * Remove todo Co-authored-by: Orion Martin <[email protected]>
Creates a base class for all the quantum state classes created in quantumlib#4979, and uses the inheritance to push the implementation of `ActOn<State>Args.kron`, `factor`, etc into the base class. Closes quantumlib#4827 Resolves quantumlib#3841 (comment) that's been bugging me for a year.
* Use Boolean Hamiltonian gates for QAOA example * Don't use deprecated function * More deprecation * Deprectate log_of_measurement_result input (quantumlib#5100) Co-authored-by: Cirq Bot <[email protected]> * Improve support for recursively applying transformer primitives on circuit operations using `deep=True` (quantumlib#5103) - Part of fixing quantumlib#5039 - Fixes multiple bugs and improves support for `deep=True` flag in transformer primitives. * Add support for deep=True flag to remaining transformer primitives (quantumlib#5106) * Add `assert_decompose_ends_at_default_gateset` to consistent protocols test to ensure all cirq gates decompose to default gateset (quantumlib#5107) * Extract BufferedDM/SV/MPS from ActOnDM/SV/MPSArgs (quantumlib#4979) * Extract BufferedDensityMatrix from ActOnDensityMatrixArgs * state vector * clean up code * clean up code * clean up code * format * docs * test * coverage * improve state vector * improve state vector * replace deleted functions * replace deleted functions * replace deleted functions * replace deleted functions * lint * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * coverage * fix merge errors * Code review comments * Remove todo Co-authored-by: Orion Martin <[email protected]> * Bugfixes in handling nested tags_to_ignore + deep=True in `cirq.map_moments` and `cirq.map_operations` transformer primitives (quantumlib#5109) - Fixes a few more bugs in the handling of deep=True flag and nested operations to ignore using `tags_to_ignore` in `cirq.map_operations` and `cirq.map_moments` transformer primitives. Also added more tests. - Step towards fixing quantumlib#5039 * Add `add_deep_support ` flag to `@cirq.transformer` decorator (quantumlib#5108) * Add flag to @cirq.transformer decorator * Fix mypy type errors and remove typos * Rename add_support_for_deep to add_deep_support * Add support for deep=True to `cirq.drop_empty_moments` transformer (quantumlib#5113) - Adds support to recursively run `cirq.drop_empty_moments` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of quantumlib#5039 * Add support for deep=True to `cirq.drop_negligible_operations` transformer (quantumlib#5114) - Adds support to recursively run `cirq.drop_negligible_operations` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of quantumlib#5039 * Add support for deep=True to `cirq.stratified_circuit` transformer (quantumlib#5117) - Adds support to recursively run `cirq.stratified_circuit` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of quantumlib#5039 * Add support for deep=True to `cirq.synchronize_terminal_measurements` transformer (quantumlib#5118) - Adds support to recursively run `cirq.synchronize_terminal_measurements` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of quantumlib#5039 * Add support for deep=True to `cirq.expand_composite` transformer (quantumlib#5119) - Adds support to recursively run `cirq.expand_composite` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Note that this does not rely on `preserve_structure` argument of `protocols.decompose` because the latter does not support handling nested circuit operations tagged with a no-compile tag (the added tests would fail if we rely on protocols.decompose(preserve_structure=True) instead transformer primitives). Hence, I would argue that we should deprecate the preserve_structure=True flag in protocols.decompose in-favour of this transformer. cc @95-martin-orion - Part of quantumlib#5039 * Add support for deep=True to `cirq.eject_phased_paulis` transformer (quantumlib#5116) - Adds support to recursively run `cirq.eject_phased_paulis` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of quantumlib#5039 * Add support for deep=True to `cirq.align_left` and `cirq.align_right` transformers (quantumlib#5112) - Adds support to recursively run `cirq.align_left` and `cirq.align_right` transformers on circuits wrapped inside a circuit operation by setting `deep=True` in transformer context. - Part of quantumlib#5039 * Add support for deep=True to `cirq.eject_z` transformer (quantumlib#5115) - Adds support to recursively run `cirq.eject_z` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Part of quantumlib#5039 * Add support for deep=True to cirq.merge_k_qubit_unitaries transformer (quantumlib#5122) * Add support for deep=True to merge_single_qubit_gates* transformers (quantumlib#5123) - Adds support to recursively run `cirq.merge_single_qubit_moments_to_phxz` transformer on circuits wrapped inside a circuit operation by setting deep=True in transformer context. - Also adds tests for `cirq.merge_single_qubit_gates_to_phxz` and `cirq.merge_single_qubit_gates_to_phased_x_and_z`, both of which automatically support deep=True flag after quantumlib#5122 - Part of quantumlib#5039 * Add support for deep=True to `cirq.optimize_for_target_gateset` transformer (quantumlib#5124) - Adds support for `deep=True` flag to `cirq.optimize_for_target_gateset` which enables optimizing circuits preserving the sub-circuit structure (i.e. without unrolling circuit operations). - Part of quantumlib#5039 * Bugfix in handling of deep=True flag in `cirq.merge_k_qubit_unitaries` transformer (quantumlib#5125) - Fixes a bug in `cirq.merge_k_qubit_unitaries` due to which the transformer was applied recursively only on circuit operations satisfying `cirq.num_qubits(op) <= k and cirq.has_unitary(op)`. Fixed the bug and added more tests. - Part of quantumlib#5039 * DeviceSpecification proto updates (quantumlib#5056) Part of quantumlib#5050 Since each gate has its own message now, target specification could potentially be moved inside gate messages (e.g. for 2-qubit gates) or disappear entirely and embed the target set in Cirq (e.g. measurement). This is lower priority since there are no major problems with the existing setup, so deferring this for now and get back to it before Cirq 1.0 if there's time. Micro-optimization: Leaving `GateSpecification` field numbers < 16 empty to allow for potential future common fields. @dstrain115 @maffoo * Add support for deep=True flag in `cg.optimized_for_sycamore` and `cg.SycamoreTargetGateset` transformers (quantumlib#5126) - Adds support for deep=True flag in `sycamore_gateset.merge_swap_rzz_and_2q_unitaries` transformer - Updates `cg.optimized_for_sycamore` to call `cirq.optimize_for_target_gateset` with `deep=True` by default, such that the method preserves circuit structure by default (which corresponds to its old behavior). - Fixes quantumlib#5039 * Rename TestDevice -> FakeDevice to avoid pytest confusion (quantumlib#5066) Pytest tries to collect `TestDevice` as a test class, and fails with the following wraning: ``` cirq-core/cirq/circuits/circuit_dag_test.py:24 cirq-core/cirq/circuits/circuit_dag_test.py:24 /home/runner/work/Cirq/Cirq/cirq-core/cirq/circuits/circuit_dag_test.py:24: PytestCollectionWarning: cannot collect test class 'TestDevice' because it has a __init__ constructor (from: cirq-core/cirq/circuits/circuit_dag_test.py) class TestDevice(cirq.Device): ``` * Add iterator support for AbstractJob (quantumlib#5136) - Add support for next() in AbstractJob - Changes __iter__ to return a generator, which will have support for iteration in for loops, as well as next(). - Also improve the iteration tests to be more thorough and accurate. Fixes: quantumlib#5120 * Pin Jinja2 version for build_docs CI. (quantumlib#5138) See CI failure here: quantumlib#5134 * Bump cirq version to 0.15.0 (quantumlib#5134) Bumps working version to v0.15.0 * Bump minimist from 1.2.5 to 1.2.6 in /cirq-web/cirq_ts (quantumlib#5140) Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/substack/minimist/commit/7efb22a518b53b06f5b02a1038a88bd6290c2846"><code>7efb22a</code></a> 1.2.6</li> <li><a href="https://github.com/substack/minimist/commit/ef88b9325f77b5ee643ccfc97e2ebda577e4c4e2"><code>ef88b93</code></a> security notice for additional prototype pollution issue</li> <li><a href="https://github.com/substack/minimist/commit/c2b981977fa834b223b408cfb860f933c9811e4d"><code>c2b9819</code></a> isConstructorOrProto adapted from PR</li> <li><a href="https://github.com/substack/minimist/commit/bc8ecee43875261f4f17eb20b1243d3ed15e70eb"><code>bc8ecee</code></a> test from prototype pollution PR</li> <li>See full diff in <a href="https://github.com/substack/minimist/compare/1.2.5...1.2.6">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=minimist&package-manager=npm_and_yarn&previous-version=1.2.5&new-version=1.2.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/quantumlib/Cirq/network/alerts). </details> * Remove deprecated two_qubit_matrix_to_diagonal_and_operations and two_qubit_matrix_to_operations (quantumlib#5102) see title. * Fix broken caching in CliffordGate and add test (quantumlib#5142) Looks like copy-pasta errors to me. Also update a test to being parameterized and complete. * Cleanup docs/noise.ipynb in preparation for Cirq 1.0 launch (quantumlib#5147) * Speed up a slow transformer test (quantumlib#5146) This test was the slowest that we run, 45 seconds, so I cut down on the parameterized range. @tanujkhattar * Make pylint parallel (quantumlib#5144) On my local machine this took pylint from 3 minutes to less than one. * [workflow] Preliminary timing information (quantumlib#5021) Add a `RuntimeInfo` field to store timing information. Augment the `execute` loop to record some basic timing info. Provide a utility context manager to make it easier to record timing information. * Add docstring for `cirq.TRANSFORMER` public object (quantumlib#5149) Adds docstring for `cirq.TRANSFORMER` public object. The api reference automatically creates a reference page for the public object, and currently inherits the docstring from the `Protocol` base class, which is irrelevant and the PR fixes it. * Base class for quantum states (quantumlib#5065) Creates a base class for all the quantum state classes created in quantumlib#4979, and uses the inheritance to push the implementation of `ActOn<State>Args.kron`, `factor`, etc into the base class. Closes quantumlib#4827 Resolves quantumlib#3841 (comment) that's been bugging me for a year. * Allow any object with supporting protocols to be the action in act_on (quantumlib#5111) * Allow any object with supporting protocols to be the action in act_on * lint * Fix raiser is not callable. (quantumlib#5155) Appears to have broken other PRs. https://github.com/quantumlib/Cirq/runs/5724527312?check_suite_focus=true * Corrected result.data implementation. (quantumlib#5153) When looking into quantumlib#4774 auto type promotion to objects raised a ValueError and was not tested. This PR fixes this and introduces the intended behavior as well as boosting performance slightly when qubit counts are < 64. * Support specific IonQ targets (qpu.generation) (quantumlib#5141) * Support specific IonQ targets Allows for more specific backend targets. * fmt * Upgrade black to stable version with format stability guarantees (quantumlib#5157) Version [22.1.0](https://black.readthedocs.io/en/latest/change_log.html#id1) is the first non-beta version of black and has a new [stability policy](https://black.readthedocs.io/en/stable/the_black_code_style/index.html#stability-policy). The last time we bumped the black version in quantumlib#4753 we did not actually reformat any code, so we could do that here and just rely on incremental formatting going forward, or we could do a global reformat to bring things up to date as we did when we originally switched to black in quantumlib#3516. I think the changes this time would be much less drastic than in the original switch. The main thing we've seen internally is tighter binding of the power operator, e.g. new black does `a**b + c**d` instead of `a ** b + c ** d`, which is a definite improvement. * Format cirq-core with latest version of black (quantumlib#5159) Review: @dabacon * Clarify virtual tag docstring (quantumlib#5161) Propose that instead of changing whether virtual tags are applied to noise models, we instead just clarify what it means to be virtual. Fixes: quantumlib#2984 * Format cirq-google with latest version of black (quantumlib#5160) Follow-up to quantumlib#5157. Format code in cirq-google to ensure these formatting changes don't get mixed in with future logic changes. * Ignore large-scale formatting changes for git blame (quantumlib#5162) Follow-up to quantumlib#5159 and quantumlib#5160. Ignore these large-scale formatting changes when goind git blame, as suggested by @dabacon. * Remove --pre from notebooks after release. (quantumlib#5135) For review after quantumlib#5134 * Update to pylint 2.13 (quantumlib#5156) Review: @mpharrigan * Update educators/intro.ipynb in preparation for Cirq 1.0 launch (quantumlib#5163) * Updated the educator intro notebook to remove deprecated items and introduce newly added concepts like gatesets and transformers. * Part of docs cleanup effort in preparation of Cirq 1.0 launch. * Disable broken symbols. (quantumlib#5165) * Autoformat all of engine_client_test.py (quantumlib#5164) ReviewL @dabacon * Allow specifying timeout_seconds when constructing an ionq Sampler (quantumlib#5133) * Allow specifying timeout_seconds when constructing an ionq Sampler This allows users of tensorflow quantum to use a high timeout and https://github.com/tensorflow/quantum/blob/f10d36b64761a003fd542392767fa079d57df0aa/tensorflow_quantum/python/quantum_context.py\#L82-L101 to run highly parallel workloads that may take very long times per-job without flakiness. * fmt * Python map * Coverage * Remove reservation colab (quantumlib#5168) - We no longer need this colab, as the UI now supports all reservation operations and is much easier. Fixes: quantumlib#3588 * Add Google-specific variant for noise properties. (quantumlib#5082) This PR provides an implementation of `SuperconductingQubitsNoiseProperties` for Google hardware. Now that SQNP is an abstract type, this is a prerequisite for re-enabling calibration-to-noise tools. This is part 3 of quantumlib#4666; part 2 was quantumlib#4964. Remaining steps include: - Reinstatement of calibration_to_noise_properties using new types - Reinstatement of compare_generated_noise_to_metrics using new types * Update docs/transform.ipynb based on new transformer framework. (quantumlib#5154) Fixes quantumlib#4960 This notebook provides a high level overview of all the newly added features to Cirq's transformer infrastructure. We can discuss whether we need more details docs on each of the specific topics -- I think a high level overview with links to reference pages of individual methods (i.e. the current PR) should be enough to close quantumlib#4960, but I'm curious to hear what others think. * Enforce same control order in ControlledGate equality check (quantumlib#5131) **Breaking Change** Changes ControlledGate equality check to enforce gates have same order. Fixes quantumlib#5110 * Fix gates.ipynb formatting (quantumlib#5175) - Move import cirq up into top block. - Clear outputs. * Cleaning up cirq/install docs (quantumlib#5178) * Corrected virtual environment link. * Replaced Foxtail with Sycamore. * Fix docs/circuits.ipynb as part of docs cleanup for Cirq 1.0 (quantumlib#5177) - Remove output - Move import to top - Minor changes to content (add `cirq.` prefix to many quoted words) - Remove broken link to devices.ipynb * Update simulator docs (quantumlib#5182) Quick cleanup pass for simulator docs. Nontrivial changes: - include note for `seed` parameter of simulator - remove comments about modifying StepResult state (deprecated) - clarify pure/mixed state behaviors and advantages - external simulator focus: qsim++, qFlex-- Everything else is cleaning format and refreshing links. * Fix broken link from cirq/tutorials page as part of docs cleanup (quantumlib#5174) Removes broken link from cirq/tutorials as part of docs cleanup. * Convert start.md to start.ipynb. (quantumlib#5176) Converts `start.md` -> `start.ipyb`. This lets us run the code block and make the notebook runnable in colab by our users. * Update google concepts doc. (quantumlib#5186) * Update google concepts doc. - Remove form for applying to EAP program. - Remove references to simulators. - Change images to remove simulators. - Remove dangling "Installing cirq". - Add commas and improve sentences in a few places. Co-authored-by: Matthew Neeley <[email protected]> * Fix docs/qubits.ipynb as part of docs cleanup for Cirq 1.0 (quantumlib#5179) - Move import to top * Minor cleanup of QCS tutorial (quantumlib#5184) @dstrain115 @MichaelBroughton @wcourtney * Link fix on start page. (quantumlib#5191) Remove extra paranthesis. * Neutral atom update (quantumlib#5192) Updates neutral atom tutorial to remove uses of deprecated device behavior. * Remove use of deprecated device behavior from quantum_volume_errors. (quantumlib#5198) Title * Remove BooleanHamiltonian object (quantumlib#5099) Now that v0.14 is released, delete deprecate object * Refactor qcs_notebook to use application default creds (quantumlib#5045) Review: @95-martin-orion * Cirq web supports LineQubits (quantumlib#5211) This would be to fix quantumlib#5173 * Import new gapic generated code for quantum engine API (quantumlib#5139) This is some very preliminary work to import new generated code for the quantum engine API. Of note is that the new code includes async support and is now using [proto-plus](https://github.com/googleapis/proto-plus-python) rather than the standard generated proto code for messages. * Fix basics (quantumlib#5180) Cleans up basics.ipynb and removes mention of old devices behavior. * Deprecate `gate_set` parameter on engine classes. (quantumlib#5207) Fixes quantumlib#4995 Review: @verult * Tweak quantum walks doc (quantumlib#5212) * Tweak quantum walks doc - Removed output cells and tweaked imports - Move print out of function. * Deprecate json_serializable_dataclass (quantumlib#5208) Fixes quantumlib#4460 * Fix error and add test for mutable pauli string (quantumlib#5213) quantumlib#4001 looks abandoned so this does the change and adds the test as requested. * Fix tutorials/state_histograms.ipynb as part of docs cleanup for Cirq 1.0 (quantumlib#5206) * Cleared output * Fixed broken links * Minor improvements in content * Fix tutorials/heatmaps.ipynb as part of docs cleanup for Cirq 1.0 (quantumlib#5205) * Cleared output * Fixed typos and broken links * Changed language to second person * Remove some 0.15 items from cirq.sim (quantumlib#5137) This covers most of the deprecations for `cirq.sim` in 0.15. The two remaining ones have some challenges: * Removing `target_tensor` etc from the initializers and replacing with `initial_state`: The repr still emits `target_tensor` so it wouldn't round-trip. * Removing `log_of_measurement_results`: Same thing. Plus we forgot to deprecate it in a couple places. Also this closes quantumlib#3898, as the pattern we used to deprecate `copy` without parameters works well. * Add Cynocracy to owners of cirq-ionq (quantumlib#5145) @Cynocracy let me know if you want to remove any of the others, or keep them as is. * Fix educators/qaoa_ising.ipynb as part of docs cleanup for Cirq 1.0 (quantumlib#5204) * Moved cirq import to top * Cleared output * Fixed typos in text * Improve documentation about writing type annotations (quantumlib#5218) Fixes quantumlib#4383 * customer_gates.ipynb - minor content cleanup (quantumlib#5215) cc @tanujkhattar * Make _commutes_ consistent (quantumlib#5217) - Requires atol to be a named parameter. - Also changes atol to be uniformly float around the codebase. (not sure why it would be int, are people using an atol=1?) - Technically a breaking change, but it's unlikely people are using this widely as most commutes do not even use atol. Fixes: quantumlib#3695 * Fix numpy annotations np.array -> np.ndarray (quantumlib#5227) `np.array` is not a valid type, but rather a factory function for creating arrays. The actual type is `np.ndarray`. This change reduces the number of `check/mypy --next` errors by >60% from 244 to 96 on my machine. * Delete the target_tensor parameter that was deprecated in 0.15 (quantumlib#5225) A few simulators used either initial_state or target_tensor to initialize their ActOnArgs. We deprecated the latter in 0.15. This PR deletes those. Note that one follow-on change included here is that the repr functions needed to be changed to emit the field as `initial_state` too. (I wish I'd just called it `quantum_state` now, but oh well). @95-martin-orion I also went ahead and removed the buffer from the repr, since it is just noise. * Deprecate the ActOnArgs._on_* methods (quantumlib#5224) Now that we have separated out the `QuantumStateRepresentation` from `ActOnArgs`, there is no need for the `_on_*` methods anymore. This PR deprecates those, adds deprecation tests, and updates any old test ActOnArgs to use the new QuantumStateRepresentation internally. @95-martin-orion * Allow specifying initial state vector in DensityMatrixSimulator (quantumlib#5223) This changes how ActOnDensityMatrixArgs is constructed to allow specifying the initial state as a state vector or state tensor, or as a density matrix or density tensor. Some of this could perhaps be moved into `cirq.to_valid_density_matrix` if people think that is a better place. Currently `to_valid_density_matrix` only handles 1D state vectors or 2D density matrices, not 2x2x..2 tensors in either case, but if we have the qid_shape we can tell handle these unambiguously. Fixes quantumlib#3958 * Unquote example code in ArithmeticOperation (quantumlib#5230) Fixes quantumlib#5228 (I hope) * Document CircuitOp optimizer best practices (quantumlib#5221) Final item for quantumlib#3634. With the new transformers, there is a clean pipeline for optimizing nested circuits and sending the (concise!) result to hardware for execution. * Remove the deprecated mutators in cirq/ops (quantumlib#5201) Removes all the deprecated mutators. * Allow server-side warnings from IonQ (quantumlib#5222) This will be used to notify users about deprecations and changes to the API without needing to update Cirq independently. * Fix educators/textbook_algorithms.ipynb as part of docs cleanup for Cirq 1.0 (quantumlib#5199) * Fixes typos * Removes outputs * Move import to top * Fix qcvv/xeb_theory.ipynb as part of docs cleanup for Cirq 1.0 (quantumlib#5202) * Moved import to top * Fixed broken link to quantum ai website * Minor improvements in text formatting * Cleaning up tutorials/variational_algorithm.ipynb (quantumlib#5185) * Move cirq import to top * Remove outputs * Document CIRCUIT_TYPE and hide other typevars/aliases in circuits.py (quantumlib#5229) Fixes quantumlib#5150 (assuming this renders nicely on the docsite; how can I check that locally?) This adds an underscore prefix to hide some type aliases and type vars that are not part of the public interface of the module. Also adds a docstring to the `CIRCUIT_TYPE` variable, which is used in a few other places. * Make check scripts run pytest in parallel (quantumlib#5143) The tests were made parallel in CI, but this updates the scripts to run in parallel. Respects if user overrides with different level of parallelism. * cirq-ionq: Retry non-standard cloudflare errors (quantumlib#5237) * Add q helper function for constructing common qubit types. (quantumlib#5181) * Add q helper function * fmt * Ignore static type errors in tests * Ignore intentional type errors * Fix Raises docstring * Fixes from review * Use *args * remove unused import * Unpin sympy and ignore sympy type errors (quantumlib#5226) Fixes quantumlib#5058 Review: @dabacon * Add calibration-to-noise pipeline (quantumlib#5187) This PR reinstates the cirq_google utility for converting `Calibration` objects to noise properties. To create a simulator with behavior that mimics some `Calibration` "cal", the expected usage is: ```python noise_props = cg.noise_properties_from_calibration(cal) noise_model = cg.NoiseModelFromGoogleNoiseProperties(noise_props) simulator = cirq.Simulator(noise=noise_model) # will mimic noise from `calibration` ``` This is part 4 of quantumlib#4666; part 3 was quantumlib#5082. Remaining steps include: - Convenience methods for modifying noise properties - Reinstatement of compare_generated_noise_to_metrics using new types * Remove device from circuits (quantumlib#5189) Removes v0.15 deprecation items for attaching devices to circuits. * Bump tensorflow-docs version (quantumlib#5250) * Fix tutorials/qaoa.ipynb as part of docs cleanup for Cirq 1.0 (quantumlib#5200) * Change example device from `cg.Bristlecone` (now deprecated) to `cg.Sycamore`. * Use new GridDeviceMetadata instead of deprecated device properties (like neighbors_of) * Move import to top * Clear outputs * Remove custom cirq_type (quantumlib#5249) Custom `cirq_type` was deprecated in quantumlib#4704 and not necessary for internal types. * Skip "magic trailing comma" when formatting with black (quantumlib#5170) The "magic trailing comma" is a comma at the end of bracketed list that forces black to format the list entries on separate lines, even if they would fit on one line. For example, if you write: ```python foo(a, b,) ``` black will see that trailing comma and format this as: ```python foo( a, b, ) ``` But with the `skip-magic-trailing-comma` setting enabled this will format on a single line instead ```python foo(a, b) ``` IME the trailing commas are almost always unintentional, e.g. left over from other refactos, and result in wasted vertical space. I suggest we enable this flag. * Remove deprecated log_of_measurement_results parameters (quantumlib#5233) * deprecate log_of_measurement_results * Fix test * coverage * Add empty ClassicalDataDictionaryStore.repr test * Add ActOnArgs test * Add tests * Add ActOnStabilizerArgs tests * nits * coverGE * format Co-authored-by: Cirq Bot <[email protected]> * Make the quantum state generic (quantumlib#5255) * Migrate google/best_practices.md to google/best_practices.ipynb as part of docs cleanup for Cirq 1.0 (quantumlib#5236) - Fixes bugs in code demonstrating use of circuit operations and compiling them using new transformers. Follow up of quantumlib#5221 * Format cirq-google with skip-magic-trailing-comma (quantumlib#5171) Review: @95-martin-orion * Format according to new black rules (quantumlib#5259) Follow up by will add hash to .git-blame-ignore-revs * Ignore skip-magic-trailing-comma formatting with git blame (quantumlib#5257) This adds a formatting commit to ignore when doing git blame. * Use sorted instead of set for random.sample (quantumlib#5248) * Fix Docs: cirq/tutorials/educators/chemistry (quantumlib#5251) * Convenience methods for modifying GoogleNoiseProperties (quantumlib#5188) * Add override methods. * Mypy passes, weak typing * Resolved mypy conundrum * with_params * Deprecate Gateset.accept_global_phase_op (quantumlib#5239) Deprecates Gateset.accept_global_phase_op **Breaking Change:** Changes the default value of `Gateset.accept_global_phase_op` from `True` to `False`. I can't think of any way to remove this parameter without eventually needing this breaking change. Currently all gatesets that are created allow global phase gates if they don't specify `accept_global_phase_op=False` explicitly. But the end goal is only to allow global phase gates if they're included in the `gates` list. So at some point in the transition the default behavior needs to break, and I can't think of a way of doing that via deprecation. Therefore I think we may as well do it now via this breaking change. Note that even though it's breaking, it isn't breaking in a bad way. Users who are adding global phase gates to things that suddenly don't accept them will just see an error that the gate is not in the gateset, and then go add it. It's much safer than breaking in the other direction in which we silently start allowing new gate types. Closes quantumlib#4741 @tanujkhattar * Exclude TYPE_CHECKING from docs (quantumlib#5261) This would be an attempt to fix quantumlib#5231 * Add unit test Co-authored-by: Dax Fohl <[email protected]> Co-authored-by: Cirq Bot <[email protected]> Co-authored-by: Tanuj Khattar <[email protected]> Co-authored-by: Orion Martin <[email protected]> Co-authored-by: Cheng Xing <[email protected]> Co-authored-by: Matthew Neeley <[email protected]> Co-authored-by: Doug Strain <[email protected]> Co-authored-by: MichaelBroughton <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Dave Bacon <[email protected]> Co-authored-by: Matthew Harrigan <[email protected]> Co-authored-by: Jon Donovan <[email protected]> Co-authored-by: Matthew Neeley <[email protected]> Co-authored-by: Timo Eckstein <[email protected]> Co-authored-by: Dax Fohl <[email protected]>
* Extract BufferedDensityMatrix from ActOnDensityMatrixArgs * state vector * clean up code * clean up code * clean up code * format * docs * test * coverage * improve state vector * improve state vector * replace deleted functions * replace deleted functions * replace deleted functions * replace deleted functions * lint * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * mps quantum state * coverage * fix merge errors * Code review comments * Remove todo Co-authored-by: Orion Martin <[email protected]>
Creates a base class for all the quantum state classes created in quantumlib#4979, and uses the inheritance to push the implementation of `ActOn<State>Args.kron`, `factor`, etc into the base class. Closes quantumlib#4827 Resolves quantumlib#3841 (comment) that's been bugging me for a year.
Addresses #4827, cleaning up code by separating concerns between the quantum part and the classical part of density matrix / state vector / MPS sim state. (Clifford args are already factored like this). While it's a large PR, most of the change is just moving quantum-state-specific code from the ActOnArgs class, to a corresponding new quantum state class. This is done for DensityMatrix, StateVector, and MPS simulators. There are no behavioral changes in this PR.
As can be seen in this PR, this allows implementations of _on_kron, _on_factor, measure, etc. within ActOnArgs to be identical one-liners, delegating to the quantum state representation.
One particular thing to note here is that I have kept the initializers simple, just populating the member variables, and have created factory classmethods for more complex logic. This is because the quantum state representations need to support combinator logic like kron, factor, etc., and thus needs simple constructors that allow it to plug in the resulting member fields and move on. Having complex validation and transformation logic inside the constructor itself makes such combinators less efficient.
As a follow-up to this, I plan to create a common interface to enforce a standardization on these quantum state representations, and that will allow us to push some common logic into ActOnArgs base class. This will allow us eventually to deprecate the need for _on_kron etc handlers in each ActOnArgs entirely, and rely solely on the ActOnArgs base class doing this generically (see #5065).
For now I have kept these classes and any references to them private, but in consideration of #4582, we may eventually want to make these classes public and move them from
sim
intoqis
.