<filename>instance_gen/count_satisfiable.py
import subprocess
import time
import numpy as np


def get_instances():
    """returns array of instance names, array of corresponding n"""
    instance_data = np.genfromtxt('m2s_nqubits.csv', delimiter=',', skip_header=1, dtype=str)    # path of csv file
    return instance_data[:, 0], instance_data[:, 1]


def get_2sat_formula(instance_name):
    out = np.loadtxt("./../../instances_original/" + instance_name + ".m2s")  # path of instance files in adam's format
    return out.astype(int)


if __name__ == '__main__':
    instance_names, instance_n_bits_str = get_instances()
    runtimes = np.zeros(10000)

    n = 5
    n_shifted = n-5                     # n_shifted runs from 0 to 15 instead of 5 to 20

    num_satisfiable = 0

    for loop, i in enumerate(range(n_shifted*10000, (n_shifted+1)*10000)):             # 10000 instances per value of n
        instance_name = instance_names[i]
        sat_formula = get_2sat_formula(instance_name)
        unsatisfied = 0
        for clause in sat_formula:
            if clause[0] == -1 and clause [2] == -1:
                unsatisfied +=1
        if unsatisfied == 0:
            num_satisfiable += 1
        if loop % 100 == 0:
            print(loop/10000 * 100, r'% done')
        
    print('The number of satisfiable instances for n={} is {}.'.format(n, num_satisfiable))
        
<filename>instance_gen/count_satisfiable.py
import subprocess
import time
import numpy as np


def get_instances():
    """returns array of instance names, array of corresponding n"""
    instance_data = np.genfromtxt('m2s_nqubits.csv', delimiter=',', skip_header=1, dtype=str)    # path of csv file
    return instance_data[:, 0], instance_data[:, 1]


def get_2sat_formula(instance_name):
    out = np.loadtxt("./../../instances_original/" + instance_name + ".m2s")  # path of instance files in adam's format
    return out.astype(int)


if __name__ == '__main__':
    instance_names, instance_n_bits_str = get_instances()
    runtimes = np.zeros(10000)

    n = 5
    n_shifted = n-5                     # n_shifted runs from 0 to 15 instead of 5 to 20

    num_satisfiable = 0

    for loop, i in enumerate(range(n_shifted*10000, (n_shifted+1)*10000)):             # 10000 instances per value of n
        instance_name = instance_names[i]
        sat_formula = get_2sat_formula(instance_name)
        unsatisfied = 0
        for clause in sat_formula:
            if clause[0] == -1 and clause [2] == -1:
                unsatisfied +=1
        if unsatisfied == 0:
            num_satisfiable += 1
        if loop % 100 == 0:
            print(loop/10000 * 100, r'% done')
        
    print('The number of satisfiable instances for n={} is {}.'.format(n, num_satisfiable))
        
returns array of instance names, array of corresponding n # path of csv file # path of instance files in adam's format # n_shifted runs from 0 to 15 instead of 5 to 20 # 10000 instances per value of n