Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Add constraint comparison utility to world.utils. #542

Closed

Conversation

neerajprad
Copy link

Summary:
This adds an isinstance like check for torch.constraint objects/classes, so that these comparisons can be consolidated within a single utility function is_constraint_eq.

Usage:

is_constraint_eq(dist.support, (constraints.real, constraints.greater_than))

, instead of:

isinstance(dist.support, (constraints._Real, constraints._GreaterThan))

, or the more obfuscatory

dist.support is constraints.real or isinstance(dist.support, constraints.greater_than)

See pytorch/pytorch#50616 for more details (note that the changes suggested in the issue are complementary).

  • This avoids usage of the non-public constraint classes (like constraints._Real, constraints._Interval).
  • Makes it possible to consolidate future changes (e.g. those arising out of the introduction of an Independent constraint - Independent constraint pytorch/pytorch#50547) within a single function.

This is a pre-requisite to some other fixes that are currently blocking D25918330. I will add these small fixes when I merge D25918330.

Differential Revision: D25935106

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported labels Jan 19, 2021
@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D25935106

@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D25935106

Summary:
Pull Request resolved: facebookresearch/beanmachine#542

This adds an equality testing utility for `torch.constraint` objects/classes, so that these comparisons can be consolidated within a single utility function `is_constraint_eq`.

Usage:
```
is_constraint_eq(dist.support, (constraints.real, constraints.greater_than))
```

, instead of:

```
isinstance(dist.support, (constraints._Real, constraints._GreaterThan))
```
, or the more obfuscatory

```
dist.support is constraints.real or isinstance(dist.support, constraints.greater_than)
```

See pytorch/pytorch#50616 for more details (note that the changes suggested in the issue are complementary).

 - This avoids usage of the non-public constraint classes (like `constraints._Real`, `constraints._Interval`).
 - Makes it possible to consolidate future changes (e.g. those arising out of the introduction of an `Independent` constraint - pytorch/pytorch#50547) within a single function.

This is a pre-requisite to some other fixes that are currently blocking D25918330. I will add these small fixes when I merge D25918330.

Differential Revision: D25935106

fbshipit-source-id: f585562b0f627f9b9669a54bcb2b45b05d560fe9
@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D25935106

@facebook-github-bot
Copy link
Collaborator

This pull request has been merged in 414dd99.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants