Skip to content

Commit

Permalink
fix redundency
Browse files Browse the repository at this point in the history
  • Loading branch information
toumix committed Apr 8, 2020
1 parent eccfc29 commit a21b492
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions discopy/tk_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,6 @@
from pytket.utils import probs_from_counts


def tensor_from_counts(counts, post_selection=None, scalar=1, normalize=True):
"""
Parameters
----------
counts : dict
From bitstrings to counts.
post_selection : dict, optional
From qubit indices to bits.
scalar : complex, optional
Scale the output using the Born rule.
normalize : bool, optional
Whether to normalize the counts.
Returns
-------
tensor : discopy.tensor.Tensor
Of dimension :code:`n_qubits * (2, )` for :code:`n_qubits` the number
of post-selected qubits.
"""
if normalize:
counts = probs_from_counts(counts)
n_qubits = len(list(counts.keys()).pop())
if post_selection:
post_selected = dict()
for bitstring, count in counts.items():
if all(bitstring[qubit] == bit
for qubit, bit in post_selection.items()):
post_selected.update({
tuple(bit for qubit, bit in enumerate(bitstring)
if qubit not in post_selection): count})
n_qubits -= len(post_selection.keys())
counts = post_selected
array = np.zeros(n_qubits * (2, ))
for bitstring, count in counts.items():
array += count * Ket(*bitstring).array
array = abs(scalar) ** 2 * array
return Tensor(Dim(1), Dim(*(n_qubits * (2, ))), array)


class TketCircuit(tk.Circuit):
"""
pytket.Circuit with post selection and scalars.
Expand Down

0 comments on commit a21b492

Please sign in to comment.