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)


dimension Returns the dimension or the number of quantum levels this qid has. E.g. 2 for a qubit, 3 for a qutrit, etc.



View source

Parse ASCII art device layout into info about qubits and connectivity. 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 to mark a qubit. As an
    example, the qubits 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.


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

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

        A list of GridQubit corresponding to qubits in the provided diagram

        ValueError: If the input string contains an invalid character.


View source

Determines if two qubits are adjacent qubits.


View source

Returns qubits that are potential neighbors to this GridQid

qids optional Iterable of qubits to constrain neighbors to.


View source

Returns a rectangle of GridQubits.

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

A list of GridQubits filling in a rectangular grid


View source

Returns a square of GridQubits.

diameter Length of a side of the square
top Row number of the topmost row
left Column number of the leftmost row

A list of GridQubits filling in a square grid


View source

Raises an exception if dimension is not positive.

ValueError dimension is not positive.


View source

Returns a new qid with a different dimension.

Child classes can override. Wraps the qubit object by default.

dimension The new dimension or number of levels.


View source


View source

Return self==value.


View source

Return self>=value.


View source

Return self>value.


View source

Return self<=value.


View source

Return self<value.


View source

Return self!=value.


View source


View source


View source


View source