import os
import sys
this_dir = os.path.dirname(os.path.abspath(__file__))
base_dir = os.path.join(this_dir, '..', '..')
sys.path.append(base_dir)



import spar_python.common.distributions.base_distributions \
    as base_distributions
import spar_python.common.spar_random as spar_random
import spar_python.common.enum as enum
import time
import unittest

VARS = enum.Enum('AHA', 'BAR', 'BAT', 'BAZ', 'FOO', 'WOM')


class IndependentDistributionTest(unittest.TestCase):
    def setUp(self):

        self.seed = int(time.time())
        self.seed_msg = "Random seed used for this test: %s" % self.seed
        self.longMessage = True
        spar_random.seed(self.seed)

        self.simple = base_distributions.SimpleIndependentDistribution
        self.compact = base_distributions.CompactIndependentDistribution
        self.compact_dist = base_distributions.CompactIndependentDistribution()
        self.simple_dist = base_distributions.SimpleIndependentDistribution()
sys.path.append(base_dir)

import unittest
import time
import spar_python.common.distributions.distribution_holder as dh
import spar_python.query_generation.learn_query_types as lqt
import spar_python.query_generation.query_handler as qh
import spar_python.common.enum as enum
import spar_python.common.spar_random as spar_random 
import spar_python.common.distributions.base_distributions \
    as base_distribution
import spar_python.query_generation.query_schema as qs
import StringIO
import logging

VARS = enum.Enum('FIRST_NAME')

class LearnQueryTypesTest(unittest.TestCase):
    
    def setUp(self):
        
        self.seed = int(time.time())
        self.seed_msg = "Random seed used for this test: %s" % self.seed
        self.longMessage = True
        spar_random.seed(self.seed)
        self.dummy_logger = logging.getLogger('dummy')
        
        #distribution holder
        dist1 = base_distribution.CompactIndependentDistribution()
        dist1.add('hello', 1)
        dist1.add('there', 99)
示例#3
0
import spar_python.circuit_generation.circuit_common.circuit_input as ci
import spar_python.circuit_generation.ibm.ibm_wire as iw
import spar_python.circuit_generation.ibm.ibm_gate as ig
import spar_python.circuit_generation.ibm.ibm_gate_mul as igm
import spar_python.circuit_generation.ibm.ibm_gate_mul_const as igmc
import spar_python.circuit_generation.ibm.ibm_gate_add as iga
import spar_python.circuit_generation.ibm.ibm_gate_add_const as igac
import spar_python.circuit_generation.ibm.ibm_gate_rotate as igr
import spar_python.circuit_generation.ibm.ibm_gate_select as igs
import spar_python.circuit_generation.ibm.ibm_circuit as ic
import spar_python.common.spar_random as sr
import spar_python.common.enum as enum

gate_types = ['LADD', 'LADDconst', 'LMUL', 'LMULconst', 'LSELECT', 'LROTATE']
# An Enum of gate types:
GATE_TYPES = enum.Enum(*gate_types)
# An Enum of possible gate type distributions used in the tests
# (identical to GATE_TYPES, but include RANDOM as well):
test_types = gate_types + ['RANDOM']
TEST_TYPES = enum.Enum(*test_types)
# Note that much of the following code relies on the fact that GATE_TYPES and
# TEST_TYPES coincide in the first 6 elements.

# This file contains methods for creating random gates and circuits.

# Below are methods for creating random gates of each type,
# wherein the method takes in the last level of gates (ultimate_level),
# the second-to-last level of gates (penultimate_level),
# a gate name, and a circuit for which the gate is intended.
# Inputs are chosen so that at least one of them comes from ultimate_level;
# any constants are chosen uniformly at random.
示例#4
0
import unittest
import time
import spar_python.common.enum as enum
import equality_query_generator as eqg
import spar_python.common.spar_random as spar_random
import spar_python.common.distributions.base_distributions \
    as base_distribution
import spar_python.query_generation.query_schema as qs
import spar_python.data_generation.spar_variables as sv
import spar_python.data_generation.learning.mock_data_files as mock_data_files
import StringIO as stringio
import spar_python.data_generation.learn_distributions as learn_distributions
import logging
import spar_python.query_generation.query_ids as qids

VARS = enum.Enum('dist1')


class EqualityQueryGeneratorTest(unittest.TestCase):
    def setUp(self):
        self.seed = int(time.time())
        self.seed_msg = "Random seed used for this test: %s" % self.seed
        self.longMessage = True
        spar_random.seed(self.seed)

        #set up intitialization values
        class Object(object):
            pass

        self.learner_options = Object()
        self.dummy_logger = logging.getLogger('dummy')
示例#5
0
#  ----          ----           ------------
#  Earlier       NH             Original Version
#  16 May 2013   SY
#  6 June 2013   MZ             Schema update
#  3 Aug 2013    SY             Another schema update
# *****************************************************************

# SPAR imports:
import spar_python.common.enum as enum
from spar_python.report_generation.common.results_schema import *

DBF_ALIAS1 = "dbf1"
DBF_ALIAS2 = "dbf2"

# field types in the results database:
FIELD_TYPES = enum.Enum("TEXT", "INTEGER", "REAL", "BOOL")
# field types in the test database:
TEST_FIELD_TYPES = enum.Enum("integer", "string", "enum", "date")

CATEGORIES = enum.Enum(
    "EQ", "P1", "P2", "P3", "P4", "P6", "P7", "P8", "P9", "P11")

MODS_CATEGORIES = enum.Enum("insert", "delete", "update")

ATOMIC_CATEGORIES = [CATEGORIES.EQ,
                     CATEGORIES.P2,
                     CATEGORIES.P3,
                     CATEGORIES.P4,
                     CATEGORIES.P6,
                     CATEGORIES.P7,
                     CATEGORIES.P11]
示例#6
0
#  Description:        Constants for query generation.
# *****************************************************************

import os
import sys
this_dir = os.path.dirname(os.path.abspath(__file__))
base_dir = os.path.join(this_dir, '..', '..')
sys.path.append(base_dir)
import spar_python.common.enum as enum

CAT = enum.Enum(
    'EQ', 'EQ_FISHING_INT', 'EQ_FISHING_STR', 'P1_EQ_AND', 'P1_EQ_OR',
    'P1_EQ_DNF', 'P1_EQ_CNF', 'P1_EQ_DEEP', 'P1_EQ_NOT', 'P1_OTHER_AND',
    'P1_OTHER_OR', 'P2_RANGE', 'P2_RANGE_FOO', 'P2_LESS', 'P2_GREATER',
    'P2_GREATER_FOO', 'P3', 'P4', 'P6_INITIAL_ONE', 'P6_MIDDLE_ONE',
    'P6_FINAL_ONE', 'P7_INITIAL', 'P7_BOTH', 'P7_FINAL', 'P7_OTHER_1',
    'P7_OTHER_2', 'P7_OTHER_3', 'P7_OTHER_4', 'P7_OTHER_5', 'P7_OTHER_6',
    'P7_OTHER_7', 'P7_OTHER_8', 'P7_OTHER_9', 'P7_OTHER_10', 'P7_OTHER_11',
    'P7_OTHER_12', 'P7_OTHER_13', 'P7_OTHER_14', 'P7_OTHER_15', 'P7_OTHER_16',
    'P7_OTHER_17', 'P8_EQ', 'P8_OTHER', 'P9_EQ', 'P9_ALARM_WORDS', 'P9_OTHER',
    'P11_SHORT', 'P11_FULL')

FIELD_TYPES = enum.Enum("TEXT", "INTEGER", "REAL", "BOOL", "LIST", "MANY")

### Common Fields ###
QRY_ENUM = 'enum'
QRY_CAT = "category"
QRY_SUBCAT = "sub_category"
QRY_PERF = 'perf'
QRY_DBNUMRECORDS = "db_num_records"
QRY_DBRECORDSIZE = "db_record_size"
示例#7
0
# SPAR imports:
import spar_python.common.enum as enum

NULL_VALUES = ["NULL", None, "None", ""] # for checking whether a cell is populated
DB_NULL_VALUE = "NULL"
PY_NULL_VALUE = ""
TRUE_VALUES = ["True", "TRUE", "1", 1]
FALSE_VALUES = ["False", "FALSE", "0", 0]
DB_TRUE_VALUE = 1
DB_FALSE_VALUE = 0
PY_TRUE_VALUE = True
PY_FALSE_VALUE = False
DELIMITER = "|"

# field types in the results database:
FIELD_TYPES = enum.Enum("TEXT", "INTEGER", "REAL", "BOOL")

class ResultsSchema(object):

    def __init__(self):
        self.list_fields = dict()
        self.tablename_to_fieldtotype = None
        self.tablename_to_requiredfields = None
        self.tablename_to_aux = None
        self.tablename_to_joins = None
        self.performer_tablenamess = None
        self.other_tablenames_heirarchy = None
        
    def process_to_database_if_list(self, tablename, fieldname, value):
        """
        Args:
示例#8
0
import spar_python.circuit_generation.stealth.stealth_wire as sw
import spar_python.circuit_generation.stealth.stealth_gate_and as sga
import spar_python.circuit_generation.stealth.stealth_gate_or as sgo
import spar_python.circuit_generation.stealth.stealth_gate_xor as sgx
import spar_python.circuit_generation.stealth.stealth_circuit as sc
import spar_python.circuit_generation.circuit_common.circuit_input as si
import spar_python.common.spar_random as sr
import spar_python.common.enum as enum

import itertools
import functools

gate_types = ['AND', 'OR', 'XOR']
# An Enum of gate types:
GATE_TYPES = enum.Enum(*gate_types)
# An Enum of possible gate type distributions used in the tests
# (identical to GATE_TYPES, but include RANDOM as well):
test_types = gate_types + ['RANDOM']
TEST_TYPES = enum.Enum(*test_types)
# Note that much of the following code relies on the fact that GATE_TYPES and
# TEST_TYPES coincide in the first 6 elements.

LEVEL_TYPES = enum.Enum("RANDOM", "XOR")

# This file contains methods for creating random gates and circuits.

# Below are methods for creating random and, or, and xor gates, wherein the
# inputs are chosen from the last level of gates available.
# There is also a method for creating a gate where the gate type is chosen
# uniformly at random.