Network Ansatzes#

The quantum network ansatz is a collection of network nodes aggregated into sequential layers ordered as prepare nodes, noise or processing nodes, and measure nodes. It is important that all measurement nodes are in the final layer. The nodes in each layer are independent and each operate upon a unique set of wires. If two sequential nodes operate on the same wire, then one-way quantum communication is sent from the first node to the second node.

class qnetvo.NetworkAnsatz(*layers, dev_kwargs=None)[source]#

The NetworkAnsatz class describes a parameterized quantum network.

Parameters:
  • layers (list[list[qnetvo.NetworkNode]]) – Each layer represents a chronological step in the network simulation. The nodes in each layer apply their operations in parallel where no two nodes can operate on the same wire.

  • dev_kwargs (optional dictionary) – Keyword arguments for the pennylane.device function.

Returns:

An instantiated NetworkAnsatz.

There are some conventions that should be followed when defining network layers:

  1. The first layer should contain all qnetvo.PrepareNode s in the network.

  2. The last layer should contain all qnetvo.MeasureNode s in the network.

  3. If classical communication is considered, then a qnetvo.CCSenderNode must be used to obtain the communicated values in a layer preceding the layers where qnetvo.CCReceiverNode s consume the classical communication.

ATTRIBUTES:

  • layers - list[list[NetworkNode]], The input layers of network nodes.

  • layers_wires - list[qml.wires.Wires], The wires used for each layer.

  • layers_cc_wires_in - list[qml.wires.Wires], The classical communication wires input to each network layer.

  • layers_cc_wires_out - list[qml.wires.Wires], The classical communication wires output from each network layer.

  • layers_num_settings - list[int], The number of setting used in each layer.

  • layers_total_num_in - list[int], The total number of inputs for each layer.

  • layers_node_num_in - list[list[int]], The number of inputs for each node in the layer.

  • layers_num_nodes - list[int], The number of nodes in each layer.

  • network_wires - The list of wires used by the network ansatz.

  • network_cc_wires - The list of classical communication wires in the network.

  • num_cc_wires - The number of classical communication wires.

  • dev_kwargs - mutable, the keyword args to pass to the pennylane.device function.

    If no dev_kwargs are provided, a "default.qubit" is constructed for noiseless networks.

  • fn (function) - A quantum function implementing the quantum network ansatz.

  • parameter_partitions (List[List[List[Tuple]]]) - A ragged array containing tuples that specify

    how to partition a 1D array of network settings into the subset of settings passed to the qnode simulating the network. See get_network_parameter_partitions() for details.

Raises:
  • ValueError – If the wires are not unique across all nodes in an ansatz layer or the cc_wires_out are not unique across all layers.

  • ValueError – If cc_wires_in are used by a layer preceding the classical values output onto cc_wires_out.

static check_cc_causal_structure(cc_wires_in_layers, cc_wires_out_layers)[source]#

Verifies that the classical communication is causal.

Note that cc_wires_out describes the classical communication senders while cc_wires_in describe classical communication receivers. All network ansatzes must have a causal structure where nodes output their classical communication in layers that precede the nodes that use that classical communication.

Params cc_wires_in_layers:

The classical communication input wires, cc_wires_in, considered for each layer.

Params cc_wires_out_layers:

The classical communication output wires, cc_wires_out, considered for each layer.

Returns:

True if the

Raises:

ValueError – If cc_wires_in are used by a layer preceding the classical values output onto cc_wires_out.

static circuit_layer_fn(layer_nodes)[source]#

Constructs a quantum function for an ansatz layer of provided network nodes.

Parameters:

layer_nodes (list[qnetvo.NetworkNode]) – A list of nodes in a network layer.

Returns:

A quantum function evaluated as circuit_layer(settings) where settings is an array constructed via the layer_settings function.

Return type:

function

static collect_wires(wires_lists, check_unique=True)[source]#

A helper method for the NetworkAnsatz class which collects and aggregates the wires from a set of collection of network nodes (prepare_nodes or measure_nodes).

Parameters:

network_nodes (list[PrepareNode or MeasureNode]) – A list consisting of either PrepareNode’s or MeasureNode’s.

Raises:

ValueError – If the same wire is used in two different nodes in network_nodes.

expand_qnode_settings(qn_settings, network_inputs)[source]#

Constructs network settings from qnode settings and the network inputs.

This implements the reverse mapping implemented in qnetvo.NetworkAnsatz.qnode_settings(). Since there are fewer qnode settings than network settings, empty elements in the returned list are set to zero.

Parameters:
  • qn_settings (array[float]) – Settings to pass to the network qnode.

  • network_inputs (list[int]) – The considered classical network inputs.

Returns:

The network settings

Return type:

array[float]

get_network_parameter_partitions()[source]#

A nested list containing tuples that specify how to partition a 1D array of network settings into the subset of settings passed to the qnode simulating the network. Each tuple (start_id, stop_id) is indexed by layer_id, node_id, and classical input_id as parameter_partitions[layer_id][node_id][input_id] => (start_id, stop_id). The start_id and stop_id describe the slice network_settings[start_id:stop_id].

layer_settings(network_settings, layer_id, layer_inputs)[source]#

Constructs the list of settings for a circuit layer in the network ansatz.

Parameters:
  • network_settings (List[Float]) – A list containing the circuit settings for each node in the network.

  • layer_id (Int) – The id for the targeted layer.

  • layer_inputs (List[Int]) – A list of the classical inputs supplied to each network node.

Returns:

A 1D array of settings for the circuit layer.

Return type:

List[float]

qnode_settings(network_settings, network_inputs)[source]#

Constructs a list of settings to pass to the qnode executing the network ansatz.

Parameters:
  • network_settings (list[list[np.ndarray]]) – The settings for the network ansatz scenario.

  • network_inputs (List[List[int]]) – The classical inputs passed to each network node.

Returns:

A list of settings to pass to the constructed qnode.

Return type:

np.array

rand_network_settings(fixed_setting_ids=[], fixed_settings=[])[source]#

Creates an array of randomized differentiable settings for the network ansatz. If fixed settings are specified, then they are marked as requires_grad=False and not differentatiated during optimzation.

Parameters:
  • fixed_setting_ids (optional List[Int]) – The ids of settings that are held constant during optimization. Also requires fixed_settings to be provided.

  • fixed_settings (optional List[Float]) – The constant values for fixed settings.

Returns:

A 1D list of qnp.tensor scalar values having requires_grad=True.

Return type:

List[Float]

tf_rand_network_settings(fixed_setting_ids=[], fixed_settings=[])[source]#

Creates a randomized settings array for the network ansatz using TensorFlow tensor types.

Parameters:
  • fixed_setting_ids (optional List[Int]) – The ids of settings that are held constant during optimization. Also requires fixed_settings to be provided.

  • fixed_settings (optional List[Float]) – The constant values for fixed settings.

Returns:

A 1D list of tf.Variable and tf.constant scalar values.

Return type:

List[tf.Tensor]

zero_network_settings()[source]#

Creates a settings array for the network ansatz that consists of zeros.

Returns:

A 1D list of np.tensor scalar values having requires_grad=True.

Return type:

List[Float]