From e25e17c00407a50a6afbdb6bfe78b2e0d19ad8b1 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Wed, 2 Jul 2025 06:26:10 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=93=9D=20CodeRabbit=20Chat:=20Refacto?= =?UTF-8?q?r=20api=5Fhealth=5Fchecker.py:=20ensure=20directory,=20rename?= =?UTF-8?q?=20function,=20fix=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/api_health_checker.py | 67 +++++++++++---------------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/protocols/api_health_checker.py b/protocols/api_health_checker.py index 647c1b1..2cce292 100644 --- a/protocols/api_health_checker.py +++ b/protocols/api_health_checker.py @@ -1,47 +1,26 @@ -# Real Protocol: API Health Checker import requests -import time +from requests.exceptions import RequestException, Timeout, ConnectionError -def task(): - """Check health of various API endpoints""" - endpoints = [ - {'name': 'Local API', 'url': 'http://localhost:8080/health'}, - {'name': 'JSONPlaceholder', 'url': 'https://jsonplaceholder.typicode.com/posts/1'}, - {'name': 'GitHub API', 'url': 'https://api.github.com/rate_limit'} - ] - - results = [] - failures = 0 - - for endpoint in endpoints: + +def execute(protocol_context): + """ + Checks the health of a list of API endpoints. + """ + api_endpoints = protocol_context.get("api_endpoints") + if not api_endpoints: + return {"status": "error", "message": "No API endpoints provided in the protocol context."} + + results = {} + for endpoint in api_endpoints: try: - start_time = time.time() - response = requests.get(endpoint['url'], timeout=5) - response_time = (time.time() - start_time) * 1000 # ms - - results.append({ - 'name': endpoint['name'], - 'status': response.status_code, - 'response_time_ms': round(response_time, 2), - 'healthy': response.status_code == 200 - }) - - if response.status_code != 200: - failures += 1 - - except Exception as e: - failures += 1 - results.append({ - 'name': endpoint['name'], - 'error': str(e), - 'healthy': False - }) - - return { - 'success': failures < len(endpoints) / 2, # Success if less than half failed - 'action': 'api_health_check', - 'total_endpoints': len(endpoints), - 'healthy_count': len(endpoints) - failures, - 'failure_count': failures, - 'results': results - } \ No newline at end of file + response = requests.get(endpoint, timeout=10) + response.raise_for_status() # Raise an exception for bad status codes + results[endpoint] = {"status": "ok", "statusCode": response.status_code} + except Timeout: + results[endpoint] = {"status": "error", "message": "Request timed out"} + except ConnectionError: + results[endpoint] = {"status": "error", "message": "Could not connect to the server"} + except RequestException as e: + results[endpoint] = {"status": "error", "message": str(e)} + + return {"status": "completed", "results": results} From 2405420f112e5f383a4abadc2b8b9e9323584b0a Mon Sep 17 00:00:00 2001 From: Garvey Date: Wed, 2 Jul 2025 03:07:25 -0500 Subject: [PATCH 2/2] Fix linting issues and add working quantum simulator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix Python version configuration in CI (3.1 -> 3.10) - Fix flake8 line length issues in api_health_checker.py - Add working quantum simulator using dimod (no API required) - Update requirements.txt with quantum dependencies 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .github/workflows/python-ci.yml | 2 +- protocols/api_health_checker.py | 22 ++++++++++--- protocols/quantum_simulator.py | 55 +++++++++++++++++++++++++++++++++ requirements.txt | 1 + 4 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 protocols/quantum_simulator.py diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 3264e47..16d7078 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.10, 3.11] + python-version: ["3.10", "3.11"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} diff --git a/protocols/api_health_checker.py b/protocols/api_health_checker.py index 2cce292..e84b927 100644 --- a/protocols/api_health_checker.py +++ b/protocols/api_health_checker.py @@ -8,18 +8,30 @@ def execute(protocol_context): """ api_endpoints = protocol_context.get("api_endpoints") if not api_endpoints: - return {"status": "error", "message": "No API endpoints provided in the protocol context."} + return { + "status": "error", + "message": "No API endpoints provided in the protocol context.", + } results = {} for endpoint in api_endpoints: try: response = requests.get(endpoint, timeout=10) - response.raise_for_status() # Raise an exception for bad status codes - results[endpoint] = {"status": "ok", "statusCode": response.status_code} + response.raise_for_status() # Raise an exception for bad codes + results[endpoint] = { + "status": "ok", + "statusCode": response.status_code + } except Timeout: - results[endpoint] = {"status": "error", "message": "Request timed out"} + results[endpoint] = { + "status": "error", + "message": "Request timed out" + } except ConnectionError: - results[endpoint] = {"status": "error", "message": "Could not connect to the server"} + results[endpoint] = { + "status": "error", + "message": "Could not connect to the server", + } except RequestException as e: results[endpoint] = {"status": "error", "message": str(e)} diff --git a/protocols/quantum_simulator.py b/protocols/quantum_simulator.py new file mode 100644 index 0000000..2155b16 --- /dev/null +++ b/protocols/quantum_simulator.py @@ -0,0 +1,55 @@ +""" +Quantum Simulator Protocol +Uses dimod for local quantum algorithm testing without D-Wave API access. +""" + +import dimod + + +def execute(protocol_context): + """ + Demonstrates local quantum optimization using dimod's ExactSolver. + This works without any API keys or external connections. + """ + try: + # Create a simple Binary Quadratic Model (BQM) + # This represents a basic optimization problem + linear = {0: -1, 1: 1, 2: -1} # Linear coefficients + quadratic = {(0, 1): 2, (1, 2): -1} # Quadratic coefficients + + # Create the BQM + bqm = dimod.BinaryQuadraticModel( + linear, quadratic, 0.0, dimod.BINARY + ) + + # Solve using local exact solver (no API required) + sampler = dimod.ExactSolver() + sampleset = sampler.sample(bqm) + + # Get the best solution + best_sample = sampleset.first + + return { + "status": "completed", + "quantum_solution": { + "variables": dict(best_sample.sample), + "energy": best_sample.energy, + "num_occurrences": best_sample.num_occurrences, + "solver_used": "dimod.ExactSolver (local)", + "problem_size": len(linear), + "message": "Quantum optimization completed locally" + } + } + + except Exception as e: + return { + "status": "error", + "message": f"Quantum simulation failed: {str(e)}" + } + + +if __name__ == "__main__": + # Test the quantum simulator + result = execute({}) + print("Quantum Simulation Result:") + print(result) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 2d06bfb..9f593e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ click==8.2.1 cryptography==45.0.4 dataclasses-json==0.6.7 dimod==0.12.20 +# D-Wave tools that work without API access diskcache==5.6.3 distro==1.9.0 dwave-cloud-client==0.13.6