cirq.DensityMatrixStepResult

A single step in the simulation of the DensityMatrixSimulator.

Inherits From: StepResultBase, StepResult

sim_state The qubit:SimulationState lookup for this step.
dtype The numpy.dtype used by the simulation. One of numpy.complex64 or numpy.complex128.

measurements A dictionary from measurement gate key to measurement results, ordered by the qubits that the measurement operates on.

Methods

density_matrix

View source

Returns the density matrix at this step in the simulation.

The density matrix that is stored in this result is returned in the computational basis with these basis states defined by the qubit_map. In particular the value in the qubit_map is the index of the qubit, and these are translated into binary vectors where the last qubit is the 1s bit of the index, the second-to-last is the 2s bit of the index, and so forth (i.e. big endian ordering). The density matrix is a 2 ** num_qubits square matrix, with rows and columns ordered by the computational basis as just described.

Example
qubit_map {QubitA: 0, QubitB: 1, QubitC: 2} Then the returned density matrix will have (row and column) indices mapped to qubit basis states like the following table

| | QubitA | QubitB | QubitC | | :-: | :----: | :----: | :----: | | 0 | 0 | 0 | 0 | | 1 | 0 | 0 | 1 | | 2 | 0 | 1 | 0 | | 3 | 0 | 1 | 1 | | 4 | 1 | 0 | 0 | | 5 | 1 | 0 | 1 | | 6 | 1 | 1 | 0 | | 7 | 1 | 1 | 1 |

Args
copy If True, then the returned state is a copy of the density matrix. If False, then the density matrix is not copied, potentially saving memory. If one only needs to read derived parameters from the density matrix and store then using False can speed up simulation by eliminating a memory copy.

sample

View source

Samples from the system at this point in the computation.

Note that this does not collapse the state vector.

Args
qubits The qubits to be sampled in an order that influence the returned measurement results.
repetitions The number of samples to take.
seed A seed for the pseudorandom number generator.

Returns
Measurement results with True corresponding to the |1⟩ state. The outer list is for repetitions, and the inner corresponds to measurements ordered by the supplied qubits. These lists are wrapped as a numpy ndarray.

sample_measurement_ops

View source

Samples from the system at this point in the computation.

Note that this does not collapse the state vector.

In contrast to sample which samples qubits, this takes a list of cirq.GateOperation instances whose gates are cirq.MeasurementGate instances and then returns a mapping from the key in the measurement gate to the resulting bit strings. Different measurement operations must not act on the same qubits.

Args
measurement_ops GateOperation instances whose gates are MeasurementGate instances to be sampled form.
repetitions The number of samples to take.
seed A seed for the pseudorandom number generator.
_allow_repeated If True, adds extra dimension to the result, corresponding to the number of times a key is repeated.

Returns: A dictionary from measurement gate key to measurement results. Measurement results are stored in a 2-dimensional numpy array, the first dimension corresponding to the repetition and the second to the actual boolean measurement results (ordered by the qubits being measured.)

Raises
ValueError If the operation's gates are not MeasurementGate instances or a qubit is acted upon multiple times by different operations from measurement_ops.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]