merlin.core.components module
The merlin.core.components module defines the fundamental building blocks for photonic quantum circuits in Merlin. These components are platform-agnostic, descriptive objects that specify what should be present in a circuit (such as rotations, beam splitters, interferometers, and measurements), rather than how they are implemented on a specific backend.
Why use components?
Components provide a clear, modular, and backend-independent way to describe quantum circuits.
They enable high-level circuit construction, parameter management (fixed, trainable, or input-driven), and facilitate translation to various simulation or hardware platforms.
By separating intent from implementation, components make it easy to prototype, optimize, and analyze quantum circuits in a flexible and extensible manner.
Main components include:
Rotation: Describes a phase shifter (single-mode rotation), with configurable axis, value, and parameter role (fixed, trainable, or input).
BeamSplitter: Represents a two-mode mixing operation, with tunable mixing angle (theta) and phase (phi), both of which can be fixed or trainable.
EntanglingBlock: Specifies a block of entangling operations (e.g., nearest-neighbor beam splitters) to increase circuit expressivity.
GenericInterferometer: Encodes a universal linear optical transformation over multiple modes, optionally trainable.
These components are used by higher-level tools (like CircuitBuilder) to assemble, manipulate, and compile quantum circuits for simulation or execution.
Pure descriptive components that describe WHAT we want, not HOW to implement it. Components are platform-agnostic and focus on intent rather than implementation.
- class merlin.core.components.ParameterRole(*values)
Bases:
EnumRole definition for circuit parameters.
- FIXED = 'fixed'
- INPUT = 'input'
- TRAINABLE = 'trainable'
- class merlin.core.components.Rotation(target, role=ParameterRole.FIXED, value=0.0, axis='z', custom_name=None)
Bases:
objectRotation gate description. The actual parameter name will be generated by the backend based on role.
- Parameters:
target (int) – Target mode of the rotation.
role (ParameterRole) – Parameter role of the rotation.
value (float) – Fixed rotation value when
roleisParameterRole.FIXED.axis (str) – Rotation axis.
custom_name (str | None) – Optional custom parameter name.
- get_params()
Return declared parameter placeholders for the rotation.
Non-fixed rotations expose either their custom name or the automatically generated identifier so that downstream tooling can bind data or trainable tensors to the gate.
-
role:
ParameterRole= 'fixed'
- class merlin.core.components.BeamSplitter(targets, theta_role=ParameterRole.FIXED, theta_value=0.7854, phi_role=ParameterRole.FIXED, phi_value=0.0, theta_name=None, phi_name=None)
Bases:
objectBeam splitter description.
- Parameters:
targets (tuple) – Pair of target modes.
theta_role (ParameterRole) – Role of the mixing-angle parameter.
theta_value (float) – Fixed value of the mixing angle when
theta_roleis fixed.phi_role (ParameterRole) – Role of the relative-phase parameter.
phi_value (float) – Fixed value of the relative phase when
phi_roleis fixed.theta_name (str | None) – Optional symbolic name for the mixing-angle parameter.
phi_name (str | None) – Optional symbolic name for the relative-phase parameter.
- get_params()
Describe which phase shifter angles should be exposed as parameters.
-
phi_role:
ParameterRole= 'fixed'
-
theta_role:
ParameterRole= 'fixed'
- class merlin.core.components.EntanglingBlock(targets='all', pattern='nearest_neighbor', depth=1, trainable=True, name_prefix=None)
Bases:
objectEntangling block description.
- Parameters:
targets (str | list[int]) – Target modes or
"all"for every mode.pattern (str) – Connectivity pattern for the entangling block.
depth (int) – Number of repeated entangling passes.
trainable (bool) – Whether the block should expose trainable parameters.
name_prefix (str | None) – Optional prefix used when generating parameter names.
- get_params()
Entangling blocks themselves carry no direct parameters.
- class merlin.core.components.GenericInterferometer(start_mode, span, trainable=True, name_prefix=None, model='mzi', trainable_inner=None, trainable_outer=None)
Bases:
objectGeneric interferometer block spanning multiple modes.
- Parameters:
start_mode (int) – First mode covered by the interferometer.
span (int) – Number of modes covered by the interferometer.
trainable (bool) – Whether the interferometer exposes trainable parameters.
name_prefix (str | None) – Optional prefix used when generating parameter names.
model (str) – Interferometer model, either
"mzi"or"bell".trainable_inner (bool | None) – Whether inner phase shifters are trainable.
trainable_outer (bool | None) – Whether outer phase shifters are trainable.
- get_params()
Return placeholder names for every internal interferometer parameter.