circuits
Circuit Maps¶
Circuits are a way of representing a GDS circuit with its parameters. A CircuitMap collects a set of Circuit objects and provides methods for sorting or filtering them by parameters.
Using this module, you can
- read/write text representations
- select specific circuits by parameters
- track spatial locations of circuits
Examples¶
Suppose I have a text file of circuits (see documentation for specification of CircuitMap text files). I can load it into AutoGator and create a CircuitMap:
>>> p = Path(Path.home() / "Downloads/mzis.txt")
>>> cm = CircuitMap.loadtxt(p)
I can update existing (or add new) parameters in bulk:
>>> cm.update_params(submitter="sequoiac")
>>> for cir in cm:
... cir.loc += (0, 127)
>>> cm.update_params(ports="LD")
In this example, suppose we have the circuits from a grouping on a GDS. Suppose this grouping is repeated six times across the file. I can create a map for the entire GDS fild by copying CircuitMaps and adjusting its parameters.
>>> dx = 2500
>>> dy = 4200
>>> groups = [deepcopy(cm) for i in range(6)]
>>> offsets = {
... "1": (0, 0),
... "2": (dx, 0),
... "3": (2*dx, 0),
... "4": (0, dy),
... "5": (dx, dy),
... "6": (2*dx, dy),
... }
>>> for i, group in enumerate(groups):
... print(len(group))
... grouping = str(i + 1)
... group.update_params(grouping=grouping)
... for cir in group:
... cir.loc += offsets[grouping]
I can then combine all the groups into a single CircuitMap:
>>> cmap = CircuitMap()
>>> for group in groups:
... cmap += group
Now that I have a complete CircuitMap, I can export it to a text file for use in automated tests.
>>> cmap.savetxt("updatedmzis.txt")
Circuit
¶
A circuit is a single isolated device from a GDS file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loc |
Union[Tuple[float, float], Location] |
Location of the circuit in the GDS file. Uniquely describes one circuit, since multiple circuits cannot share a single location. |
required |
params |
Dict[str, str] |
Key, value parameters describing the circuit. Values must all be strings and pairs are delimited by commas. |
required |
loc: Location
property
writable
¶
Location of the circuit in the GDS file.
CircuitMap
¶
Stores circuit objects.
CircuitMaps are indexable; Circuit objects can be accessed by index or by location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
circuits |
List[Circuit] |
List of Circuit objects. |
[] |
__add__(self, o)
special
¶
Adds two CircuitMaps together. Does not modify the original CircuitMap.
filterby(self, **kwargs)
¶
Filters out circuits that don't match the key, value pairs provided.
If the key doesn't exist in a circuit, it will be filtered out.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
str |
The key, value pairs to filter on. All parameters are interpreted as strings. |
{} |
Returns:
Type | Description |
---|---|
CircuitMap |
New CircuitMap that contains filtered circuits. |
filterout(self, **kwargs)
¶
Filters out any circuits that match the key, values pairs provided.
If the circuit does not contain the given key, it will be included.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
str |
The key, value pairs to filter out on. All parameters are interpreted as strings. |
{} |
Returns:
Type | Description |
---|---|
CircuitMap |
New CircuitMap that excludes filtered out circuits. |
loadtxt(filename)
classmethod
¶
Loads a text file containing circuit information.
Circuit information is expected to be in the following format::
(x, y) key1=value1, key2=value 2, key3=value 3, ...
Full-line comments are allowed and are prefixed by '#'. Any lines defining circuits do not support end-of-line comments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
Union[str, Path] |
Name of the file to load. |
required |
Exceptions:
Type | Description |
---|---|
FileNotFoundError |
If the file does not exist. |
Returns:
Type | Description |
---|---|
CircuitMap |
CircuitMap containing the circuits in the file. |
savetxt(self, path)
¶
Saves the circuit map to a text file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path] |
File path to save the text file. |
required |
update_params(self, **kwargs)
¶
Updates the parameters of all circuits in the CircuitMap.
If the parameter doesn't exist in a circuit, it will be added.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
dict |
The key, value pairs to update the circuits with. |
{} |
Location (tuple)
¶
Location is the GDS coordinate of a circuit as an (x, y) pair.
Typically signifies the presence of a grating coupler.
Examples:
(1, 2)
Attributes:
Name | Type | Description |
---|---|---|
x |
float |
The x coordinate of the location. |
y |
float |
The y coordinate of the location. |
__add__(self, o)
special
¶
Locations can be added to other Locations or tuples of length 2.
__eq__(self, o)
special
¶
Locations can be compared to other Locations or tuples of length 2.
__getnewargs__(self)
special
¶
Return self as a plain tuple. Used by copy and pickle.
__new__(_cls, x=0, y=0)
special
staticmethod
¶
Create new instance of Location(x, y)
__repr__(self)
special
¶
Return a nicely formatted representation string