Circuit

Circuit

A quantum optical circuit.

Circuit

class mrmustard.lab.circuit.Circuit(components)[source]

A quantum optical circuit.

A circuit is defined by a collection of CircuitComponents. Each mode is expected to begin with a State followed by a series of Transformations.

Parameters:

components (list[CircuitComponent]) – A list of components in the circuit.

draw(draw_params=True)[source]

A string-based representation of this circuit.

Parameters:

draw_params (bool) – Whether to draw the parameters of the components.

Returns:

A string-based representation of the circuit.

Return type:

str

expectation(operator)[source]

Compute the expectation value of an operator with respect to the circuit.

Parameters:

operator (CircuitComponent) – The operator to compute the expectation value of. Expected to be a unitary-like component (input and output ket wires on each of its modes).

Returns:

The expectation value of the operator with respect to the circuit.

Raises:

ValueError – If the operator acts on a mode that is no longer open in the circuit (e.g. already measured out).

Return type:

Scalar

run(output_shape=None, representation=None)[source]

Runs the circuit.

The return type depends on whether the underlying computational graph is fully specified or not.

Parameters:
  • output_shape (tuple[int, ...] | None) – If the circuit returns a State, the shape of the output in the Fock basis.

  • representation (Literal[ReprEnum.BARGMANN, ReprEnum.FOCK] | None) – If the circuit returns a State, the representation of the output.

Returns:

The result of the circuit.

Return type:

State | Scalar

to_comp_graph()[source]

Compiles this circuit into a ComputationalGraph.

Returns:

A computational graph representing this circuit.

Return type:

ComputationalGraph

trace_out(modes)[source]

Trace out the specified modes.

Parameters:

modes (int | tuple[int, ...]) – The modes to trace out.

Returns:

A new Circuit with modes traced out.

Return type:

Circuit