Skip to content

Creating a new code module

edmundhighcock edited this page Apr 1, 2016 · 4 revisions

Log

This is a log of what I did to create a new module called gryfxcrmod... this will one day be turned into a proper set of instructions!

$ sudo gem install jeweler\
$ jeweler gryfxcrmod\
$ cd gryfxcrmod\
$ git remote add set-url origin git@github.com:coderunner-framework/gryfxcrmod.git

Create gryfxcrmod on github.

$ git push origin master\
$ mkdir lib/gryfxcrmod\
$ touch lib/gryfxcrmod/gryfx.rb

Comment out these lines in Rakefile:

#require 'rcov/rcovtask'\
#Rcov::RcovTask.new do |test|\
  ##test.libs << 'test'\
  ##test.pattern = 'test/**/test_*.rb'\
  ##test.verbose = true\
  ##test.rcov_opts << '--exclude "gems/*"'\
##end

Comment this line in Gemfile

#gem "rcov", ">= 0"

and edit these lines to this:

gem "bundler", ">= 1.0.0"\
gem "jeweler", ">= 1.8.4"

and add this line at the top of Gemfile:

gem "coderunner", ">= 0.13.0"

In test/helper replace this line:

require 'gryfxcrmod'

with this line:

require 'coderunner'

Add this line to lib/gryfxcrmod.rb

require 'gryfxcrmod/gryfx'

Edit test/test_gryfxcrmod to this:

require 'helper'

class TestGryfxcrmod < Test::Unit::TestCase\
  def setup\
    CodeRunner.setup_run_class('gryfx')\
  end\
  def test_basics\
  end\
end

Now install bundler if you don't already have it:

$ sudo gem install bundler

And install dependencies:

$ sudo bundle install

Now run the tests:

$ rake test

I got this error:

NameError: uninitialized constant CodeRunner::Gryfx

We need to put something in lib/gryfxcrmod/gryfx.rb... edit it to give this:

class CodeRunner\
  class Gryfx < Run\
  end\
end 

Test again

$ rake test

Error is:

NoMethodError: Run class property modlet_required not found

We need to add basic configuration for gryfxcrmod.

Edit lib/gryfxcrmod/gryfx.rb so that it looks like this:

class CodeRunner
  #  This is a customised subclass of the CodeRunner::Run  class which allows CodeRunner to run and analyse the gyrofluid GPU turbulent transport solver Gryfx.
  #
  #  It  generates the Gryfx input file, and both analyses the results and allows easy plotting of them. 
class Gryfx < Run::FortranNamelistC
  #include CodeRunner::SYSTEM_MODULE


# Where this file is
@code_module_folder = folder = File.dirname(File.expand_path(__FILE__)) # i.e. the directory this file is in

# Use the Run::FortranNamelist tools to process the variable database
setup_namelists(@code_module_folder)
#require 'trinitycrmod/output_files'
#require 'trinitycrmod/graphs'

################################################
# Quantities that are read or determined by CodeRunner
# after the simulation has ended
###################################################

@results = []

@code_long="Gryfx Gyrofluid Solver"

@run_info=[:time, :is_a_restart, :restart_id, :restart_run_name, :completed_timesteps, :percent_complete]

@uses_mpi = false

@modlet_required = false

@naming_pars = []

@excluded_sub_folders = []

#  A hook which gets called when printing the standard run information to the screen using the status command.
def print_out_line
  #p ['id', id, 'ctd', ctd]
  #p rcp.results.zip(rcp.results.map{|r| send(r)})
  name = @run_name
  name += " (res: #@restart_id)" if @restart_id
  name += " real_id: #@real_id" if @real_id
  beginning = sprintf("%2d:%d %-60s %1s:%2.1f(%s) %3s%1s",  @id, @job_no, name, @status.to_s[0,1],  @run_time.to_f / 60.0, @nprocs.to_s, percent_complete, "%")
  if ctd
    beginning += sprintf("Q:%f, Pfusion:%f MW, Ti0:%f keV, Te0:%f keV, n0:%f x10^20", fusionQ, pfus, ti0, te0, ne0)
  end
  beginning += "  ---#{@comment}" if @comment
  beginning
end


#  This is a hook which gets called just before submitting a simulation. It sets up the folder and generates any necessary input files.
def generate_input_file
    write_input_file
end

#  This command uses the infrastructure provided by Run::FortranNamelist, provided by CodeRunner itself.
def write_input_file
  File.open(@run_name + ".in", 'w'){|file| file.puts input_file_text}
end

# Parameters which follow the Trinity executable, in this case just the input file.
def parameter_string
  @run_name + ".in"
end


def parameter_transition
end


@source_code_subfolders = []

# This method, as its name suggests, is called whenever CodeRunner is asked to analyse a run directory. This happens if the run status is not :Complete, or if the user has specified recalc_all(-A on the command line) or reprocess_all (-a on the command line).
#
def process_directory_code_specific
  get_status
  #p ['id is', id, 'ctd is ', ctd]
  if ctd
    calculate_results
  end
  #p ['fusionQ is ', fusionQ]
end

end end

`

Now run the tests: they are ok!

Now copy a .gitignore from an existing CodeRunner module

$ cp ../trinitycrmod/.gitignore .

Open Rakefile and edit project information.

Now check in:

$ git commit -av

Add a version:

$ rake version:write

Release! (You need an account on rubygems.org.)

$ rake release

Clone this wiki locally