circuit module#

Circuits#

This module provides the Circuit class, which is the primary modularization object in JITX for creating hierarchical designs with ports, components, and subcircuits.

class Circuit[source]#

Bases: Positionable

The Circuit is JITX’s primary modularization object. The main function of a Circuit is instantiate ports that can be seen as an external interface, instantiate subcircuits or components, as well as net ports of these elements together.

Ports, components, and other circuits can be created directly in the class for convenience, and will be instantiated separately as instance attributes for each created circuit instance. It’s perfectly valid to add elements to self in the __init__ method, and in fact, type of coding logic, such as a parameterized circuit, would need to go into an __init__ method, as it’s not possible to execute that properly in the class context.

All elements of the circuit needs to be reachable from the circuit in some way, it is not sufficient to merely create a component, it must be assigned to member field in the circuit in some way. It can be added to a container (such as a list, or a dictionary) that is assigned to the circuit object, not every component needs have its own attribute. The same is true for nets.

A general purpose += operator is provided to add elements to the circuit that do not need an assigned name. They’ll all be gathered into a private list that is not accessible from the outside. Note that if elements that have their name displayed somewhere (such as nets in the schematic) are added to this list, they will still be displayed, but their name may look confusing. For most objects it’s advisable to either assign them to a field or add them to a list or mapping which are rendered in a sensible way.

>>> class MyCircuit(Circuit):
...     # assume FancyComponent has an `n` and a `p` port. JITX's instantiation
...     # mechanism will create a new instance of FancyComponent for each
...     # instance of MyCircuit
...     comp = FancyComponent()
...     diffp = DiffPair()
...
...     def __init__(self):
...         self.nets = [
...             diffp.n + comp.n,
...             diffp.p + comp.p,
...         ]
in_bom: bool | None = None#

Whether the components within this circuit are in the bill of materials. If unset, defers to the parent Circuit’s in_bom attribute. If there is no parent circuit, defaults to True.

soldered: bool | None = None#

Whether the components within this circuit are soldered on the board. If unset, defers to the parent Circuit’s soldered attribute. If there is no parent circuit, defaults to True.

schematic_x_out: bool | None = None#

Whether the components within this circuit are marked with a red X in the schematic. If unset, defers to the parent Circuit’s schematic_x_out attribute. If there is no parent circuit, defaults to False.

transform: Placement | None = Placement(Transform((0, 0), 0, (1, 1)), 0)#

The placement of this circuit relative to the parent circuit.

require(Bundle, /, *, count=None, restrictions=None)[source]#

Require a port bundle to be provided a subcircuit, or, alternatively, by this circuit as a self-provide.

Note that the returned port instance is a placeholder port for the provided port that can be netted with other ports, but should not be added to this circuit as a member field, as it’s not a port that this circuit itself exposes.

Parameters:
Return type:

Union[TypeVar(T, bound= Port), Sequence[TypeVar(T, bound= Port)]]

Returns:

The required port bundle instance.

>>> class MyCircuit(Circuit):
...     subcircuit = MySubCircuit()
...     my_signal_port = DiffPair()
...     def __init__(self):
...         diffpair = self.subcircuit.require(DiffPair)
...         self.signal_net = self.my_signal__port + diffpair
place(instance, placement, /, *, on=Side.Top, relative_to=None)[source]#

Place a component or circuit on the board relative to this circuit’s frame of reference. It is different from at() in that it does not modify the instance’s actual placement in its parents frame of reference, but instead adds a placement request for a child circuit or component. If the instance is introspected before placement occurs, the placement will not be reflected in the instance’s Trace transform.

Note that circuits have a default placement of (0, 0) on top, which is to allow for elements inside the circuit to be placed relative to the design origin. If the circuit should have a free-floating frame of reference that components are placed relative to, the circuit should either be given a placement using at() or explicitly set to be free floating using circuit.at(floating=True). Note that if the circuit is free floating and components inside the circuit are not placed, it is ambiguous which frame of reference is modified when the components are placed.

Return type:

TypeVar(T, bound= Component | Circuit)

Parameters:
>>> class MyCircuit(Circuit):
...     def __init__(self):
...         self.component = MyComponent()
...         self.place(self.component, Transform.rotate(90))
annotate(text, *, normalize=True)[source]#

Add a schematic annotation.

Parameters:
  • text (str) – Markdown formatted text to add as an annotation.

  • normalize – Whether to normalize the indentation, this is on by default, and is useful to allow natural indentation of multiline strings.

Return type:

None

>>> class MyCircuit(Circuit):
...     def __init__(self):
...         self.annotate("Hello, world!")
at(x=None, y=None, /, *, on=Side.Top, rotate=0, floating=False)[source]#

Place the circuit on the board relative to its parent’s frame of reference.

Parameters:
  • x (Placement | Transform | TypeAliasType | float | None) – x-value, transform, or placement to adopt.

  • y (float | None) – y-value if x is an x-value. This argument is only valid in that context.

  • on (Side) – If set to bottom, this object will be placed on the “opposite” side from its frame of reference. This means if the frame of reference is on the bottom of the board, setting this to “bottom” will actually put the object back on top.

  • rotate (float) – Rotation in degrees to apply to the object. Only applicable if not supplying a transform or placement.

  • floating (bool) – If set to True, no other arguments are valid, and will allow this circuit to be free floating, subject to interactive placement.

Return type:

Self

Returns:

The circuit itself, for method chaining.

class Annotation(text)[source]#

A text entity in the schematic. Typically not used directly, but rather through the convenience method annotate() which also normalizes the indentation.

Parameters:

text (str)

text: str#
class SchematicGroup(elem=None, /, *elems)[source]#

Bases: Structurable

A schematic group defines elements that will be placed together under a single logical grouping in the schematic. The group’s name is derived from the name of the instance attribute used to define the SchematicGroup object.

>>> class MyCircuit(Circuit):
...     comp = MyComponent()
...     def __init__(self):
...         # Add 'comp' to the schematic group named 'my_group'
...         self.my_group = SchematicGroup(self.comp)
Parameters:
class CurrentCircuit(circuit)[source]#

Bases: Context

The current circuit being processed. Should not be used directly, but rather accessed through jitx.current.circuit instead.

>>> def get_ports() -> list[Port]:
...    circuit = jitx.current.circuit
...    ports = extract(circuit, Port)
...    return list(ports)
Parameters:

circuit (Circuit)

circuit: Circuit#
class InstancePlacement(instance, placement, relative_to=None)[source]#

Bases: Critical

A placement of a component or circuit relative to another component or circuit.

These are created by the place() method, and do not need to be created manually.

Parameters:
instance: ReferenceType[Component | Circuit]#

The component or circuit to place.

placement: Placement#

The placement of the component or circuit.

relative_to: ReferenceType[Component | Circuit] | None = None#

The circuit or component to place relative to. If not provided, the placement is relative to the circuit’s frame of reference.