PhotonSharp

PhotonSharp / Developer reference

λλ API reference

Search the implemented language surface: core operations, optical extensions, syntax, literals, parameter ranges, and examples.

Scope: This reference lists everything accepted by the current .photon expression parser. There are no user-defined classes, methods, imports, loops, or functions in this language. Optical operations are expression forms, not object methods. Read the guide for the core-first learning path.

Name / categorySignatureReturnsBehavior and constraints
letSyntaxlet name = value in bodytype of bodyBind one result for use in the following expression.

Bindings are nested expressions, not mutable assignments. A bound optical signal must be consumed exactly once.

Example: let light = input(0) in
output(1) <- light;
()

unpackSyntaxunpack pair as (a, b) in bodytype of bodyBind both values of a two-output operation.

Use for split, power_split, unitary, coupler, or mzi. Both signals must be consumed.

Example: unpack split(0.5, input(0)) as (a, b) in
output(1) <- a; output(2) <- b; ()

pairSyntax(a, b)(Optical, Optical)Construct an ordered pair of optical signals.

Use as the last argument to unitary, coupler, and mzi. This is an expression, not an array.

Example: unitary(H, (a, b))

unitSyntax()UnitFinish an expression after all signals are consumed.

The Unit literal usually terminates a program. It carries no optical signal.

Example: output(1) <- input(0); ()

outputCoreoutput(port) <- signal; bodytype of bodyConsume a signal at a numbered output port.

Output ports are unique nonnegative integers. The semicolon introduces the remaining program; use () when finished.

Constraints: port: nonnegative integer, unique

Example: output(1) <- light; ()

inputCoreinput(port)OpticalCreate an optical input from the test bench.

The default ideal input is 1 mW at 1550 nm; input properties can be changed in Circuit Designer. The same input port cannot be read twice.

Constraints: port: nonnegative integer, unique

Example: let light = input(0) in output(1) <- light; ()

phaseCorephase(radians, signal)OpticalApply an ideal phase rotation.

The complex field is multiplied by exp(i × radians). This preserves power in the ideal model.

Constraints: radians: finite real

Example: phase(pi / 2, light)

splitCoresplit(ratio, signal)(Optical, Optical)Split the field by core λλ amplitude ratio.

The output fields are ratio × E and (1 − ratio) × E. At ratio 0.5, each branch has 25% of input power; use power_split for a power-conserving split.

Constraints: ratio: 0 to 1

Example: unpack split(0.5, light) as (a, b) in …

unitaryCoreunitary(matrix, (a, b))(Optical, Optical)Apply a 2×2 unitary matrix to two optical fields.

Matrix may be H, I, or [[a,b],[c,d]] with real or complex entries. The compiler checks unitarity to a numerical tolerance.

Constraints: matrix: 2×2 unitary

Example: unpack unitary(H, (a, b)) as (upper, lower) in …

sourceOptical extensionsource(power_mw, phase_rad)OpticalCreate a coherent model source.

The field has amplitude √power and the given phase. source(0, 0) supplies a zero-power input to a two-input component. Sources are ideal and mutually coherent in this model.

Constraints: power_mw ≥ 0; phase_rad finite

Example: let light = source(1, 0) in output(1) <- light; ()

waveguideOptical extensionwaveguide(length_um, loss_db_cm, effective_index, signal)OpticalApply compact waveguide phase and loss.

Uses path length, distributed loss, effective index, and the configured wavelength to calculate forward propagation. No bend geometry or electromagnetic solver is implied.

Constraints: length_um ≥ 0; loss_db_cm ≥ 0; effective_index > 0

Example: waveguide(83, 2, 2.4, light)

attenuateOptical extensionattenuate(loss_db, signal)OpticalApply lumped optical loss.

The field amplitude is multiplied by 10^(−loss_db/20), so power falls by 10^(−loss_db/10).

Constraints: loss_db ≥ 0

Example: attenuate(3, light)

kerrOptical extensionkerr(gamma_rad_per_mw, signal)
kerr(gamma_rad_per_mw, loss_db, signal)
OpticalApply illustrative power-dependent phase.

The phase shift is gamma_rad_per_mw × input power in mW. The optional loss_db also attenuates the field. This is a compact model, not calibrated material behavior.

Constraints: gamma finite; optional loss_db ≥ 0

Example: kerr(0.7, light)

power_splitOptical extensionpower_split(ratio, signal)(Optical, Optical)Split input power between two outputs.

Output field amplitudes are √(1 − ratio) × E and √ratio × E. At 0.5, each branch has half the input power. Compare core split.

Constraints: ratio: 0 to 1

Example: unpack power_split(0.5, light) as (a, b) in …

couplerOptical extensioncoupler(ratio, (a, b))(Optical, Optical)Mix two coherent fields in an ideal directional coupler.

Uses through amplitude √(1 − ratio) and cross amplitude i√ratio. Both inputs and both outputs are optical signals.

Constraints: ratio: 0 to 1

Example: unpack coupler(0.5, (a, b)) as (upper, lower) in …

mziOptical extensionmzi(phase_rad, coupling_ratio, (a, b))(Optical, Optical)Model a Mach–Zehnder interferometer.

Two identical ideal couplers surround a phase shift in one arm. It consumes a pair and returns a pair.

Constraints: phase_rad finite; coupling_ratio: 0 to 1

Example: unpack mzi(pi / 2, 0.5, (a, b)) as (upper, lower) in …

probeOptical extensionprobe(threshold_mw, signal)OpticalRecord a threshold measurement and pass the optical signal onward.

The measured bit is 1 when input power is at least threshold_mw, otherwise 0. The optical field is passed through unchanged. The bit is a readout, not an optical Boolean value.

Constraints: threshold_mw ≥ 0

Example: let observed = probe(0.5, light) in output(1) <- observed; ()

detectOptical extensiondetect(responsivity_a_w, signal); bodytype of bodyTerminate a signal at a model photodetector.

Reports photocurrent in mA as input power in mW × responsivity in A/W. It consumes the optical signal and returns Unit, allowing the next expression after a semicolon.

Constraints: responsivity_a_w ≥ 0

Example: detect(0.8, light); ()

realValues0.5 · -1 · 1e-3RealNumeric literal for operation parameters.

Parameter arithmetic supports multiplication and division, not general addition/subtraction or named numeric variables. Values must be finite.

Constraints: finite real

Example: phase(pi / 2, light)

piValuespi · πRealMathematical π in numeric parameters.

Both spellings are accepted by the parser. Use for phase angles and unitary matrix entries.

Example: phase(π, light)

HValuesH2×2 unitary matrixBuilt-in normalized Hadamard matrix.

Rows are [1/√2, 1/√2] and [1/√2, −1/√2]. Only accepted as a unitary matrix argument.

Example: unitary(H, (a, b))

IValuesI2×2 unitary matrixBuilt-in identity matrix.

Passes the two fields through unchanged in the ideal unitary operation. Only accepted as a matrix argument.

Example: unitary(I, (a, b))

complexValuescomplex(real, imag)Complex matrix entrySpecify a complex entry in an explicit unitary matrix.

Only accepted inside an explicit 2×2 matrix passed to unitary; not a general complex-number constructor for optical expressions.

Constraints: real and imag finite

Example: unitary([[1, 0], [0, complex(0, 1)]], (a, b))

matrixValues[[a, b], [c, d]]2×2 unitary matrixExplicit matrix literal for unitary.

Rows each contain two real or complex entries. The result must be unitary.

Constraints: 2×2 and unitary

Example: unitary([[1, 0], [0, 1]], (a, b))

operatorsSyntax= · in · as · <- · ; · , · ( ) · [ ] · * · /SyntaxPunctuation and operators supported by the source parser.

= binds after let; in starts a body; as names pair outputs; <- connects an output; ; continues after output or detector. * and / are numeric parameter arithmetic only. There is no general + or binary − operator.

Example: let x = input(0) in output(1) <- x; ()

commentsSyntax// comment · # commentSyntaxLine comments.

Either marker ignores the remainder of the line. Comments cannot interrupt a token.

Example: // Explain this phase
let x = input(0) in …

Operation parameters are positional and finite. Optical values obey the one-use rule. The simulator uses an idealized compact model, not a foundry-calibrated device model.