`CircuitDag` and `Unique` can be removed from the `cirq.contrib` level
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 76/100
Research direction
Start in cirq-core/cirq/contrib/__init__.py and remove the CircuitDag and Unique re-export. Update the listed references in circuit_dag.py, circuit_dag_test.py, acquaintance/topological_sort.py, acquaintance/topological_sort_test.py, and json_test_data/spec.py; add redirects for the old API documentation pages. Done when callers import the classes from cirq.contrib.circuitdag and the updated tests and documentation references are consistent.
Written by the indexing model from the issue text.
Description
CircuitDag, Unique, and circuit_to_latex_using_qcircuit are anomalous in the Cirq contrib module in that they are defined within contrib submodules yet exposed at the cirq.contrib namespace level. This is visible in the documentation for the contrib module (screenshot attached →).
The qcircuit module will soon go away because it is being deprecated (#8355). As part of a small cleanup of the contrib module (motivated by the deprecation of qcircuit and a goal to improve the quantikz module), I propose that CircuitDag and Unique be removed from the cirq.contrib level. The net effect will be to require callers to import CircuitDag and Unique from cirq.contrib.circuitdag instead of from cirq.contrib.
What will need to change in Cirq if this is done?
The main change is simply to remove the last line in cirq-core/cirq/contrib/__init__.py:
from cirq.contrib import graph_device # noqa: F401
from cirq.contrib import quirk # noqa: F401
from cirq.contrib.qcircuit import circuit_to_latex_using_qcircuit as circuit_to_latex_using_qcircuit
from cirq.contrib import json # noqa: F401
from cirq.contrib.circuitdag import CircuitDag as CircuitDag, Unique as Unique
Since these classes are only used by other contrib modules, the other changes are fairly limited:
-
Unique.__repr__incirq/contrib/circuitdag/circuit_dag.py:46hardcodes the string'cirq.contrib.Unique(...)'. -
cirq/contrib/circuitdag/circuit_dag_test.py: about 24 uses ofcirq.contrib.CircuitDagandcirq.contrib.Unique. -
cirq/contrib/acquaintance/topological_sort.py:31: uses the annotationdag: cirq.contrib.CircuitDag. This is annotation only, because offrom __future__ import annotations. -
cirq/contrib/acquaintance/topological_sort_test.py:28: callscirq.contrib.CircuitDag.from_circuit(...)inside a module-levelparametrize. -
cirq/contrib/json_test_data/spec.py:27: hasshould_not_be_serialized=["Unique", "CircuitDag"], which is checked against the members ofcirq.contrib. -
API documentation: the published pages currently document the two classes at
reference/python/cirq/contrib/CircuitDagand.../Unique. We should add redirects so that the old references point to the new pages, which will bereference/python/cirq/contrib/circuitdag/CircuitDagand.../Unique.
All the production code in Cirq already does either from cirq.contrib import circuitdag or from cirq.contrib.circuitdag import CircuitDag. None of the notebooks, Markdown docs/snippets, doctests, or other Cirq subpackages (cirq-google, cirq-ft, cirq-aqt, cirq-ionq, cirq-pasqal, cirq-rigetti, cirq-web) reference CircuitDag, Unique, or circuitdag.
What will be affected outside of Cirq?
A GitHub code search finds that almost all cases where CircuitDag is accessed from cirq.contrib are either forks of the Cirq repo or vendored copies of the Cirq sources. The only non-fork/non-vendored cases I found are:
-
QuEraComputing/bloqade-circuit in
src/bloqade/cirq_utils/parallelize.py, and it already imports fromcirq.contrib.circuitdag.circuit_dag, so it is unaffected. -
conda-forge/conda-forge-bot-data in
import_to_pkg_maps/4/a/8/d/e/cirq.contr.json. This seems to be an automatically-generated module map; presumably, if the Cirq repo is updated, then this will eventually get auto-updated too.
It should be noted that the Cirq contrib module is not bound by Cirq's backward compatibility guarantees.
Why are things structured the way they are currently?
Some investigation of the commit history shows that CircuitDag and Unique were originally top-level cirq. Following Issue #547, Casey Duckering created cirq/circuits/circuit_dag.py and flattened CircuitDag into the top-level cirq namespace (cirq.CircuitDag) in #759 (2018), then flattened Unique (cirq.Unique) two days later in #761 so that cirq/contrib/paulistring/recombine.py could use it in type annotations.
In #3816 ("Is anyone using CircuitDag?") and #4494, maintainers concluded that CircuitDag was only used by contrib modules (acquaintance, paulistring, routing) and was not suitable for core Cirq 1.0, deciding to deprecate it from core and move it into cirq.contrib. The re-exports were later added to __init__.py to give users a drop-in replacement when CircuitDag was taken out of core in PR #5481 ("Move CircuitDag to contrib", Doug Strain, 2022-06-13). The commit message and the deprecation decorators state the intent: "cirq.CircuitDag is now deprecated and now must be changed to cirq.contrib.CircuitDag." Exporting CircuitDag and Unique directly in cirq/contrib/init.py allowed existing callers of import cirq; cirq.CircuitDag and cirq.Unique to migrate by inserting .contrib without adding a separate submodule import.
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 1.3k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 48
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from quantumlib/Cirq
-
Potential missed optimization: `drop_diagonal_before_measurement` leaves an identity `PhasedXZGate` that blocks further removalPossibly taken @jangyoujin0917 claimed this 22 days ago. Openarea/gates area/optimization kind/feature-request triage/accepted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
quantumlib/Cirq#8523 · 1 comment ·
Maintainers usually reply within 1 day
-
`defer_measurements` ignores `BitMaskKeyCondition.index` and changes circuit behaviorMay be free again @Tejendra-06 claimed this 54 days ago, and no pull request is open. Opengood for learning help wanted kind/bug-report skill/experienced triage/accepted triage/wont-fix
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
quantumlib/Cirq#8361 · 8 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
kind/feature-request triage/discuss
quantumlib/Cirq#8598 ·
Maintainers usually reply within 1 day
-
area/docstrings area/google kind/bug-report triage/discuss
Difficulty 1/5 1-3 hours Newbie friendliness 91/100
quantumlib/Cirq#8587 ·
Maintainers usually reply within 1 day
-
kind/bug-report triage/discuss
Difficulty 2/5 1-3 hours Newbie friendliness 57/100
quantumlib/Cirq#8580 ·
Maintainers usually reply within 1 day
Similar issues
-
docs(contributing): the two things that silently block a PRPossibly taken A pull request linked to this issue is open or already merged. Openavailable documentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
Nixitov/Riptide-Native#944 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
JTHCode/secretguard#24 ·
Maintainers usually reply within 1 day
-
area: middleware documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainers usually reply within 1 day