tensorlogic-cli 0.1.0-beta.1

TensorLogic command-line interface and library for compiling logical expressions to tensor graphs
Documentation
// Jenkins Pipeline for TensorLogic Validation
// Save as: Jenkinsfile

pipeline {
    agent any

    environment {
        TENSORLOGIC_VERSION = '0.1.0-alpha.2'
        CARGO_HOME = "${WORKSPACE}/.cargo"
        PATH = "${CARGO_HOME}/bin:${PATH}"
    }

    options {
        buildDiscarder(logRotator(numToKeepStr: '10'))
        timeout(time: 30, unit: 'MINUTES')
        timestamps()
    }

    stages {
        stage('Setup') {
            steps {
                script {
                    echo "Setting up TensorLogic CLI..."
                    sh '''
                        curl https://sh.rustup.rs -sSf | sh -s -- -y
                        source $HOME/.cargo/env
                        cargo install tensorlogic-cli --version ${TENSORLOGIC_VERSION}
                    '''
                }
            }
        }

        stage('Validate') {
            steps {
                script {
                    echo "Validating logic rules..."
                    sh '''
                        tensorlogic batch rules/*.tl --validate
                    '''
                }
            }
        }

        stage('Statistics') {
            parallel {
                stage('Generate Stats') {
                    steps {
                        script {
                            echo "Generating statistics..."
                            sh '''
                                mkdir -p reports
                                for rule in rules/*.tl; do
                                    name=$(basename "$rule" .tl)
                                    tensorlogic "$rule" \\
                                        --output-format stats \\
                                        --analyze > "reports/${name}_stats.txt"
                                done
                            '''
                        }
                    }
                }

                stage('Compile to JSON') {
                    steps {
                        script {
                            echo "Compiling to JSON..."
                            sh '''
                                mkdir -p compiled
                                for rule in rules/*.tl; do
                                    name=$(basename "$rule" .tl)
                                    tensorlogic "$rule" \\
                                        --output-format json \\
                                        --output "compiled/${name}.json" \\
                                        --validate
                                done
                            '''
                        }
                    }
                }
            }
        }

        stage('Visualize') {
            when {
                anyOf {
                    branch 'main'
                    branch 'develop'
                }
            }
            steps {
                script {
                    echo "Generating visualizations..."
                    sh '''
                        mkdir -p visualizations
                        for rule in rules/*.tl; do
                            name=$(basename "$rule" .tl)
                            tensorlogic "$rule" \\
                                --output-format dot \\
                                --output "visualizations/${name}.dot"
                            dot -Tpng "visualizations/${name}.dot" \\
                                -o "visualizations/${name}.png"
                        done
                    '''
                }
            }
        }

        stage('Test Strategies') {
            matrix {
                axes {
                    axis {
                        name 'STRATEGY'
                        values 'soft_differentiable', 'hard_boolean', 'fuzzy_godel', 'fuzzy_product'
                    }
                }
                stages {
                    stage('Test') {
                        steps {
                            script {
                                echo "Testing with strategy: ${STRATEGY}"
                                sh """
                                    for rule in rules/*.tl; do
                                        echo "Testing \$(basename \$rule) with ${STRATEGY}"
                                        tensorlogic "\$rule" \\
                                            --strategy ${STRATEGY} \\
                                            --validate \\
                                            --quiet
                                    done
                                """
                            }
                        }
                    }
                }
            }
        }

        stage('Quality Checks') {
            steps {
                script {
                    echo "Running quality checks..."
                    sh '''
                        # Check for large graphs
                        for rule in rules/*.tl; do
                            stats=$(tensorlogic "$rule" --output-format stats --quiet)
                            tensors=$(echo "$stats" | grep "Tensors:" | awk '{print $2}')
                            if [ "$tensors" -gt 100 ]; then
                                echo "⚠️  Large graph in $(basename $rule): $tensors tensors"
                            fi
                        done

                        # Format conversion checks
                        for rule in rules/*.tl; do
                            tensorlogic convert "$rule" \\
                                --from expr \\
                                --to json \\
                                --quiet > /dev/null
                        done
                    '''
                }
            }
        }

        stage('Deploy') {
            when {
                branch 'main'
            }
            steps {
                script {
                    echo "Deploying compiled rules..."
                    sh '''
                        # Example deployment
                        # Upload to artifact repository, S3, etc.
                        echo "Deployment would happen here"
                    '''
                }
            }
        }
    }

    post {
        always {
            archiveArtifacts artifacts: 'reports/*.txt, compiled/*.json, visualizations/*.png', allowEmptyArchive: true
        }
        success {
            echo "✓ Pipeline completed successfully!"
        }
        failure {
            echo "✗ Pipeline failed!"
        }
        cleanup {
            cleanWs()
        }
    }
}