Writing my own little powershell plotting script

Everything I seem to find for plotting files with an offset is either too complicated or too simple. Plotman is supposedly great, but getting it to work on Windows is a nightmare. Unfortunately my powershell skills are horrible. I would love to be able to a) have a central configuration file – most examples I see hardcode everything. b) check to see if the load is too high or the temp folder is too crowded before starting a new plot and c) give a countdown before the next plot and some kind of a status. So far here’s what I’ve got. Do you have any improvements / suggestions? A nice script of your own that you’d care to share?

#performance tweaks
$initial_delay = 0
$delay_increment = 2400
$plots_to_run = 1
$ram_buffer_size = 8192
$cores_to_use = 3

#folders
$chia_version = "1.1.1"
$home_folder = "C:\Users\user_name"
$temp_drive_location = "h:\"
$final_drive_location = "f:\"
$chia_executable_location = "$home_folder\AppData\Local\chia-blockchain\app-$chia_version\resources\app.asar.unpacked\daemon"

$current_loop = 1
DO
{

 "Starting plot $current_loop"

  $wait_argument = $initial_delay + $delay_increment * ($current_loop - 1)

 "Now current_loop is $current_loop and wait_argument is $wait_argument"

 cd $chia_executable_location 

 $current_plotting_command = "start-process ./chia.exe plots create -k 32 -r $cores_to_use -b $ram_buffer_size -n 100 -t $temp_drive_location -d $final_drive_location"
 
 $current_log = "$(get-date -f yyyy-MM-dd-hh-mm-ss)_log.txt"

 Invoke-Expression  $current_plotting_command *> $home_folder/.chia/mainnet/plotter/$current_log

 "executing: $current_plotting_command logging to $current_log"

  timeout /t $wait_argument;

 $current_loop ++

} While ($current_loop -le $plots_to_run -1)
6 Likes
 # this script runs a string of plots -- one immideately, and then one every $delay_increment seconds
# when done it sends you an sms (you need a Twilio account for that)

####################################################################################################
# Config -- make sure you change this to your specifics.
####################################################################################################
# since location of chia executable changes with every release you need to update 
# $chia_version every time!
####################################################################################################

#how many plots?
$plots_to_run = 12

#delay (first plot will fire off in 1 second, the rest will fire $delay_increment seconds after each other
$initial_delay = 1
$delay_increment = 2400 #40 minutes

#ram and cores
$ram_buffer_size = 4000
$cores_to_use = 3

#location of the executable (you only need to change the version and your home folder -- in Windows it depends on your username)
$chia_version = "1.1.2"
$home_folder = "C:\Users\your_user_name"
$chia_executable_location = "$home_folder\AppData\Local\chia-blockchain\app-$chia_version\resources\app.asar.unpacked\daemon"


# temp drive and final drive 
# todo: add support for multiple drives 
$temp_drive_location = "h:\"
$final_drive_location = "g:\"

# End config
# If you are not gonna rip out sms functionality, there's also hardcoded config for Twilio below 
####################################################################################################

# pretty countdown timer. 
Function Sleep-Progress($seconds_to_sleep, $message){
    for ($i=5; $i -gt 1; $i–-) {  
        Write-Progress -Activity  $message -SecondsRemaining $i
        Start-Sleep 1
    }
}


#you need a twilio.com account for this to work
#send sms message with Twilio -- config hardcoded inside
Function Send-SMS($message){
    if($send_sms){

        # Twilio sms config
        $send_sms = 1
        $sid = 'your_sid'
        $token = 'your_token'
        $number = 'your_twilio_number'

        # Twilio API endpoint and POST params
        $url = "https://api.twilio.com/2010-04-01/Accounts/$sid/Messages.json"
        $params = @{ To = "+phone_number_you_are_messaging"; From = $number; Body = $message }

        # Create a credential object for HTTP basic auth
        $p = $token | ConvertTo-SecureString -asPlainText -Force
        $credential = New-Object System.Management.Automation.PSCredential($sid, $p)

        # Make API request, selecting JSON properties from response
        Invoke-WebRequest $url -Method Post -Credential $credential -Body $params -UseBasicParsing |
        ConvertFrom-Json | Select sid, body
    }

} 


#this is the main loop

$current_loop = 1
DO
{

 "Starting plot $current_loop"

  if(1 -eq $current_loop){
    $wait_argument = $initial_delay
  }
  else{
     $wait_argument = $delay_increment * ($current_loop - 1)
  }

 "Now current_loop is $current_loop and wait_argument is $wait_argument"

 cd $chia_executable_location 

 $current_plotting_command = "$chia_executable_location/chia.exe plots create -k 32 -r $cores_to_use -b $ram_buffer_size -n 1 -t $temp_drive_location -d $final_drive_location"
 
 $current_log = "$(get-date -f yyyyMMdTHHmmssffffZ)_log.txt"

 Invoke-Expression -Command  $current_plotting_command *> $home_folder/.chia/mainnet/plotter/$current_log

 "executing: $current_plotting_command logging to $current_log"


  $sleep_message = "Getting ready to launch $current_loop of $plots_to_run. Sleeping for $wait_argument seconds"

  Sleep-Progress $wait_argument $sleep_message

  "sleep over, waking up, next iteration"

 $current_loop ++

} While ($current_loop -le $plots_to_run)

"done with looping"
Send-SMS "done with looping"
3 Likes

Awesome! Keep us up to date, this looks very cool. Love the variable use for version, number of plots, etc!

Looks neat. I’ve got some utility scripts at GitHub - JustinLloyd/chia-utilities that might have some stuff you can crib ideas from. I run my plots on Task Scheduler.

4 Likes

I probably would not have bothered writing my own if I found this first – that looks much better

1 Like

Well thanks for the compliment, but if you do use them, don’t blindly pull latest each time I push to the repo. The scripts are for my own edification and I frequently practice Drunken Coding/Blind Hacking, push at 4AM and go to bed, only to wake up the next day at 9AM and say “which idiot wrote this?!?” The scripts are stable right now, that doesn’t mean they will be stable at 5AM on Saturday morning.

1 Like

How do you get CommandLine to show up in $ChiaProcesses = Get-Process -Name 'chia' -ErrorAction Ignore| Select-Object -Property Id, CommandLine ? Is that in some special version of Powershell? I get errors when I try to get CommandLine and it does not show up in Get-Process for me.

In pwsh 7 it works from ps, get-process. In powershell 5.1:

gwmi win32_process -filter "name='chia.exe'" |select commandline
3 Likes

Are there anyway you could share the parallel plotting script with logging ability, with no SMS related script. Just a good old code with local control

Haha, that’s exactly what I needed. I was thinking of tackling it myself but you already did. Thanks, man!

There is also GitHub - MScholtes/PS2EXE: Module to compile powershell scripts to executables PS2EXE which will convert your PowerShell scripts to .exe files.

May help people if they get something they can just double-click to use.

1 Like