Skip to content

Commit

Permalink
changed the behavior of the simular: given shots = None now returns t…
Browse files Browse the repository at this point in the history
…he distribution in the form of floats (instead of integers scaled with some number)
  • Loading branch information
positr0nium committed Mar 2, 2025
1 parent fe30b71 commit 3ee5074
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/qrisp/jasp/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def testing_function(*args):

# new_key = int(new_key, base=2)
try:
new_counts_dic[new_key] += counts[key]/100000
new_counts_dic[new_key] += counts[key]
except KeyError:
new_counts_dic[new_key] = counts[key]/100000
new_counts_dic[new_key] = counts[key]

for k in old_counts_dic.keys():
if abs(old_counts_dic[k] - new_counts_dic[k]) > 1E-4:
Expand Down
6 changes: 3 additions & 3 deletions src/qrisp/misc/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,10 +1331,10 @@ def get_measurement_from_qc(qc, qubits, backend, shots=None):
counts = new_counts_dic

# Plot result (if needed)

if shots is not None:
# Normalize counts
for key in counts.keys():
counts[key] = counts[key] / abs(no_of_shots_executed)
for key in counts.keys():
counts[key] = counts[key] / abs(no_of_shots_executed)

return counts

Expand Down
9 changes: 3 additions & 6 deletions src/qrisp/simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,23 @@ def run(qc, shots, token="", iqs=None, insert_reset=True):
# The iqs object contains the outcome bitstrings in the attribute .outcome_list
# and the probablities in .cl_prob. In order to ensure qiskit compatibility, we
# reverse the bitstrings

cl_prob = np.round(cl_prob, 5)
norm = np.sum(cl_prob)
cl_prob = cl_prob/norm

res = {}
#If shots >= 1000000, no samples will be drawn and the distribution will
#be returned instead
if shots is None:
shots = 100000

for j in range(len(outcome_list)):

outcome_str = bin(outcome_list[j])[2:].zfill(len(mes_list))

shot_val = int(np.round(cl_prob[j]*abs(shots)))

try:
res[outcome_str] += shot_val
res[outcome_str] += cl_prob[j]
except KeyError:
res[outcome_str] = shot_val
res[outcome_str] = cl_prob[j]

#Generate samples
else:
Expand Down
14 changes: 7 additions & 7 deletions tests/test_uncomputation_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ def sqrt_oracle(qf):
print(qf)

assert qf.get_measurement() == {0.5: 0.9453289065781315,
0.0: 0.007810156203124062,
1.0: 0.007810156203124062,
1.5: 0.007810156203124062,
2.0: 0.007810156203124062,
2.5: 0.007810156203124062,
3.0: 0.007810156203124062,
3.5: 0.007810156203124062}
0.0: 0.007810156203124063,
1.0: 0.007810156203124063,
1.5: 0.007810156203124063,
2.0: 0.007810156203124063,
2.5: 0.007810156203124063,
3.0: 0.007810156203124063,
3.5: 0.007810156203124063}


# ---------
Expand Down

0 comments on commit 3ee5074

Please sign in to comment.