qiskit-documentation/docs/api/qiskit/0.31/qiskit.result.QuasiDistribu...

182 lines
6.0 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: QuasiDistribution (v0.31)
description: API reference for qiskit.result.QuasiDistribution in qiskit v0.31
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.result.QuasiDistribution
---
# QuasiDistribution
<Class id="qiskit.result.QuasiDistribution" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.18/qiskit/result/distributions/quasi.py" signature="QuasiDistribution(data, shots=None)" modifiers="class">
Bases: `dict`
A dict-like class for representing qasi-probabilities.
Builds a quasiprobability distribution object.
**Parameters**
* **data** (*dict*)
Input quasiprobability data. Where the keys represent a measured classical value and the value is a float for the quasiprobability of that result. The keys can be one of several formats:
> * A hexadecimal string of the form `"0x4a"`
> * A bit string e.g. `'0b1011'` or `"01011"`
> * An integer
* **shots** (*int*) Number of shots the distribution was derived from.
**Raises**
* **TypeError** If the input keys are not a string or int
* **ValueError** If the string format of the keys is incorrect
## Methods
<span id="qiskit-result-quasidistribution-binary-probabilities" />
### binary\_probabilities
<Function id="qiskit.result.QuasiDistribution.binary_probabilities" signature="QuasiDistribution.binary_probabilities(num_bits=None)">
Build a quasi-probabilities dictionary with binary string keys
**Parameters**
**num\_bits** (*int*) number of bits in the binary bitstrings (leading zeros will be padded). If None, the length will be derived from the largest key present.
**Returns**
**A dictionary where the keys are binary strings in the format**
`"0110"`
**Return type**
dict
</Function>
<span id="qiskit-result-quasidistribution-clear" />
### clear
<Function id="qiskit.result.QuasiDistribution.clear" signature="QuasiDistribution.clear() → None. Remove all items from D." />
<span id="qiskit-result-quasidistribution-copy" />
### copy
<Function id="qiskit.result.QuasiDistribution.copy" signature="QuasiDistribution.copy() → a shallow copy of D" />
<span id="qiskit-result-quasidistribution-fromkeys" />
### fromkeys
<Function id="qiskit.result.QuasiDistribution.fromkeys" signature="QuasiDistribution.fromkeys(value=None, /)">
Create a new dictionary with keys from iterable and values set to value.
</Function>
<span id="qiskit-result-quasidistribution-get" />
### get
<Function id="qiskit.result.QuasiDistribution.get" signature="QuasiDistribution.get(key, default=None, /)">
Return the value for key if key is in the dictionary, else default.
</Function>
<span id="qiskit-result-quasidistribution-hex-probabilities" />
### hex\_probabilities
<Function id="qiskit.result.QuasiDistribution.hex_probabilities" signature="QuasiDistribution.hex_probabilities()">
Build a quasi-probabilities dictionary with hexadecimal string keys
**Returns**
**A dictionary where the keys are hexadecimal strings in the**
format `"0x1a"`
**Return type**
dict
</Function>
<span id="qiskit-result-quasidistribution-items" />
### items
<Function id="qiskit.result.QuasiDistribution.items" signature="QuasiDistribution.items() → a set-like object providing a view on Ds items" />
<span id="qiskit-result-quasidistribution-keys" />
### keys
<Function id="qiskit.result.QuasiDistribution.keys" signature="QuasiDistribution.keys() → a set-like object providing a view on Ds keys" />
<span id="qiskit-result-quasidistribution-nearest-probability-distribution" />
### nearest\_probability\_distribution
<Function id="qiskit.result.QuasiDistribution.nearest_probability_distribution" signature="QuasiDistribution.nearest_probability_distribution(return_distance=False)">
Takes a quasiprobability distribution and maps it to the closest probability distribution as defined by the L2-norm.
**Parameters**
**return\_distance** (*bool*) Return the L2 distance between distributions.
**Returns**
Nearest probability distribution. float: Euclidean (L2) distance of distributions.
**Return type**
[ProbDistribution](qiskit.result.ProbDistribution "qiskit.result.ProbDistribution")
**Notes**
Method from Smolin et al., Phys. Rev. Lett. 108, 070502 (2012).
</Function>
<span id="qiskit-result-quasidistribution-pop" />
### pop
<Function id="qiskit.result.QuasiDistribution.pop" signature="QuasiDistribution.pop(k[, d]) → v, remove specified key and return the corresponding value.">
If key is not found, d is returned if given, otherwise KeyError is raised
</Function>
<span id="qiskit-result-quasidistribution-popitem" />
### popitem
<Function id="qiskit.result.QuasiDistribution.popitem" signature="QuasiDistribution.popitem() → (k, v), remove and return some (key, value) pair as a">
2-tuple; but raise KeyError if D is empty.
</Function>
<span id="qiskit-result-quasidistribution-setdefault" />
### setdefault
<Function id="qiskit.result.QuasiDistribution.setdefault" signature="QuasiDistribution.setdefault(key, default=None, /)">
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
</Function>
<span id="qiskit-result-quasidistribution-update" />
### update
<Function id="qiskit.result.QuasiDistribution.update" signature="QuasiDistribution.update([E, ]**F) → None. Update D from dict/iterable E and F.">
If E is present and has a .keys() method, then does: for k in E: D\[k] = E\[k] If E is present and lacks a .keys() method, then does: for k, v in E: D\[k] = v In either case, this is followed by: for k in F: D\[k] = F\[k]
</Function>
<span id="qiskit-result-quasidistribution-values" />
### values
<Function id="qiskit.result.QuasiDistribution.values" signature="QuasiDistribution.values() → an object providing a view on Ds values" />
</Class>