From 685751a173ccf26755555b0b23b50dab23110d32 Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Wed, 8 Jan 2025 07:34:05 +0400 Subject: [PATCH] add first script --- cvx/cli/__init__.py | 13 --------- cvx/cli/smallest_eigenvalue.py | 43 ---------------------------- cvx/cli/weather.py | 51 ---------------------------------- cvx/cradle/__init__.py | 0 cvx/cradle/main.py | 3 ++ 5 files changed, 3 insertions(+), 107 deletions(-) delete mode 100644 cvx/cli/__init__.py delete mode 100644 cvx/cli/smallest_eigenvalue.py delete mode 100644 cvx/cli/weather.py create mode 100644 cvx/cradle/__init__.py create mode 100644 cvx/cradle/main.py diff --git a/cvx/cli/__init__.py b/cvx/cli/__init__.py deleted file mode 100644 index 6d037dc..0000000 --- a/cvx/cli/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2023 Stanford University Convex Optimization Group -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/cvx/cli/smallest_eigenvalue.py b/cvx/cli/smallest_eigenvalue.py deleted file mode 100644 index 9712946..0000000 --- a/cvx/cli/smallest_eigenvalue.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2023 Stanford University Convex Optimization Group -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from typing import Dict - -import fire # type: ignore -import numpy as np - -from cvx.bson.file import read_bson - - -def smallest_ev(bson_file) -> Dict[str, float]: - """ - Compute the smallest eigenvalue of matrices stored in a bson file. - - There are faster methods to compute the smallest eigenvalue, e.g. an inverse power iteration. - Here, we only use this as an example to work with the bson interface. - - On the command line - - poetry run smallest-eigenvalue cli/data/test.bson - """ - - eigenvalues = {key: np.min(np.linalg.eigh(matrix)[0]) for key, matrix in read_bson(bson_file).items()} - - for key, ev in eigenvalues.items(): - print(key, ev) - - return eigenvalues - - -def main(): # pragma: no cover - fire.Fire(smallest_ev) diff --git a/cvx/cli/weather.py b/cvx/cli/weather.py deleted file mode 100644 index 55216d0..0000000 --- a/cvx/cli/weather.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2023 Stanford University Convex Optimization Group -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import fire # type: ignore -import requests # type: ignore - - -def cli(metric: str, latitude: float = 37.4419, longitude: float = -122.143) -> None: - """ - Get the current weather for a given metric - - Parameters - ---------- - metric : str - The metric to get the current weather for. - Use time, temperature, windspeed, winddirection or weathercode - For details: https://open-meteo.com/en/docs - latitude : float, optional - The latitude to get the current weather for, by default 37.4419 - longitude : float, optional - The longitude to get the current weather for, by default -122.143 - """ - url = "https://api.open-meteo.com/v1/forecast" - url = f"{url}?latitude={str(latitude)}&longitude={str(longitude)}¤t_weather=true" - r = requests.get(url) - - if r.status_code == 200: - if metric in r.json()["current_weather"]: - x = r.json()["current_weather"][metric] - return x - else: - raise ValueError("Metric not supported!") - else: - raise ConnectionError("Open-Meteo is down!") - - -def main(): # pragma: no cover - """ - Run the CLI using Fire - """ - fire.Fire(cli) diff --git a/cvx/cradle/__init__.py b/cvx/cradle/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cvx/cradle/main.py b/cvx/cradle/main.py new file mode 100644 index 0000000..b818af9 --- /dev/null +++ b/cvx/cradle/main.py @@ -0,0 +1,3 @@ +def main(): + print("Hello") +