cirq.devices.GridQid

A qid on a 2d square lattice

Inherits From: Qid

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)

row the row coordinate
col the column coordinate
dimension The dimension of the qid's Hilbert space, i.e. the number of quantum levels.

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 device layout into info about qids and connectivity. 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
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...
..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 ('

'), an error will be thrown. The top-left corner of the diagram will be have coordinate (0,0).

Returns:
A list of GridQid corresponding to qids in the provided diagram

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

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 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

View source

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

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.

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.

View source