Optimization passes

graphix.optimization module

This module defines some optimization passes for patterns.

graphix.optimization.standardize(pattern: Pattern) Pattern[source]

Return a standardized form to the given pattern.

A standardized form is an equivalent pattern where the commands appear in the following order: N, E, M, Z, X, C.

Note that a standardized form does not always exist in presence of C commands. For instance, there is no standardized form for the following pattern (written in the right-to-left convention): E(0, 1) C(0, H) N(1) N(0).

The function raises NotImplementedError if there is no standardized form. This behavior can change in the future.

Parameters:

pattern (Pattern) – The original pattern.

Returns:

standardized – The standardized pattern, if it exists.

Return type:

Pattern

class graphix.optimization.StandardizedPattern(input_nodes: Iterable[Node], output_nodes: Iterable[Node], results: Mapping[Node, Outcome], n_list: Iterable[command.N], e_set: Iterable[Iterable[Node]], m_list: Iterable[command.M], c_dict: Mapping[Node, Clifford], z_dict: Mapping[Node, Iterable[Node]], x_dict: Mapping[Node, Iterable[Node]])[source]

Pattern in standardized form.

Use the method to_pattern() to get the standardized pattern.

This class uses immutable data structures for its fields (tuple, frozenset and Mapping).

Instances can be generated with the constructor from any compatible data structures, and an instance can be generated directly from a pattern with the class method from_pattern().

The constructor instantiates the Mapping fields as MappingProxyType objects over fresh dictionaries, ensuring their immutability. We expose the type Mapping instead of MappingProxyType for the readability, as they provide the same interface.

input_nodes

Input nodes.

Type:

tuple[Node, …]

output_nodes

Output nodes.

Type:

tuple[Node, …]

results

Already measured nodes (by Pauli presimulation).

Type:

Mapping[Node, Outcome]

n_list

The N commands.

Type:

tuple[command.N]

e_set

Set of edges. Each edge is a set with two elements.

Type:

frozenset[frozenset[Node]]

m_list

The M commands.

Type:

tuple[command.M]

c_dict

Mapping associating Clifford corrections to some nodes.

Type:

Mapping[Node, Clifford]

z_dict

Mapping associating Z-domains to some nodes.

Type:

Mapping[Node, frozenset[Node]]

x_dict

Mapping associating X-domains to some nodes.

Type:

Mapping[Node, frozenset[Node]]

graphix.optimization.incorporate_pauli_results(pattern: Pattern) Pattern[source]

Return an equivalent pattern where results from Pauli presimulation are integrated in corrections.

graphix.optimization.remove_useless_domains(pattern: Pattern) Pattern[source]

Return an equivalent pattern where measurement domains that are not used given the specific measurement angles and planes are removed.

graphix.optimization.single_qubit_domains(pattern: Pattern) Pattern[source]

Return an equivalent pattern where domains contains at most one qubit.