Skip to content

Commit

Permalink
discard lower parameters in decode_counts, example_grover_3 notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
dakk committed Nov 27, 2023
1 parent d60c4ba commit bdbaf42
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 92 deletions.
167 changes: 167 additions & 0 deletions docs/source/example_grover_3.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Python and translate them into unitary operators (gates) for use in quantum circ

example_grover_1.ipynb
example_grover_2.ipynb
example_grover_3.ipynb


Indices and tables
Expand Down
86 changes: 0 additions & 86 deletions examples/grover_hash_collision2.py

This file was deleted.

6 changes: 2 additions & 4 deletions qlasskit/algorithms/qalgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ def oraclize(qf: QlassF, element: Any, name="oracle"):
if qf.name == name:
qf.name = f"_{name}"

oracle = QlassF.from_function(
f"def {name}(v: {argt_name}) -> bool:\n return {qf.name}(v) == {element}",
defs=[qf.to_logicfun()],
)
fs = f"def {name}(v: {argt_name}) -> bool:\n return {qf.name}(v) == {element}"
oracle = QlassF.from_function(fs, defs=[qf.to_logicfun()])

if (
len(oracle.expressions) == 1
Expand Down
8 changes: 6 additions & 2 deletions qlasskit/qcircuit/qcircuitwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, Dict, List
from typing import Any, Dict, List, Optional

from .qcircuit import QCircuit, SupportedFramework

Expand Down Expand Up @@ -63,7 +63,7 @@ def encode_input(self, *qvals):
def decode_output(self, istr):
raise Exception("Abstract")

def decode_counts(self, counts: Dict[str, int]) -> Dict[Any, int]:
def decode_counts(self, counts: Dict[str, int], discard_lower: Optional[int] = None) -> Dict[Any, int]:
"""Decode data from a circuit counts dict"""
outcomes = [(self.decode_output(e), c) for (e, c) in counts.items()]
int_counts: Dict[Any, int] = {}
Expand All @@ -72,6 +72,10 @@ def decode_counts(self, counts: Dict[str, int]) -> Dict[Any, int]:
int_counts[e] += c
else:
int_counts[e] = c

if discard_lower:
int_counts = dict(filter(lambda el: el[1] >= discard_lower, int_counts.items()))

return int_counts

def circuit(self):
Expand Down

0 comments on commit bdbaf42

Please sign in to comment.