How to use the opentuner.resultsdb.models.Base function in opentuner

To help you get started, we’ve selected a few opentuner examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jansel / opentuner / opentuner / resultsdb / connect.py View on Github external
# if there are existing tables
    if not engine.dialect.has_table(connection, "_meta"):
      # if no version table, assume outdated db version and error
      connection.close()
      raise Exception("Your opentuner database is currently out of date. Save a back up and reinitialize")

  # else if we have the table already, make sure version matches
  if engine.dialect.has_table(connection, "_meta"):
    Session = scoped_session(sessionmaker(autocommit=False,
                                          autoflush=False,
                                          bind=engine))
    version = _Meta.get_version(Session)
    if not DB_VERSION == version:
      raise Exception('Your opentuner database version {} is out of date with the current version {}'.format(version, DB_VERSION))

  Base.metadata.create_all(engine)

  Session = scoped_session(sessionmaker(autocommit=False,
                                        autoflush=False,
                                        bind=engine))
  # mark database with current version
  _Meta.add_version(Session, DB_VERSION)
  Session.commit()

  return engine, Session
github jansel / opentuner / opentuner / resultsdb / models.py View on Github external
#state          = Column(Enum('ANY_MACHINE', 'SINGLE_MACHINE', 'DELETED'),
  #                        default='ANY_MACHINE', name='t_input_state')

  input_class_id = Column(ForeignKey(InputClass.id))
  input_class = relationship(InputClass, backref='inputs')

  #optional, set only for state='SINGLE_MACHINE'
  #machine_id     = Column(ForeignKey(MachineClass.id))
  #machine        = relationship(MachineClass, backref='inputs')

  #optional, for use by InputManager
  path = Column(Text)
  extra = Column(PickleType(pickler=CompressedPickler))


class TuningRun(Base):
  uuid = Column(String(32), index=True, unique=True)

  program_version_id = Column(ForeignKey(ProgramVersion.id))
  program_version = relationship(ProgramVersion, backref='tuning_runs')

  machine_class_id = Column(ForeignKey(MachineClass.id))
  machine_class = relationship(MachineClass, backref='tuning_runs')

  input_class_id = Column(ForeignKey(InputClass.id))
  input_class = relationship(InputClass, backref='tuning_runs')

  name = Column(String(128), default='unnamed')
  args = Column(PickleType(pickler=CompressedPickler))
  objective = Column(PickleType(pickler=CompressedPickler))

  state = Column(Enum('QUEUED', 'RUNNING', 'COMPLETE', 'ABORTED',
github jansel / opentuner / opentuner / resultsdb / models.py View on Github external
except:
      s = string
    return loads(s)

class Base(object):
  @declared_attr
  def __tablename__(cls):
    """convert camel case to underscores"""
    return re.sub(r'([a-z])([A-Z])', r'\1_\2', cls.__name__).lower()

  id = Column(Integer, primary_key=True, index=True)


Base = declarative_base(cls=Base)

class _Meta(Base):
  """ meta table to track current version """
  db_version = Column(String(128))

  @classmethod
  def has_version(cls, session, version):
    try:
      session.flush()
      session.query(_Meta).filter_by(db_version=version).one()
      return True
    except sqlalchemy.orm.exc.NoResultFound:
      return False

  @classmethod
  def get_version(cls, session):
    try:
      session.flush()
github jansel / opentuner / opentuner / resultsdb / models.py View on Github external
result = relationship(Result, backref='desired_results')
  start_date = Column(DateTime)

  #input_id        = Column(ForeignKey(Input.id))
  #input           = relationship(Input, backref='desired_results')


Index('ix_desired_result_custom1', DesiredResult.tuning_run_id,
      DesiredResult.generation)

Index('ix_desired_result_custom2', DesiredResult.tuning_run_id,
      DesiredResult.configuration_id)


# track bandit meta-technique information if a bandit meta-technique is used for a tuning run.
class BanditInfo(Base):
  tuning_run_id = Column(ForeignKey(TuningRun.id))
  tuning_run = relationship(TuningRun, backref='bandit_info')
  # the bandit exploration/exploitation tradeoff
  c = Column(Float)
  # the bandit window
  window = Column(Integer)

class BanditSubTechnique(Base):
  bandit_info_id = Column(ForeignKey(BanditInfo.id))
  bandit_info = relationship(BanditInfo, backref='subtechniques')
  name = Column(String(128))


if __name__ == '__main__':
  #test:
  engine = create_engine('sqlite:///:memory:', echo=True)
github jansel / opentuner / opentuner / resultsdb / models.py View on Github external
size = Column(Integer)

  @classmethod
  def get(cls, session, program, name='default', size=-1):
    try:
      session.flush()
      return session.query(InputClass).filter_by(program=program,
                                                 name=name,
                                                 size=size).one()
    except sqlalchemy.orm.exc.NoResultFound:
      t = InputClass(program=program, name=name, size=size)
      session.add(t)
      return t


class Input(Base):
  #state          = Column(Enum('ANY_MACHINE', 'SINGLE_MACHINE', 'DELETED'),
  #                        default='ANY_MACHINE', name='t_input_state')

  input_class_id = Column(ForeignKey(InputClass.id))
  input_class = relationship(InputClass, backref='inputs')

  #optional, set only for state='SINGLE_MACHINE'
  #machine_id     = Column(ForeignKey(MachineClass.id))
  #machine        = relationship(MachineClass, backref='inputs')

  #optional, for use by InputManager
  path = Column(Text)
  extra = Column(PickleType(pickler=CompressedPickler))


class TuningRun(Base):
github jansel / opentuner / opentuner / resultsdb / models.py View on Github external
try:
      session.flush()
      if parameter_info is None:
        return session.query(ProgramVersion).filter_by(program=program,
                                                     version=version).one()
      else:
        return session.query(ProgramVersion).filter_by(program=program,
                                                      version=version,
                                                      parameter_info=parameter_info).one()
    except sqlalchemy.orm.exc.NoResultFound:
      t = ProgramVersion(program=program, version=version, parameter_info=parameter_info)
      session.add(t)
      return t


class Configuration(Base):
  program_id = Column(ForeignKey(Program.id))
  program = relationship(Program)
  hash = Column(String(64))
  data = Column(PickleType(pickler=CompressedPickler))

  @classmethod
  def get(cls, session, program, hashv, datav):
    try:
      session.flush()
      return (session.query(Configuration)
              .filter_by(program=program, hash=hashv).one())
    except sqlalchemy.orm.exc.NoResultFound:
      t = Configuration(program=program, hash=hashv, data=datav)
      session.add(t)
      return t
github jansel / opentuner / opentuner / resultsdb / models.py View on Github external
tuning_run = relationship(TuningRun, backref='bandit_info')
  # the bandit exploration/exploitation tradeoff
  c = Column(Float)
  # the bandit window
  window = Column(Integer)

class BanditSubTechnique(Base):
  bandit_info_id = Column(ForeignKey(BanditInfo.id))
  bandit_info = relationship(BanditInfo, backref='subtechniques')
  name = Column(String(128))


if __name__ == '__main__':
  #test:
  engine = create_engine('sqlite:///:memory:', echo=True)
  Base.metadata.create_all(engine)
github jansel / opentuner / opentuner / resultsdb / models.py View on Github external
  @classmethod
  def get(cls, session, program, hashv, datav):
    try:
      session.flush()
      return (session.query(Configuration)
              .filter_by(program=program, hash=hashv).one())
    except sqlalchemy.orm.exc.NoResultFound:
      t = Configuration(program=program, hash=hashv, data=datav)
      session.add(t)
      return t


Index('ix_configuration_custom1', Configuration.program_id, Configuration.hash)


class MachineClass(Base):
  name = Column(String(128))

  @classmethod
  def get(cls, session, name):
    try:
      session.flush()
      return session.query(MachineClass).filter_by(name=name).one()
    except sqlalchemy.orm.exc.NoResultFound:
      t = MachineClass(name=name)
      session.add(t)
      return t


class Machine(Base):
  name = Column(String(128))
github jansel / opentuner / opentuner / resultsdb / models.py View on Github external
try:
      s = zlib.decompress(string)
    except:
      s = string
    return loads(s)

class Base(object):
  @declared_attr
  def __tablename__(cls):
    """convert camel case to underscores"""
    return re.sub(r'([a-z])([A-Z])', r'\1_\2', cls.__name__).lower()

  id = Column(Integer, primary_key=True, index=True)


Base = declarative_base(cls=Base)

class _Meta(Base):
  """ meta table to track current version """
  db_version = Column(String(128))

  @classmethod
  def has_version(cls, session, version):
    try:
      session.flush()
      session.query(_Meta).filter_by(db_version=version).one()
      return True
    except sqlalchemy.orm.exc.NoResultFound:
      return False

  @classmethod
  def get_version(cls, session):
github jansel / opentuner / opentuner / resultsdb / models.py View on Github external
DesiredResult.generation)

Index('ix_desired_result_custom2', DesiredResult.tuning_run_id,
      DesiredResult.configuration_id)


# track bandit meta-technique information if a bandit meta-technique is used for a tuning run.
class BanditInfo(Base):
  tuning_run_id = Column(ForeignKey(TuningRun.id))
  tuning_run = relationship(TuningRun, backref='bandit_info')
  # the bandit exploration/exploitation tradeoff
  c = Column(Float)
  # the bandit window
  window = Column(Integer)

class BanditSubTechnique(Base):
  bandit_info_id = Column(ForeignKey(BanditInfo.id))
  bandit_info = relationship(BanditInfo, backref='subtechniques')
  name = Column(String(128))


if __name__ == '__main__':
  #test:
  engine = create_engine('sqlite:///:memory:', echo=True)
  Base.metadata.create_all(engine)