Shape

class Shape(points, lines=None, indices=None)[source]

Bases: object

This class is used to store a boundary shape on a given manifold that is used to select sublattices.

Init shape

Parameters:
  • points (List) – points on the shape

  • lines (List[List], optional) – lines on the shape. Defaults to None

  • indices (List, optional) – indices of the shape Defaults to None.

Raises:

QiskitError – If <indices> are defined then lines must also be defined

Methods

bounding_box_from_lines()[source]

Generate bounding box from lines on the shape

contains(point, on_boundary=True, epsilon=0.01, method='winding')[source]
Parameters:
  • point (_type_) – _description_

  • on_boundary (bool, optional) – _description_. Defaults to True.

  • epsilon (float, optional) – _description_. Defaults to 0.01.

  • method (str, optional) – _description_. Defaults to “winding”.

Returns:

_description_

Return type:

bool

contains_quad_winding_number(point, on_boundary=False, epsilon=0.01)[source]

Deterine if a point is inside a polygon (PIP Problem)

On or near boundary method uses l2 distances and interior method uses algorithm from Hornmann and Agathos, Computational Geometry 20 (2001) 131-144

With optional on_boundary set to False (default) the boundary is not included on the inside. If on_boundary is False then points positioned on the boundary may of may not be included. Increase the size of the shape to avoid this problem or set on_boundary to True. Setting on_boundary to True will be slower as it checks l2 distances from boundary.

Currently only a simple version of the algorithm is implemented. This should be corrected at a later date or in next version.

Parameters:
  • point (Union[list, ndarray]) – Point to check if inside the given shape

  • on_boundary (bool) – Set True to include the boundary. Slow for larger boundaries. Default is False. Points will be included if with epsilon of the boundary.

  • epsilon (float) – Value used to indicate if a point is close enough to the boundary to be included. Default is 0.01

Returns:

True is point in on the polygon and False otherwise.

Return type:

bool

contains_ray_trace(point, on_boundary=True, epsilon=0.01)[source]

Check if inside the bounded region using an infinite horizontal line from the point to +infinity

This implementation assumes that the path is given by a sequence of straight lines.

A more sophisticated verison is required if the path is otherwise.

Parameters:
  • point (point) – point to check if in region (including on boundary)

  • on_boundary (bool) – True if boundary to be include in “inside”. Default is True

  • epsilon (real) – Tolerance distance between two points to be equal. Default is 0.001

Returns: (bool) Check if inside the bounded region using an infinite

horizontal line from the point to +infinity

static create_lines(points)[source]

Creates Lines from a set of points

inside(tiling, on_boundary=False, epsilon=0.1)[source]

Returns the in-out data for a shape and a tiling

Parameters:
  • tiling (Shell) – Input Tiling (shell)

  • on_boundary (bool) – If True then the in-out data will include those vertices within epsilon of the boundary. This is more expensive. It is better to use a shape which is slightly larger. Default is False.

  • epsilon (Real) – Real number use when on_boundary is True. Default is 0.1

Returns:

vertex -> bool dictionary. True for inside the shape and False otherwise

Return type:

Dict[bool]

static is_between(p, a, b, strict=False, epsilon=0.0)[source]

is p between a and b: a <= p < =b

Parameters:
  • p (Real) – point

  • a (Real) – end point

  • b (Real) – end point

  • strict (bool) – is strict comparison. Default is False

  • epsilon (Real) – Will squeeze inequality by epsilon

Returns:

True is a is between a and b, False if not

Return type:

bool

classmethod rect(origin, direction, scale1, scale2, manifold=<qiskit_qec.geometry.plane.Plane object>, delta=0, dtype=<class 'float'>)[source]

Create a rectangle on a manifold

A rect has the following lables:

          r2
          o
      /       \
r3  o          \
     \          o r1
      \       /
          o
         r0=origin
direction (r0 to r1)
scale1 = scale(r0,r1)
scale2 = scale(r1,r2)
Parameters:
  • origin (Union[List, Tuple, ndarray]) – Origin (r0) of rectangle. The origin is one of the corners of the rectangle.

  • direction (Union[List, Tuple, ndarray]) – Direction vector from r0 to r1

  • scale1 (Union[int, float]) – how large to scale up (r0,r1) side

  • scale2 (Union[int, float]) – how large to scale up (r1,r2) side

  • manifold (Manifold) – Manifold that rectangle lives on. Defaults to Plane().

  • delta (optional) – How large to increase the rectangle by. Defaults to 0.

  • dtype (type, optional) – type of entries for definiting points to use. Defaults to float.

Raises:
  • QiskitError – Rectangle scales must be positive

  • QiskitError – Origin must be on the surface if the manifold

  • QiskitError – Manifold not yet supported

Returns:

rectangle of given parameters

Return type:

rect

classmethod square(origin, direction, scale, manifold, delta=0, dtype=<class 'int'>)[source]

Create a square (2d) shape on the 2-manifold.

The square has one corner placed at the origin (origin must be on the plane). The the square is defined as the path following heading in the direction <direction> towards the next corner of length <length>. The proceeding to the next corner and so on.

Parameters:
  • origin ([coordinate]) – a coordinate on the plane

  • direction ([vector]) – vector describing the direction of the second corner

  • scale ([real]) – side of square = scale * ||direction||

  • manifold ([TwoManifold]) – 2-manifold

  • dtype ([dtype], optional) – Date type of coordinate entries. Defaults to int.

Returns:

Shape obj describing a square of length <length> in the manifold <manifold>

Return type:

[Shape]