mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   EdH (https://www.mersenneforum.org/forumdisplay.php?f=152)
-   -   How I Create a Colab Session That Factors factordb Small Composites with PARI/GP (https://www.mersenneforum.org/showthread.php?t=26212)

EdH 2020-11-21 17:12

How I Create a Colab Session That Factors factordb Small Composites with PARI/GP
 
(Note: I expect to keep the first post of each of these "How I..." threads up-to-date with the latest version. Please read the rest of each thread to see what may have led to the current set of instructions.)

I will take the liberty of expecting readers to already be somewhat familiar with Google's Colaboratory sessions. There are several threads already on Colab and these should be reviewed by interested readers:

[URL="https://mersenneforum.org/showthread.php?t=24646"]Google Colaboratory Notebook?[/URL]
[URL="https://www.mersenneforum.org/showthread.php?t=24818"]GPU72 Notebook Integration...[/URL]
[URL="https://mersenneforum.org/showthread.php?p=527912"]Notebook Instance Reverse SSH and HTTP Tunnels.[/URL]
[URL="https://www.mersenneforum.org/showthread.php?t=24875"]Colab question[/URL]

I do not, as of yet, have a github account, so I have not created an upload of this to github. Others may feel free to do so, if desired.

The following is a manner to retrieve small composites from factordb.com and factor out small primes by TF using PARI/GP. This does not totally factor all composites that are encountered. Although it can be used with larger composites, it is not to be considered effective, unless those composites are comprised of many small primes.

When run, this session retrieves composites of a chosen size from factordb, factors out small primes and submits the factors back to the db.

To use Colab, you need a Gmail account and will be required to log into that account to run a session.

On to the specifics:

Open a [URL="https://colab.research.google.com/notebooks/welcome.ipynb"]Google Colaboratory[/URL] session.
Sign in with your Google/Gmail account info.
Choose New Python3 notebook:
[code]
Menu->File->New Python3 notebook (or within popup)
[/code]Click Connect to start a session.
Edit title from Untitled... to whatever you like.
Paste the following into the Codeblock:
[code]
#########################################################
### This Colaboratory session is designed to retrieve ###
### small composites from factordb.com and factor them ##
### using PARI/GP. The factors are then sent back to ###
### factordb. ###
### ###
### To adjust the number of composites to retrieve as ###
### well as the size to retrive, change the variables ###
### totalrun and digitsize. The size of the random ###
### number to be used to help avoid collisions (1000) ###
### can also be changed, as well as the offset (10). ###
#########################################################

!apt install pari-gp
!echo '#!/bin/bash/' >dbW.sh
!echo '' >>dbW.sh
!echo 'digitsize=20' >>dbW.sh
!echo 'totalrun=50' >>dbW.sh
!echo '' >>dbW.sh
!echo 'printf "\nFactoring $totalrun composites:\n\n"' >>dbW.sh
!echo 'for ((n=0;n<totalrun;n++))' >>dbW.sh
!echo ' do' >>dbW.sh
!echo ' startt=$SECONDS' >>dbW.sh
!echo ' randomnumber=$(echo $((10 + RANDOM % 1000)))' >>dbW.sh
!echo ' wget "http://factordb.com/listtype.php?t=3&mindig=${digitsize}&perpage=1&start=$randomnumber&download=1" -q -O dbTemp' >>dbW.sh
!echo ' exec <"dbTemp"' >>dbW.sh
!echo ' read composite in' >>dbW.sh
!echo ' if [[ $composite =~ ^[0-9]+$ ]]' >>dbW.sh
!echo ' then' >>dbW.sh
!echo ' ccount=0' >>dbW.sh
!echo ' echo "Composite $((${n}+1)) of $totalrun is $composite <${#composite}>"' >>dbW.sh
!echo ' temp=$(echo "factor($composite, 10^9)" | gp -f -q)' >>dbW.sh
!echo ' temp=$(echo "${temp//\n/}" | xargs)' >>dbW.sh
!echo ' temp=$(echo "${temp// 1]/}")' >>dbW.sh
!echo ' temp=$(echo "${temp//]/}")' >>dbW.sh
!echo ' temp=$(echo "${temp//[/*}")' >>dbW.sh
!echo ' temp=$(echo "${temp// /}")' >>dbW.sh
!echo ' printf "Factors are ${temp:1} <$((${SECONDS}-${startt}))s>\n\n"' >>dbW.sh
!echo ' returnfactors=${composite}%3D${temp:1}' >>dbW.sh
!echo ' wget "http://factordb.com/report.php?report=$returnfactors" -q -O dbSuccess' >>dbW.sh
!echo ' else' >>dbW.sh
!echo ' let ccount=${ccount}+1' >>dbW.sh
!echo ' printf "Non-number found (${composite})! Pausing briefly. . .\n\n"' >>dbW.sh
!echo ' if [ $ccount -gt 4 ]' >>dbW.sh
!echo ' then' >>dbW.sh
!echo ' sleep 590' >>dbW.sh
!echo ' fi' >>dbW.sh
!echo ' sleep 10' >>dbW.sh
!echo ' fi' >>dbW.sh
!echo ' done' >>dbW.sh
!echo 'echo "Total time for $n composites was $SECONDS seconds."' >>dbW.sh
!echo 'rm dbTemp' >>dbW.sh
!bash dbW.sh

[/code]Click on the Run cell icon or use CTRL-Enter.

The first time this is run, PARI/GP will be installed prior to writing the script to a file and running it. Subsequent runs within the same session check that PARI/GP is installed and then continue.

The current default is to process fifty, 20 digit composites and stop. The factors are sent to the db automatically, so no other manual intervention is needed. To change the number of composites to work on for each run, edit the totalrun variable. To change the size of the composites to work on edit the digitsize variable. Choosing a size doesn't guarantee work on that size. It is only the minimum size to retrieve. This script will work with the smallest size available starting with the digitsize value.

Eventually, I hope to add a more detailed description of all the code.


All times are UTC. The time now is 18:12.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.