State and context for an operation acting on a density matrix.

Inherits From: ActOnArgs, OperationTarget

To act on this object, directly edit the target_tensor property, which is storing the density matrix of the quantum system with one axis per qubit.

target_tensor The state vector to act on, stored as a numpy array with one dimension for each qubit in the system. Operations are expected to perform inplace edits of this object.
available_buffer A workspace with the same shape and dtype as target_tensor. Used by operations that cannot be applied to target_tensor inline, in order to avoid unnecessary allocations.
qubits Determines the canonical ordering of the qubits. This is often used in specifying the initial state, i.e. the ordering of the computational basis states.
qid_shape The shape of the target tensor.
prng The pseudo random number generator to use for probabilistic effects.
log_of_measurement_results A mutable object that measurements are being recorded into.
ignore_measurement_results If True, then the simulation will treat measurement as dephasing instead of collapsing process. This is only applicable to simulators that can model dephasing.
initial_state The initial state for the simulation in the computational basis.
dtype The numpy.dtype of the inferred state vector. One of numpy.complex64 or numpy.complex128. Only used when target_tenson is None.
classical_data The shared classical data container for this simulation.

ValueError The dimension of target_tensor is not divisible by 2 and qid_shape is not provided.

allows_factoring Subclasses that allow factorization should override this.


classical_data The shared classical data container for this simulation..

log_of_measurement_results Gets the log of measurement results.



qubits Gets the qubit order maintained by this target.



View source


View source

Creates a copy of the object.

deep_copy_buffers If True, buffers will also be deep-copied. Otherwise the copy will share a reference to the original object's buffers.

A copied instance.


View source

Creates a final merged state.


View source

Splits two state spaces after a measurement or reset.


View source


View source

Joins two state spaces together.


View source

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.

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.

ValueError If a measurement key has already been logged to a key.


View source

Renames q1 to q2.

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.

The original object with the qubits renamed if inplace is requested, or a copy of the original object with the qubits renamed otherwise.

ValueError If the qubits are of different dimensionality.


View source

Samples the state value.


View source

Swaps two qubits.

This only affects the index, and does not modify the underlying state.

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.

The original object with the qubits swapped if inplace is requested, or a copy of the original object with the qubits swapped otherwise.

ValueError If the qubits are of different dimensionality.


View source

Physically reindexes the state by the new basis.

qubits The desired qubit order.
inplace True to perform this operation inplace.

The state with qubit order transposed and underlying representation updated.

ValueError If the provided qubits do not match the existing ones.


View source

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.

qubits The qubits to be added to the state space.


A new subclass object containing the extended state space.


View source

Gets the item associated with the qubit.


View source

Iterates the keys of the mapping.


View source

Gets the number of items in the mapping.