mm.physics.representations.Bargmann

class mrmustard.physics.representations.Bargmann(A, b, c=1.0)[source]

Bases: Representation

The Fock-Bargmann representation of a broad class of quantum states, transformations, measurements, channels, etc.

The ansatz available in this representation is a linear combination of exponentials of bilinear forms with a polynomial part:

\[F(z) = \sum_i \textrm{poly}_i(z) \textrm{exp}(z^T A_i z / 2 + z^T b_i)\]

This function allows for vector space operations on Bargmann objects including linear combinations (+), outer product (&), and inner product (@).

>>> from mrmustard.physics.representations import Bargmann
>>> from mrmustard.physics.triples import displacement_gate_Abc, vacuum_state_Abc

>>> # bargmann representation of one-mode vacuum
>>> rep_vac = Bargmann(*vacuum_state_Abc(1))

>>> # bargmann representation of one-mode dgate with gamma=1+0j
>>> rep_dgate = Bargmann(*displacement_gate_Abc(1))

The inner product is defined as the contraction of two Bargmann objects across marked indices. Indices are marked using __getitem__. Once the indices are marked for contraction, they are be used the next time the inner product (@) is called. For example:

>>> import numpy as np

>>> # mark indices for contraction
>>> idx_vac = [0]
>>> idx_rep = [1]

>>> # bargmann representation of coh = vacuum >> dgate
>>> rep_coh = rep_vac[idx_vac] @ rep_dgate[idx_rep]
>>> assert np.allclose(rep_coh.A, [[0,],])
>>> assert np.allclose(rep_coh.b, [1,])
>>> assert np.allclose(rep_coh.c, 0.6065306597126334)

This can also be used to contract existing indices in a single Bargmann object, e.g. to implement the partial trace.

>>> trace = (rep_coh @ rep_coh.conj()).trace([0], [1])
>>> assert np.allclose(trace.A, 0)
>>> assert np.allclose(trace.b, 0)
>>> assert trace.c == 1

The A, b, and c parameters can be batched to represent superpositions.

>>> # bargmann representation of one-mode coherent state with gamma=1+0j
>>> A_plus = [[0,],]
>>> b_plus = [1,]
>>> c_plus = 0.6065306597126334

>>> # bargmann representation of one-mode coherent state with gamma=-1+0j
>>> A_minus = [[0,],]
>>> b_minus = [-1,]
>>> c_minus = 0.6065306597126334

>>> # bargmann representation of a superposition of coherent states
>>> A = [A_plus, A_minus]
>>> b = [b_plus, b_minus]
>>> c = [c_plus, c_minus]
>>> rep_coh_sup = Bargmann(A, b, c)

Note that the operations that change the shape of the ansatz (outer product and inner product) do not automatically modify the ordering of the combined or leftover indices. However, the reordering method allows reordering the representation after the products have been carried out.

Parameters:
  • A (Batch[ndarray[Tuple[int, int], TypeVar(C, complex64, complex128)]]) – A batch of quadratic coefficient \(A_i\).

  • b (Batch[ndarray[Tuple[int], TypeVar(C, complex64, complex128)]]) – A batch of linear coefficients \(b_i\).

  • c (Batch[ndarray[Tuple[int, ...], TypeVar(C, complex64, complex128)]]) – A batch of arrays \(c_i\).

Note: The args can be passed non-batched, as they will be automatically broadcasted to the correct batch shape.

A

The batch of quadratic coefficient \(A_i\).

ansatz

The ansatz of the representation.

b

The batch of linear coefficients \(b_i\)

c

The batch of arrays \(c_i\).

A

The batch of quadratic coefficient \(A_i\).

ansatz

The ansatz of the representation.

b

The batch of linear coefficients \(b_i\)

c

The batch of arrays \(c_i\).

__call__(z)

Evaluates the Bargmann function at the given array of points.

conj()

The conjugate of this Bargmann object.

from_ansatz(ansatz)

Returns a Bargmann object from an ansatz object.

plot([just_phase, with_measure, log_scale, ...])

Plots the Bargmann function \(F(z)\) on the complex plane.

reorder(order)

Reorders the indices of the A matrix and b vector of the (A, b, c) triple in this Bargmann object.

trace(idx_z, idx_zconj)

The partial trace over the given index pairs.

__call__(z)[source]

Evaluates the Bargmann function at the given array of points.

Parameters:

z (ndarray[Tuple[int, ...], TypeVar(C, complex64, complex128)]) – The array of points.

Return type:

ndarray[Tuple[int, ...], TypeVar(C, complex64, complex128)]

Returns:

The value of the Bargmann function at z.

conj()[source]

The conjugate of this Bargmann object.

classmethod from_ansatz(ansatz)[source]

Returns a Bargmann object from an ansatz object.

Return type:

Bargmann

plot(just_phase=False, with_measure=False, log_scale=False, xlim=(-6.283185307179586, 6.283185307179586), ylim=(-6.283185307179586, 6.283185307179586))[source]

Plots the Bargmann function \(F(z)\) on the complex plane. Phase is represented by color, magnitude by brightness. The function can be multiplied by \(exp(-|z|^2)\) to represent the Bargmann function times the measure function (for integration).

Parameters:
  • just_phase – Whether to plot only the phase of the Bargmann function.

  • with_measure – Whether to plot the bargmann function times the measure function \(exp(-|z|^2)\).

  • log_scale – Whether to plot the log of the Bargmann function.

  • xlim – The x limits of the plot.

  • ylim – The y limits of the plot.

Returns:

The figure and axes of the plot

reorder(order)[source]

Reorders the indices of the A matrix and b vector of the (A, b, c) triple in this Bargmann object.

>>> from mrmustard.physics.representations import Bargmann
>>> from mrmustard.physics.triples import displacement_gate_Abc

>>> rep_dgate1 = Bargmann(*displacement_gate_Abc([0.1, 0.2, 0.3]))
>>> rep_dgate2 = Bargmann(*displacement_gate_Abc([0.2, 0.3, 0.1]))

>>> assert rep_dgate1.reorder([1, 2, 0, 4, 5, 3]) == rep_dgate2
Parameters:

order (tuple[int, ...] | list[int]) – The new order.

Return type:

Bargmann

Returns:

The reordered Bargmann object.

trace(idx_z, idx_zconj)[source]

The partial trace over the given index pairs.

Parameters:
  • idx_z (tuple[int, ...]) – The first part of the pairs of indices to trace over.

  • idx_zconj (tuple[int, ...]) – The second part.

Returns:

the ansatz with the given indices traced over

Return type:

Bargmann