Skip to content

wire

eigenkit.photonics.wire

The JSON encoding of photonic circuits.

This module is the photonic counterpart of core.wire. It turns a PhotonicCircuitSpec into plain JSON data and back, so that a circuit can be sent to a service or stored. It holds only data, and does not use Perceval.

The angles of the components use the same encoding as the parameters of the qubit circuits, so a WeightRef or an InputRef means the same thing in both.

photonic_spec_from_json(data)

Build a photonic circuit from the data that photonic_spec_to_json produced.

The circuit goes through the same checks as one built by hand.

Parameters:

Name Type Description Default
data dict

The encoded circuit.

required

Returns:

Type Description
PhotonicCircuitSpec

The decoded PhotonicCircuitSpec.

Raises:

Type Description
TypeError

If data is not a dictionary.

KeyError

If a key is missing.

ValueError

If a component is unknown, or the circuit is not valid.

photonic_spec_to_json(spec)

Encode a photonic circuit as JSON data.

Parameters:

Name Type Description Default
spec PhotonicCircuitSpec

The circuit to encode.

required

Returns:

Type Description
dict

A dictionary with the keys "n_modes", "n_weights", "n_inputs", "input_state" and "components". Every integer in it is a plain Python int, so json.dumps accepts it.