![]() |
State and context for an operation acting on a state vector.
Inherits From: ActOnArgs
, OperationTarget
cirq.ActOnStateVectorArgs(
target_tensor: Optional[np.ndarray] = None,
available_buffer: Optional[np.ndarray] = None,
prng: Optional[np.random.RandomState] = None,
log_of_measurement_results: Optional[Dict[str, List[int]]] = None,
qubits: Optional[Sequence['cirq.Qid']] = None,
initial_state: Union[np.ndarray, 'cirq.STATE_VECTOR_LIKE'] = 0,
dtype: Type[np.number] = np.complex64,
classical_data: Optional['cirq.ClassicalDataStore'] = None
)
There are two common ways to act on this object:
- 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. - Overwrite the
available_buffer
property with the new state vector, and then passavailable_buffer
intoswap_target_tensor_for
.
Methods
apply_operation
apply_operation(
op: 'cirq.Operation'
)
copy
copy(
deep_copy_buffers: bool = True
) -> TSelf
Creates a copy of the object.
Args | |
---|---|
deep_copy_buffers
|
If True, buffers will also be deep-copied. Otherwise the copy will share a reference to the original object's buffers. |
Returns | |
---|---|
A copied instance. |
create_merged_state
create_merged_state() -> TSelf
Creates a final merged state.
factor
factor(
qubits: Sequence['cirq.Qid'], *, validate=True, atol=1e-07, inplace=False
) -> Tuple[TSelf, TSelf]
Splits two state spaces after a measurement or reset.
get_axes
get_axes(
qubits: Sequence['cirq.Qid']
) -> List[int]
kronecker_product
kronecker_product(
other: TSelf, *, inplace=False
) -> TSelf
Joins two state spaces together.
measure
measure(
qubits: Sequence['cirq.Qid'], key: str, invert_mask: Sequence[bool]
)
Measures the qubits and records to log_of_measurement_results
.
Any bitmasks will be applied to the measurement record. If
self._ignore_measurement_results
is set, it dephases instead of
measuring, and no measurement result will be logged.
Args | |
---|---|
qubits
|
The qubits to measure. |
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_key_names_ method.
|
invert_mask
|
The invert mask for the measurement. |
Raises | |
---|---|
ValueError
|
If a measurement key has already been logged to a key. |
rename
rename(
q1: 'cirq.Qid', q2: 'cirq.Qid', *, inplace=False
)
Renames q1
to q2
.
Args | |
---|---|
q1
|
The qubit to rename. |
q2
|
The new name. |
inplace
|
True to rename the qubit in the current object, False to create a copy with the qubit renamed. |
Returns | |
---|---|
The original object with the qubits renamed if inplace is requested, or a copy of the original object with the qubits renamed otherwise. |
Raises | |
---|---|
ValueError
|
If the qubits are of different dimensionality. |
sample
sample(
qubits: Sequence['cirq.Qid'],
repetitions: int = 1,
seed: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None
) -> np.ndarray
Samples the state value.
subspace_index
subspace_index(
axes: Sequence[int],
little_endian_bits_int: int = 0,
*,
big_endian_bits_int: int = 0
) -> Tuple[Union[slice, int, 'ellipsis'], ...]
THIS FUNCTION IS DEPRECATED.
IT WILL BE REMOVED IN cirq v0.16
.
None, this function was unintentionally made public.
An index for the subspace where the target axes equal a value.
Args:
axes: The qubits that are specified by the index bits.
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*(3*2) + 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*(3*2) + 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
swap(
q1: 'cirq.Qid', q2: 'cirq.Qid', *, inplace=False
)
Swaps two qubits.
This only affects the index, and does not modify the underlying state.
Args | |
---|---|
q1
|
The first qubit to swap. |
q2
|
The second qubit to swap. |
inplace
|
True to swap the qubits in the current object, False to create a copy with the qubits swapped. |
Returns | |
---|---|
The original object with the qubits swapped if inplace is requested, or a copy of the original object with the qubits swapped otherwise. |
Raises | |
---|---|
ValueError
|
If the qubits are of different dimensionality. |
swap_target_tensor_for
swap_target_tensor_for(
new_target_tensor: np.ndarray
)
THIS FUNCTION IS DEPRECATED.
IT WILL BE REMOVED IN cirq v0.16
.
None, this function was unintentionally made public.
Gives a new state vector for the system.
Typically, the new state vector should be `args.available_buffer` where
`args` is this <a href="../cirq/ActOnStateVectorArgs"><code>cirq.ActOnStateVectorArgs</code></a> instance.
Args:
new_target_tensor: The new system state. Must have the same shape
and dtype as the old system state.
transpose_to_qubit_order
transpose_to_qubit_order(
qubits: Sequence['cirq.Qid'], *, inplace=False
) -> TSelf
Physically reindexes the state by the new basis.
Args | |
---|---|
qubits
|
The desired qubit order. |
inplace
|
True to perform this operation inplace. |
Returns | |
---|---|
The state with qubit order transposed and underlying representation updated. |
Raises | |
---|---|
ValueError
|
If the provided qubits do not match the existing ones. |
with_qubits
with_qubits(
qubits
) -> TSelf
Extend current state space with added qubits.
The state of the added qubits is the default value set in the subclasses. A new state space is created as the Kronecker product of the original one and the added one.
Args | |
---|---|
qubits
|
The qubits to be added to the state space. |
Regurns | |
---|---|
A new subclass object containing the extended state space. |
__getitem__
__getitem__(
item: Optional['cirq.Qid']
) -> TSelf
Gets the item associated with the qubit.
__iter__
__iter__() -> Iterator[Optional['cirq.Qid']]
Iterates the keys of the mapping.
__len__
__len__() -> int
Gets the number of items in the mapping.