Linear Cost Functions

Cost functions such as nonlocality witnesses can often be expressed as a linear function on the network probabilities or correlators.

qnetvo.linear_probs_cost_fn(network_ansatz, game, postmap=tensor([], dtype=float64, requires_grad=True), qnode_kwargs={})[source]

Constructs an ansatz-specific cost that is a linear function of the network probablities.

The cost function is encoded into a game matrix whose coefficients scale conditional probabilities for the network. The cost is derived from the score which is evaluated as,

\[\langle\mathbf{G},\mathbf{P}\rangle = \sum_{\{\vec{x}_i\}_i,\vec{a}} G_{a|\{x_i\}_i} P(a|\{x_i\}),\]

where \(\mathbf{P}\) is a behavior (see qnetvo.behavior_fn()) and \(\{\vec{x}_i\}_i\) specifies the collection of inputs for each layer as indexed by \(i\).

A post-processing map \(\mathbf{L}\) may optionally be applied as \(\mathbf{L}\mathbf{P}_{Net}\) where

\[\mathbf{L} = \sum_{z',z}P(z'|z)|z'\rangle\langle z|.\]

In the above expression, \(z'\) is a new output drawn from a new alphabet.

Parameters:
  • network_ansatz (NetworkAnsatz class) – The network to which the cost function is applied.

  • game (np.arrray) – A matrix with dimensions A x (\prod_i X_i) for

  • postmap (optional np.ndarray) – A post-processing map applied to the bitstrings output from the quantum circuit. The postmap matrix is column stochastic, that is, each column sums to one and contains only positive values.

Returns:

A cost function evaluated as cost(*network_settings).

Return type:

function

Raises:

ValueError – If the number of outputs from the qnode do not match the the number of rows in the specified game.