pygsti.evotypes.stabilizer_slow.stabilizer

Defines the StabilizerState and StabilizerFrame classes

Module Contents

Classes

StabilizerFrame

Encapsulates a stabilizer frame (linear combo of stabilizer states).

Functions

sframe_kronecker(sframe_factors)

Computes a tensor-product StabilizerFrame from a set of factors.

class pygsti.evotypes.stabilizer_slow.stabilizer.StabilizerFrame(state_s, state_ps=None, amps=None)

Bases: object

Encapsulates a stabilizer frame (linear combo of stabilizer states).

Stores stabilizer elements in the first n, and antistabilizer elements in the latter n columns of the “state matrix” (to facilitate composition), and phase vectors & amplitudes in parallel arrays.

Parameters

state_snumpy.ndarray

A 2n x 2n binary matrix, where n is the number of qubits. The first n columns specify stabilizer elements and the latter n colunns specify anti-stabilizer elements. In each column, bits (i,i+n) encode a Pauli on the i-th qubit: 00 = I, 10 = X, 01 = Z, 11 = -iY. (Note the -iY is different from some representations in the literature which encode 11 = Y.)

state_psnumpy.ndarray, optional

A mod-4 array of shape (k,2n) where n is the number of qubits and k is the number of components in the stabilizer frame. Each row of state_ps is the phase vector for the corresponding to to an amplitude in amps. A phase vector encodes the overall phase of each of the stabilizer and anti-stabilizer elements (the columns of state_s) by specyfing the number of ‘i’ factors (0 to 3). If None, then no phase vectors are stored.

ampsnumpy.ndarray, optional

The (complex) amplitudes for each stabilizer-state component of the frame. The length of this 1D array must equal ‘k’, the first dimension of state_ps. amps should be None when and only when state_ps is None, corresponding to the case of zero components.

Attributes

nqubitsint

The number of qubits in the state this frame represents

Initialize a new StabilizerFrame object.

Parameters

state_snumpy.ndarray

A 2n x 2n binary matrix, where n is the number of qubits. The first n columns specify stabilizer elements and the latter n colunns specify anti-stabilizer elements. In each column, bits (i,i+n) encode a Pauli on the i-th qubit: 00 = I, 10 = X, 01 = Z, 11 = -iY. (Note the -iY is different from some representations in the literature which encode 11 = Y.)

state_psnumpy.ndarray, optional

A mod-4 array of shape (k,2n) where n is the number of qubits and k is the number of components in the stabilizer frame. Each row of state_ps is the phase vector for the corresponding to to an amplitude in amps. A phase vector encodes the overall phase of each of the stabilizer and anti-stabilizer elements (the columns of state_s) by specyfing the number of ‘i’ factors (0 to 3). If None, then no phase vectors are stored.

ampsnumpy.ndarray, optional

The (complex) amplitudes for each stabilizer-state component of the frame. The length of this 1D array must equal ‘k’, the first dimension of state_ps. amps should be None when and only when state_ps is None, corresponding to the case of zero components.

property nqubits

The number of qubits in the state this frame represents

Returns

int

classmethod from_zvals(nqubits=None, zvals=None)

Create a StabilizerFrame for a computational basis state.

Parameters
nqubitsint, optional

The number of qubits. If None, inferred from the length of zvals.

zvalsiterable, optional

An iterable over anything that can be cast as True/False to indicate the 0/1 value of each qubit in the Z basis. If None, the all-zeros state is created.

Returns

StabilizerFrame

to_rep(state_space)

Return a “representation” object for this StabilizerFrame

Such objects are primarily used internally by pyGSTi to compute things like probabilities more efficiently.

Returns

StateRep

copy()

Copy this stabilizer frame.

Note that this also copies “view filters” setup via push_view calls.

Returns

StabilizerFrame

push_view(qubit_filter)

Applies a filter to the action of clifford_update.

After calling push_view, the stabilizer frame looks to some extent as though it were only a frame on the subset of qubits given by qubit_fitler. In particular, calls to clifford_update should specify clifford operations that act only on the filtered qubits. Furthermore, views can be nested. For example, if on a frame starting with 10 qubits (labeled 0 to 9) push_view([3,4,5,6]) and then push_view([0,2]) are called, the current “view” will be of the original qubits 3 and 5.

This is useful for applying “embedded” gates (those acting on just a subset of the state space).

Parameters
qubit_filterlist

A list of qubit indices to view, relative to the current view.

Returns

None

pop_view()

Removes the last-applied (via push_view()) view filter.

Returns
list

A list of qubit indices to view (a “view filter”).

format_state()

Get a string representing the full ip-th stabilizer state (w/global phase)

Returns

str

extract_all_amplitudes()

Get a dictionary of the full amplitudes of each present computational basis state.

This may take a while for many-qubit states, as it requires getting 2^(num_qubits) amplitudes.

Returns
dict

Keys are tuples of z-values specifying the different computational basis states. Values are the complex amplitudes.

to_statevec()

Convert this stabilizer frame to dense length-2^(num_qubits) complex state vector of amplitudes.

Returns

numpy.ndarray

extract_amplitude(zvals)

Get the full (not just “canonical”) amplitude of a given computational basis state.

Parameters
zvalsnumpy.ndarray

An array of 0/1 elements specifying the desired basis state.

Returns

complex

clifford_update(smatrix, svector, u_mx, qubit_filter=None)

Update this stabilizer frame by the action of a Clifford operation.

The Clifford operation is given in the usual symplectic representation. If there are any active views (from calling push_view()) and/or if qubit_filter is not None, then smatrix, svector, and u_mx should be sized for just the number of qubits in the current view.

Parameters
smatrixnumpy.ndarray

The symplectic matrix of shape (2n,2n), where n is the number of qubits (in the current view if applicable), representing the Clifford operation.

svectornumpy.ndarray

The phase vector of shape (2n,) representing the Clifford operation.

u_mxnumpy.ndarray

The dense unitary representation of the Clifford action, which is needed in order to track the global phase of the frame (state). This is a complex matrix of shape (2^n,2^n), where n is the number of qubits (in the current view if applicable).

qubit_filterlist, optional

An additional view filter to apply just for this function call (i.e. it is not stored on a stack as it is for push_view().

Returns

None

measurement_probability(zvals, qubit_filter=None, return_state=False, check=False)

Extract the probability of obtaining a given computation-basis-measurement outcome.

Parameters
zvalsnumpy.ndarray

An array of 0/1 elements specifying the computational basis outcomes.

qubit_filterlist, optional

A list specifying a subset of the qubits to measure. len(zvals) should always equal len(qubit_filter). If None, then all qubits are measured. Currently unsupported.

return_statebool, optional

Whether the post-measurement state (frame) should be returned. Currently unsupported.

checkbool, optional

Whether to perform internal self-consistency checks (for debugging, makes function run more slowly).

Returns

float

pygsti.evotypes.stabilizer_slow.stabilizer.sframe_kronecker(sframe_factors)

Computes a tensor-product StabilizerFrame from a set of factors.

Parameters

sframe_factorslist of StabilizerFrame objects

The factors to tensor together in the given left-to-right order.

Returns

StabilizerFrame