nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: patrick-kidger/equinox
Pull request #950 (2025-02-14 10:50:36)

Allow zero shapes in nn.Linear
`math.sqrt(0)` throws an exception, which prevents `eqx.nn.Linear(0, 4)` from working, even though it is well defined.


Patch:
diff --git a/equinox/nn/_linear.py b/equinox/nn/_linear.py
index 4c8655d..8b3fe01 100644
--- a/equinox/nn/_linear.py
+++ b/equinox/nn/_linear.py
@@ -52,7 +52,10 @@ class Linear(Module, strict=True):
         wkey, bkey = jrandom.split(key, 2)
         in_features_ = 1 if in_features == "scalar" else in_features
         out_features_ = 1 if out_features == "scalar" else out_features
-        lim = 1 / math.sqrt(in_features_)
+        if in_features_ == 0:
+            lim = 1.0
+        else:
+            lim = 1 / math.sqrt(in_features_)
         wshape = (out_features_, in_features_)
         self.weight = default_init(wkey, wshape, dtype, lim)
         bshape = (out_features_,)


Test patch:
diff --git a/tests/test_nn.py b/tests/test_nn.py
index d20ac9b..aeeee0a 100644
--- a/tests/test_nn.py
+++ b/tests/test_nn.py
@@ -22,6 +22,16 @@ def test_custom_init():
 
 
 def test_linear(getkey):
+    # Zero input shape
+    linear = eqx.nn.Linear(0, 4, key=getkey())
+    x = jrandom.normal(getkey(), (0,))
+    assert linear(x).shape == (4,)
+
+    # Zero output shape
+    linear = eqx.nn.Linear(4, 0, key=getkey())
+    x = jrandom.normal(getkey(), (4,))
+    assert linear(x).shape == (0,)
+
     # Positional arguments
     linear = eqx.nn.Linear(3, 4, key=getkey())
     x = jrandom.normal(getkey(), (3,))
Repository: googleapis/google-api-python-client
Pull request #2367 (2024-03-22 21:43:59)

feat: validate credentials for universe before request
Towards #2365 🦕
Towards b/324211188 🦕



Patch:
diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py
index 5f160485c..eb01be65a 100644
--- a/googleapiclient/discovery.py
+++ b/googleapiclient/discovery.py
@@ -1050,6 +1050,9 @@ def createMethod(methodName, methodDesc, rootDesc, schema):
     def method(self, **kwargs):
         # Don't bother with doc string, it will be over-written by createMethod.
 
+        # Validate credentials for the configured universe.
+        self._validate_credentials()
+
         for name in kwargs:
             if name not in parameters.argmap:
                 raise TypeError("Got an unexpected keyword argument {}".format(name))


Test patch:
diff --git a/tests/test_discovery.py b/tests/test_discovery.py
index 8ffed4907..635d2acd5 100644
--- a/tests/test_discovery.py
+++ b/tests/test_discovery.py
@@ -2428,6 +2428,44 @@ if HAS_UNIVERSE:
 
             # TODO(google-api-python-client/issues/2365): Add test case for fake configured universe and fake credentials' universe.
 
+        def test_validate_credentials_before_api_request(self):
+            fake_universe = "foo.com"
+
+            http = google_auth_httplib2.AuthorizedHttp(
+                credentials=mock.Mock(universe_domain=universe.DEFAULT_UNIVERSE),
+                http=build_http(),
+            )
+            discovery = read_datafile("tasks.json")
+            tasks = build_from_document(
+                discovery,
+                http=http,
+                client_options=google.api_core.client_options.ClientOptions(
+                    universe_domain=universe.DEFAULT_UNIVERSE
+                ),
+            )
+
+            tasklists = tasks.tasklists()
+            request = tasklists.list()
+
+            # Check that credentials are indeed verified before request.
+            assert tasklists._validate_credentials()
+
+            http = google_auth_httplib2.AuthorizedHttp(
+                credentials=mock.Mock(universe_domain=fake_universe), http=build_http()
+            )
+            discovery = read_datafile("tasks.json")
+            tasks = build_from_document(
+                discovery,
+                http=http,
+                client_options=google.api_core.client_options.ClientOptions(
+                    universe_domain=universe.DEFAULT_UNIVERSE
+                ),
+            )
+
+            # Check that credentials are verified before request.
+            with self.assertRaises(universe.UniverseMismatchError):
+                request = tasks.tasklists().list()
+
 
 if __name__ == "__main__":
     unittest.main()
Repository: QCHackers/tqec
Pull request #255 (2024-06-26 12:37:04)

Fix grid.py and grid_test.py
This fixes the last merge that has been performed too quickly.


Patch:
diff --git a/src/tqec/templates/constructions/qubit.py b/src/tqec/templates/constructions/qubit.py
index 910fb1a8..6cea281e 100644
--- a/src/tqec/templates/constructions/qubit.py
+++ b/src/tqec/templates/constructions/qubit.py
@@ -13,7 +13,7 @@ from tqec.templates.scale import LinearFunction
 
 
 class DenseQubitSquareTemplate(ComposedTemplate):
-    def __init__(self, dim: Dimension) -> None:
+    def __init__(self, dim: LinearFunction, k: int = 2) -> None:
         """An error-corrected qubit.
 
         The below text represents this template for an input ``dimension = FixedDimension(4)`` ::
@@ -27,9 +27,10 @@ class DenseQubitSquareTemplate(ComposedTemplate):
 
         Args:
             dim: dimension of the error-corrected qubit.
+            k: initial value for the scaling parameter.
         """
         # nsone: non-scalable one
-        nsone = FixedDimension(1)
+        nsone = LinearFunction(0, 1)
 
         # 0  4  4  4  4  1
         # 5  6  6  6  6  7


Test patch:
diff --git a/src/tqec/templates/constructions/grid_test.py b/src/tqec/templates/constructions/grid_test.py
index e72b14d6..8a52949a 100644
--- a/src/tqec/templates/constructions/grid_test.py
+++ b/src/tqec/templates/constructions/grid_test.py
@@ -3,7 +3,7 @@ import numpy
 from tqec.templates.atomic.rectangle import RawRectangleTemplate
 from tqec.templates.constructions.grid import TemplateGrid
 from tqec.templates.constructions.qubit import DenseQubitSquareTemplate
-from tqec.templates.scale import FixedDimension
+from tqec.templates.scale import LinearFunction
 
 
 def test_grid_simple():
@@ -21,7 +21,7 @@ def test_grid_simple():
 
 
 def test_grid_qubits():
-    template = DenseQubitSquareTemplate(FixedDimension(2))
+    template = DenseQubitSquareTemplate(LinearFunction(0, 2), k=2)
     assert template.expected_plaquettes_number == 14
     template_arr = template.instantiate(list(range(1, 15)))