cirq.sim.ActOnStateVectorArgs

State and context for an operation acting on a state vector.

There are three common ways to act on this object:

  1. Directly edit the target_tensor property, which is storing the state vector of the quantum system as a numpy array with one axis per qudit.
  2. Overwrite the available_buffer property with the new state vector, and then pass available_buffer into swap_target_tensor_for.
  3. Call record_measurement_result(key, val) to log a measurement result.

Methods

record_measurement_result

View source

Adds a measurement result to the log.

Args
key The key the measurement result should be logged under. Note that operations should only store results under keys they have declared in a _measurement_keys_ method.
value The value to log for the measurement.

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.

When operating on qudits instead of qubits, the same basic logic applies but in a different basis. For example, if the target axes have dimension [a:2, b:3, c:2] then the integer 10 decomposes into [a=0, b=2, c=1] via 7 = 1(32) + 2*(2) + 0.

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.

When operating on qudits instead of qubits, the same basic logic applies but in a different basis. For example, if the target axes have dimension [a:2, b:3, c:2] then the integer 10 decomposes into [a=1, b=2, c=0] via 7 = 1(32) + 2*(2) + 0.

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

swap_target_tensor_for

View source

Gives a new state vector for the system.

Typically, the new state vector should be args.available_buffer where args is this cirq.ActOnStateVectorArgs instance.

Args
new_target_tensor The new system state. Must have the same shape and dtype as the old system state.