View source on GitHub |
A qid on a 2d square lattice
Inherits From: Qid
cirq.GridQid(
row: int, col: int, *, dimension: int
) -> 'cirq.GridQid'
GridQid uses row-major ordering:
GridQid(0, 0, dimension=2) < GridQid(0, 1, dimension=2)
< GridQid(1, 0, dimension=2) < GridQid(1, 1, dimension=2)
New GridQid can be constructed by adding or subtracting tuples or numpy arrays
cirq.GridQid(2, 3, dimension=2) + (3, 1)
cirq.GridQid(5, 4, dimension=2)
cirq.GridQid(2, 3, dimension=2) - (1, 2)
cirq.GridQid(1, 1, dimension=2)
cirq.GridQid(2, 3, dimension=2) + np.array([3, 1], dtype=int)
cirq.GridQid(5, 4, dimension=2)
Args | |
---|---|
row
|
the row coordinate |
col
|
the column coordinate |
dimension
|
The dimension of the qid's Hilbert space, i.e. the number of quantum levels. |
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, dimension: int ) -> List['GridQid']
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, period or space to mark a qid. As an example, the qids 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 qid 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). |
dimension
|
The dimension of the qubits in the cirq.GridQid s used
in this construction.
|
Returns | |
---|---|
A list of cirq.GridQid s corresponding to qids 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, *, dimension: int ) -> List['GridQid']
Returns a rectangle of GridQid.
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 |
dimension
|
The dimension of the qid's Hilbert space, i.e. the number of quantum levels. |
Returns | |
---|---|
A list of GridQid filling in a rectangular grid |
square
@staticmethod
square( diameter: int, top: int = 0, left: int = 0, *, dimension: int ) -> List['GridQid']
Returns a square of GridQid.
Args | |
---|---|
diameter
|
Length of a side of the square |
top
|
Row number of the topmost row |
left
|
Column number of the leftmost row |
dimension
|
The dimension of the qid's Hilbert space, i.e. the number of quantum levels. |
Returns | |
---|---|
A list of GridQid 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