def calc_parity(state):
    """
    Takes in a state and returns its parity (even = 0 , odd = 1)

    :param state:
    :type state: str

    :return: parity of state
    :rtype: int
    """
    bit_sum = 0
    for bit in state:
        if int(bit) not in [0,1]:
            raise ValueError('state {} not allowed'.format(state))
        bit_sum += int(bit)
    parity = bit_sum % 2
    return parity