Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add probabilities to MeasurementOutcomes #1066

Merged
merged 44 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
05340f5
added probabilities to measurementoutcomes
BrunoLiegiBastonLiegi Oct 27, 2023
5b470b6
improved coverage
BrunoLiegiBastonLiegi Oct 30, 2023
0134e65
updated docs
BrunoLiegiBastonLiegi Oct 30, 2023
fa43f2e
improved docstrings
BrunoLiegiBastonLiegi Oct 30, 2023
6a2343d
added qubits par to probabilities
BrunoLiegiBastonLiegi Oct 31, 2023
a470a43
Merge branch 'master' into circuit_output
renatomello Oct 31, 2023
3145127
Merge branch 'master' into circuit_output
renatomello Nov 1, 2023
1fb5307
Merge branch 'master' into circuit_output
renatomello Nov 2, 2023
c07894d
Update tests/test_result.py
BrunoLiegiBastonLiegi Nov 6, 2023
130bedd
Update tests/test_result.py
BrunoLiegiBastonLiegi Nov 6, 2023
e4b0355
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 6, 2023
7160505
Update tests/test_result.py
BrunoLiegiBastonLiegi Nov 6, 2023
ec77f11
Update src/qibo/result.py
BrunoLiegiBastonLiegi Nov 6, 2023
b10a8b0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 6, 2023
614fce3
Update tests/test_result.py
BrunoLiegiBastonLiegi Nov 6, 2023
131b33f
Update tests/test_result.py
BrunoLiegiBastonLiegi Nov 6, 2023
2f774e7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 6, 2023
2f8e1d2
added probs_from_freq calculation to backend
BrunoLiegiBastonLiegi Nov 6, 2023
839a2af
fixed tests by 'hand'
BrunoLiegiBastonLiegi Nov 6, 2023
c7b7fcf
improved coverage
BrunoLiegiBastonLiegi Nov 7, 2023
cf88599
removed cmaes files
BrunoLiegiBastonLiegi Nov 7, 2023
ec45720
removed calculate_probs_from_freq from backends
BrunoLiegiBastonLiegi Nov 10, 2023
7ac8674
reintegrated some tests
BrunoLiegiBastonLiegi Nov 10, 2023
899f8a8
bugfix
BrunoLiegiBastonLiegi Nov 13, 2023
0e600d7
docstring improvement
renatomello Nov 13, 2023
d5a638c
typing
renatomello Nov 13, 2023
56fa3c6
docstring
renatomello Nov 13, 2023
a472565
typing
renatomello Nov 13, 2023
7f3b6a6
docstring
renatomello Nov 13, 2023
6db83f9
identation
renatomello Nov 13, 2023
f4fff00
typing
renatomello Nov 13, 2023
d0838ff
completing docstrings
BrunoLiegiBastonLiegi Nov 14, 2023
f1c1428
docstring to circuit result
BrunoLiegiBastonLiegi Nov 14, 2023
1f1fefc
Update src/qibo/result.py
BrunoLiegiBastonLiegi Nov 14, 2023
80cc68c
Update src/qibo/result.py
BrunoLiegiBastonLiegi Nov 14, 2023
329b097
Update src/qibo/result.py
BrunoLiegiBastonLiegi Nov 14, 2023
9927974
Update src/qibo/result.py
BrunoLiegiBastonLiegi Nov 14, 2023
aab93aa
Update src/qibo/result.py
BrunoLiegiBastonLiegi Nov 14, 2023
989b9b2
Update src/qibo/result.py
BrunoLiegiBastonLiegi Nov 14, 2023
8d0f339
Update src/qibo/result.py
BrunoLiegiBastonLiegi Nov 14, 2023
aa1f9c2
Update src/qibo/result.py
BrunoLiegiBastonLiegi Nov 14, 2023
b2c8c28
Update src/qibo/result.py
BrunoLiegiBastonLiegi Nov 14, 2023
182955f
added args to docstring
BrunoLiegiBastonLiegi Nov 14, 2023
60f4253
Merge branch 'master' into circuit_output
renatomello Nov 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions doc/source/api-reference/qibo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1133,10 +1133,11 @@ Therefore, one of the three objects :class:`qibo.result.QuantumState`,
is going to be returned by the circuit execution. The first gives acces to the final
state and probabilities via the :meth:`qibo.result.QuantumState.state` and
:meth:`qibo.result.QuantumState.probabilities` methods, whereas the second
allows to retrieve the final samples and frequencies with the
:meth:`qibo.result.MeasurementOutcomes.samples` and
:meth:`qibo.result.MeasurementOutcomes.frequencies` methods. The
third includes all the above instead.
allows to retrieve the final samples, the frequencies and the probabilities (calculated
as ``frequencies/nshots``) with the :meth:`qibo.result.MeasurementOutcomes.samples`,
:meth:`qibo.result.MeasurementOutcomes.frequencies` and
:meth:`qibo.result.MeasurementOutcomes.probabilities` methods respectively. The
:class:`qibo.result.CircuitResult` object includes all the above instead.

Every time some measurement is performed at the end of the execution, the result
will be a ``CircuitResult`` unless the final state could not be represented with the
Expand Down
18 changes: 10 additions & 8 deletions src/qibo/backends/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,21 +426,21 @@ def execute_circuit(self, circuit, initial_state=None, nshots=1000):
# execute_circuit_repeated would have been called
if circuit.measurements:
circuit._final_state = CircuitResult(
state, circuit.measurements, self, nshots=nshots
state, circuit.measurements, backend=self, nshots=nshots
)
return circuit._final_state
else:
circuit._final_state = QuantumState(state, self)
circuit._final_state = QuantumState(state, backend=self)
return circuit._final_state

else:
if circuit.measurements:
circuit._final_state = CircuitResult(
state, circuit.measurements, self, nshots=nshots
state, circuit.measurements, backend=self, nshots=nshots
)
return circuit._final_state
else:
circuit._final_state = QuantumState(state, self)
circuit._final_state = QuantumState(state, backend=self)
return circuit._final_state

except self.oom_error:
Expand Down Expand Up @@ -516,7 +516,9 @@ def execute_circuit_repeated(self, circuit, nshots, initial_state=None):
if circuit.density_matrix:
final_states.append(state)
if circuit.measurements:
result = CircuitResult(state, circuit.measurements, self, nshots=1)
result = CircuitResult(
state, circuit.measurements, backend=self, nshots=1
)
sample = result.samples()[0]
results.append(sample)
if not circuit.density_matrix:
Expand All @@ -532,18 +534,18 @@ def execute_circuit_repeated(self, circuit, nshots, initial_state=None):
final_result = CircuitResult(
final_state,
circuit.measurements,
self,
backend=self,
samples=self.aggregate_shots(results),
nshots=nshots,
)
else:
final_result = QuantumState(final_state, self)
final_result = QuantumState(final_state, backend=self)
circuit._final_state = final_result
return final_result
else:
final_result = MeasurementOutcomes(
circuit.measurements,
self,
backend=self,
samples=self.aggregate_shots(results),
nshots=nshots,
)
Expand Down
Loading