cirq.protocols.ApplyUnitaryArgs

Arguments for performing an efficient left-multiplication by a unitary.

The receiving object is expected to mutate target_tensor so that it contains the state after multiplication, and then return target_tensor. Alternatively, if workspace is required, the receiving object can overwrite available_buffer with the results and return available_buffer. Or, if the receiving object is attempting to be simple instead of fast, it can create an entirely new array and return that.

target_tensor The input tensor that needs to be left-multiplied by the unitary effect of the receiving object. The tensor will have the shape (2, 2, 2, ..., 2). It usually corresponds to a multi-qubit superposition, but it could also be a multi-qubit unitary transformation or some other concept.
available_buffer Pre-allocated workspace with the same shape and dtype as the target tensor.
axes Which axes the unitary effect is being applied to (e.g. the qubits that the gate is operating on).

Methods

default

View source

A default instance starting in state |0⟩.

Specify exactly one argument.

Args
num_qubits The number of qubits to make space for in the state.
qid_shape The shape of the state, specifying the dimension of each qid.

subspace_index

View source

An index for the subspace where the target axes equal a value.

Args
little_endian_bits_int The desired value of the qubits at the targeted axes, packed into an integer. The least significant bit of the integer is the desired bit for the first axis, and so forth in increasing order. Can't be specified at the same time as big_endian_bits_int.
big_endian_bits_int The desired value of the qubits at the targeted axes, packed into an integer. The most significant bit of the integer is the desired bit for the first axis, and so forth in decreasing order. Can't be specified at the same time as little_endian_bits_int.

Returns
A value that can be used to index into target_tensor and available_buffer, and manipulate only the part of Hilbert space corresponding to a given bit assignment.

Example:

If target_tensor is a 4 qubit tensor and axes is [1, 3] and then this method will return the following when given little_endian_bits=0b01:

`(slice(None), 0, slice(None), 1, Ellipsis)`

Therefore the following two lines would be equivalent:

args.target_tensor[args.subspace_index(0b01)] += 1

args.target_tensor[:, 0, :, 1] += 1

with_axes_transposed_to_start

View source

Returns a transposed view of the same arguments.

Returns
A view over the same target tensor and available workspace, but with the numpy arrays transposed such that the axes field is guaranteed to equal range(len(result.axes)). This allows one to say e.g. result.target_tensor[0, 1, 0, ...] instead of result.target_tensor[result.subspace_index(0b010)].