Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Tests #91

Merged
merged 105 commits into from
Jul 8, 2024
Merged

Conversation

merajhashemi
Copy link
Collaborator

No description provided.

@merajhashemi merajhashemi changed the base branch from master to merajhashemi/refactor-cmp May 1, 2024 20:07
@codecov-commenter
Copy link

codecov-commenter commented May 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (gallego-posada/1.0.0-alpha@9f94213). Learn more about missing BASE report.

Current head dbf6fa3 differs from pull request most recent head 37fad6f

Please upload reports for the commit 37fad6f to get more accurate results.

Additional details and impacted files
@@                      Coverage Diff                      @@
##             gallego-posada/1.0.0-alpha      #91   +/-   ##
=============================================================
  Coverage                              ?   80.17%           
=============================================================
  Files                                 ?       28           
  Lines                                 ?      938           
  Branches                              ?        0           
=============================================================
  Hits                                  ?      752           
  Misses                                ?      186           
  Partials                              ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Base automatically changed from merajhashemi/refactor-cmp to gallego-posada/1.0.0-alpha May 14, 2024 14:56
def compute_violations(self, x: torch.Tensor) -> cooper.CMPState:
"""
Computes the constraint violations for the given parameters.
"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment that sampling for strict violation and violation is different

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO?

self.device = device

def test_convergence(self, extrapolation, alternation_type):
x = torch.nn.Parameter(torch.ones(5, device=self.device))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start from random init

@merajhashemi merajhashemi force-pushed the merajhashemi/refactor-tests branch from 0b32859 to c49f65d Compare May 15, 2024 17:53
Comment on lines 43 to 46
if self.expects_penalty_coefficient and penalty_coefficient is None:
raise ValueError(f"{type(self).__name__} expects a penalty coefficient but none was provided.")
if not self.expects_penalty_coefficient and penalty_coefficient is not None:
raise ValueError(f"{type(self).__name__} does not expect a penalty coefficient but one was provided.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this has code repetition with Constraint.sanity_check_penalty_coefficient. Let's merge the two.

Create a helper function for this in the Formulation called sanity_check_penalty_coefficient and call it here. Moreover, replace the check in Constraint with a self.formulation.sanity_check_penalty_coefficient

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3ee14f9

def compute_violations(self, x: torch.Tensor) -> cooper.CMPState:
"""
Computes the constraint violations for the given parameters.
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO?

Comment on lines +206 to +210
constraints = []
if self.has_ineq_constraint:
constraints.append(self.A.cpu().numpy() @ x <= self.b.cpu().numpy())
if self.has_eq_constraint:
constraints.append(self.C.cpu().numpy() @ x == self.d.cpu().numpy())
Copy link
Collaborator

@juan43ramirez juan43ramirez Jul 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever use both equalities and inequalities in our tests? Would the code work then?
Otherwise, can we raise an error if someone tries having both?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. We don't currently have any tests that have both types of constraints. But the cmp should work 🤔

@merajhashemi merajhashemi merged commit 1b5b926 into gallego-posada/1.0.0-alpha Jul 8, 2024
1 check failed
@merajhashemi merajhashemi deleted the merajhashemi/refactor-tests branch July 8, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants