Skip to content

Reed Solomon

LetteraUnica edited this page Jun 4, 2021 · 2 revisions

Explanation of the Reed-Solomon Functions

All the functions that implement the Reed Solomon code are designed so that everything is a function of the length of the sent message. In order to use the encoder you will need a way to initialize a state of your chosen number of Qbtis, you can do this either through a file states.txt or directly, by declaring a list of coefficients, for example:

initial_state = [ [1,0],[1,0],[0,1]]

Will initialize the state |0>|0>|1>. Please note that in order to run simulations, you'll need a IBM-q account togheter with a token. The encoding of the state is done by the function:

def encoder(initial_state):
    """Takes a message and return the circuit that encodes it.
    Input: list of binary lists, as initial_state = [ [1,0],[1,0],[0,1]]
    Returns: encoding circuit
    """

which by default returns the encoding circuit. The decoding happens inside the function:

def decoder(qc):
    """Takes the encoding circuit, computes the syndrome and corrects the message.
    Input: quantum circuit after encoding
    Returns: decoding circuit, retrieved message, outcomes of measurements, syndrome.
    """

The simulation function used to retrieve the syndrome when calling get_syndrome(qc) or get_qbits(qc) is:

def simulate(qc):
    """Simulates the circuit using the cloud-computing services of IBMq, this is always the recommended choice to run simulations"""
    provider = IBMQ.get_provider(hub='ibm-q')
    backend=provider.get_backend('simulator_mps')
    result = execute(qc, backend,shots=shots).result()
    print('Simulation Success: {}'.format(result.success))
    print("Time taken: {} sec".format(result.time_taken))
    counts = result.get_counts(0)
    return counts

Usage

If you wish to encode using a file, place the file RS.py in the same directory as states.txt, or alternatively, simply declare the variable initial_state as before. After doing import RS, first run the function init_decoder() which will execute the initialization of every parameter of the code, you can then use any function of your choice in the file.

Clone this wiki locally