1 from .encoder_base
import EncoderBase
5 This cyclic encoder is the simplest (and currently the only used) encoding scheme to ensure 6 equal Hamming distances between items separated by n indices. Not very efficient in use of qubits, 7 but simple enough to implement. 11 assert(num_nouns%2 == 0)
12 assert(num_verbs%2 == 0)
22 num_shifts = num_items//2
24 for i
in range(1, num_shifts+1):
25 vals[i] = vals[i-1] + (0b1 << (i-1))
26 for i
in range(1, num_shifts):
27 vals[i + num_shifts ] = vals[i + num_shifts -1] - (0b1 << (i-1))
28 val_dict = { k:v
for (k,v)
in zip(range(len(vals)), vals)}
38 raise Exception(
"Unknown data set: {}".format(data))
40 if val_offset
not in enc_mapping:
41 raise(ValueError(
"Encoding index value not within expected range. Value={}".format(val_offset)))
42 return enc_mapping[val_offset]
51 raise Exception(
"Unknown data set: {}".format(data))
52 if val_offset
not in self.dec_mapping:
53 raise(ValueError(
"Decoding index value not within expected range. Value={}".format(val_offset)))
54 return dec_mapping[val_offset]
def _gen_encoding_vals(self, num_items)
def decode(self, bin_val, data)
def __init__(self, num_nouns, num_verbs)
def encode(self, bin_val, data)