merlin.core.circuit module

Circuit is a simple container of components with metadata.

class merlin.core.circuit.Circuit(n_modes, components=<factory>, metadata=<factory>)

Bases: object

Simple circuit container.

Parameters:
  • n_modes (int) – Number of photonic modes in the circuit.

  • components (list[Any]) – Ordered list of circuit components.

  • metadata (dict[str, Any]) – Arbitrary circuit metadata.

add(component)

Append a component and return the circuit for chained calls.

Parameters:

component (Any) – Circuit element such as a rotation, beam splitter, or measurement.

Returns:

self to support fluent-style chaining.

Return type:

Circuit

clear()

Remove every component and metadata entry from the circuit.

components: list[Any]
property depth: int

Estimate logical depth by summing component depths when available.

get_parameters()

Collect parameter placeholders exposed by each component.

Returns:

Mapping from parameter name to default value or None.

Return type:

dict[str, Any]

metadata: dict[str, Any]
n_modes: int
property num_components: int

Return the count of registered components.