cirq.GridQubit

A qubit on a 2d square lattice.

Inherits From: Qid

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)

row the row coordinate
col the column coordinate

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

View source

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

View source

Determines if two qubits are adjacent qubits.

neighbors

View source

Returns qubits that are potential neighbors to this GridQid

Args
qids optional Iterable of qubits to constrain neighbors to.

rect

View source

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

View source

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

View source

Raises an exception if dimension is not positive.

Raises
ValueError dimension is not positive.

with_dimension

View source

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__

View source

__eq__

View source

Return self==value.

__ge__

View source

Return self>=value.

__gt__

View source

Return self>value.

__le__

View source

Return self<=value.

__lt__

View source

Return self<value.

__ne__

View source

Return self!=value.

__neg__

View source

__radd__

View source

__rsub__

View source

__sub__

View source