View source on GitHub |
A qubit on a 2d square lattice.
Inherits From: Qid
cirq.GridQubit(
row: int, col: int
) -> 'cirq.GridQubit'
Used in the notebooks
Used in the tutorials |
---|
GridQubits use row-major ordering:
GridQubit(0, 0) < GridQubit(0, 1) < GridQubit(1, 0) < GridQubit(1, 1)
New GridQubits can be constructed by adding or subtracting tuples
cirq.GridQubit(2, 3) + (3, 1)
cirq.GridQubit(5, 4)
cirq.GridQubit(2, 3) - (1, 2)
cirq.GridQubit(1, 1)
cirq.GridQubit(2, 3,) + np.array([3, 1], dtype=int)
cirq.GridQubit(5, 4)
Args | |
---|---|
row
|
the row coordinate |
col
|
the column coordinate |
Attributes | |
---|---|
col
|
|
dimension
|
Returns the dimension or the number of quantum levels this qid has. E.g. 2 for a qubit, 3 for a qutrit, etc. |
row
|
Methods
from_diagram
@staticmethod
from_diagram( diagram: str ) -> List['GridQubit']
Parse ASCII art into device layout info.
As an example, the below diagram will create a list of GridQubit in a pyramid structure.
---A---
--AAA--
-AAAAA-
AAAAAAA
You can use any character other than a hyphen, period or space to mark a qubit. As an example, the qubits for a 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...
..ABCDEFGH..
.ABCDEFGHIJ.
ABCDEFGHIJKL
.CDEFGHIJKL.
..EFGHIJKL..
...GHIJKL...
....IJKL....
.....KL.....
Args | |
---|---|
diagram
|
String representing the qubit layout. Each line represents a row. Alphanumeric characters are assigned as qid. Dots ('.'), dashes ('-'), and spaces (' ') are treated as 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). |
Returns | |
---|---|
A list of GridQubit corresponding to qubits in the provided diagram |
Raises | |
---|---|
ValueError
|
If the input string contains an invalid character. |
is_adjacent
is_adjacent(
other: 'cirq.Qid'
) -> bool
Determines if two qubits are adjacent qubits.
neighbors
neighbors(
qids: Optional[Iterable[ops.Qid]] = None
) -> Set['_BaseGridQid']
Returns qubits that are potential neighbors to this GridQid
Args | |
---|---|
qids
|
optional Iterable of qubits to constrain neighbors to. |
rect
@staticmethod
rect( rows: int, cols: int, top: int = 0, left: int = 0 ) -> List['GridQubit']
Returns a rectangle of GridQubits.
Args | |
---|---|
rows
|
Number of rows in the rectangle |
cols
|
Number of columns in the rectangle |
top
|
Row number of the topmost row |
left
|
Column number of the leftmost row |
Returns | |
---|---|
A list of GridQubits filling in a rectangular grid |
square
@staticmethod
square( diameter: int, top: int = 0, left: int = 0 ) -> List['GridQubit']
Returns a square of GridQubits.
Args | |
---|---|
diameter
|
Length of a side of the square |
top
|
Row number of the topmost row |
left
|
Column number of the leftmost row |
Returns | |
---|---|
A list of GridQubits filling in a square grid |
validate_dimension
@staticmethod
validate_dimension( dimension: int ) -> None
Raises an exception if dimension
is not positive.
Raises | |
---|---|
ValueError
|
dimension is not positive.
|
with_dimension
with_dimension(
dimension: int
) -> 'GridQid'
Returns a new qid with a different dimension.
Child classes can override. Wraps the qubit object by default.
Args | |
---|---|
dimension
|
The new dimension or number of levels. |
__add__
__add__(
other: Union[Tuple[int, int], Self]
) -> Self
__eq__
__eq__(
other
) -> bool
Return self==value.
__ge__
__ge__(
other
) -> bool
Return self>=value.
__gt__
__gt__(
other
) -> bool
Return self>value.
__le__
__le__(
other
) -> bool
Return self<=value.
__lt__
__lt__(
other
) -> bool
Return self<value.
__ne__
__ne__(
other
) -> bool
Return self!=value.
__neg__
__neg__() -> Self
__radd__
__radd__(
other: Tuple[int, int]
) -> Self
__rsub__
__rsub__(
other: Tuple[int, int]
) -> Self
__sub__
__sub__(
other: Union[Tuple[int, int], Self]
) -> Self