Skip to content

Fix from_diagram docstring on GridQubit. #5307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 1, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions cirq-core/cirq/devices/grid_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,25 @@ def rect(

@staticmethod
def from_diagram(diagram: str, dimension: int) -> List['GridQid']:
r"""Parse ASCII art device layout into info about qids and
connectivity. As an example, the below diagram will create a list of
GridQid in a pyramid structure.
r"""Parse ASCII art device layout into a device.

As an example, the below diagram will create a list of GridQid in a
pyramid structure.


```
---A---
--AAA--
-AAAAA-
AAAAAAA
```

You can use any character other than a hyphen to mark a qid. As an
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is incorrect, as noted in the "Args: diagram" section below. Periods and spaces are also treated as non-Qid positions, and non-alphanumeric characters produce an error.

example, the qids for the Bristlecone device could be represented by
the below diagram. This produces a diamond-shaped grid of qids, and
qids with the same letter correspond to the same readout line.

```
.....AB.....
....ABCD....
...ABCDEF...
Expand All @@ -229,20 +235,22 @@ def from_diagram(diagram: str, dimension: int) -> List['GridQid']:
...GHIJKL...
....IJKL....
.....KL.....
```

Args:
diagram: String representing the qid layout. Each line represents
a row. Alphanumeric characters are assigned as qid.
Dots ('.'), dashes ('-'), and spaces (' ') are treated as
Dots ('.'), dashes ('-'), and spaces are treated as
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why drop the (' ')? I think it's helpful just for clarifying that we mean the "space" character, not whitespace in general.

empty locations in the grid. If diagram has characters other
than alphanumerics, spacers, and newlines ('\n'), an error will
be thrown. The top-left corner of the diagram will be have
coordinate (0,0).
dimension: The dimension of the qubits in the `GridQid`s used
coordinate (0, 0).

dimension: The dimension of the qubits in the `cirq.GridQid`s used
in this construction.

Returns:
A list of GridQid corresponding to qids in the provided diagram
A list of `cirq.GridQid`s corresponding to qids in the provided diagram

Raises:
ValueError: If the input string contains an invalid character.
Expand Down