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

Simplify state conversions (excludes Crystal environments) #247

Merged
merged 60 commits into from
Dec 9, 2023

Conversation

alexhernandezgarcia
Copy link
Owner

This PR simplifies state conversions in the following ways:

  • state*2oracle has been removed as well as other mentions to oracle. In short, references to the oracle are now unified into references to the proxy.
  • statebatch2proxy and statetorch2proxy are now unified by states2proxy
  • statebatch2policy and statetorch2policy are now unified by states2policy
  • state2proxy has been removed from all environments because it is enough with the implementation in the base environment, which calls states2proxy.
  • policy2state has been removed.

I have also taken the chance to add richer docstrings. I believe all other changes should be related to the above.

  • I have run the sanity checks and everything seems fine.
  • Tests are passed locally.

Note: the PR includes some deletion of files, which come from a different branch because I messed up things somehow... 😓 Sorry for that!

nikita-0209 and others added 30 commits April 11, 2023 11:58
@alexhernandezgarcia
Copy link
Owner Author

@carriepl I would like to have your advice on how to proceed with this PR. The situation is the following:

  • This branch was off main before main included the crystal's updates.
  • Therefore, this PR does not update the crystal's environments.
  • Therefore, if it is merged to main, then main will be broken, until the changes updating the crystal's environments are applied.

I am thinking that an auxiliary branch off main would do, but I wonder if there is any other better way.

@carriepl
Copy link
Collaborator

carriepl commented Dec 8, 2023

@carriepl I would like to have your advice on how to proceed with this PR. The situation is the following:

  • This branch was off main before main included the crystal's updates.
  • Therefore, this PR does not update the crystal's environments.
  • Therefore, if it is merged to main, then main will be broken, until the changes updating the crystal's environments are applied.

I am thinking that an auxiliary branch off main would do, but I wonder if there is any other better way.

Is there any obstacle to rebasing this branch (or a copy of this branch, to be safer) over the main and then updating the crystal environments in the rebased version of this branch?

@alexhernandezgarcia
Copy link
Owner Author

@carriepl I would like to have your advice on how to proceed with this PR. The situation is the following:

  • This branch was off main before main included the crystal's updates.
  • Therefore, this PR does not update the crystal's environments.
  • Therefore, if it is merged to main, then main will be broken, until the changes updating the crystal's environments are applied.

I am thinking that an auxiliary branch off main would do, but I wonder if there is any other better way.

Is there any obstacle to rebasing this branch (or a copy of this branch, to be safer) over the main and then updating the crystal environments in the rebased version of this branch?

That's about what I thought you could say. The only obstacle is that I don't feel super at ease with rebasing yet. Would you mind outlining what the steps should be?

Copy link
Collaborator

@josephdviviano josephdviviano left a comment

Choose a reason for hiding this comment

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

Love this, net -1000 lines of code is a good PR any day of the week!

I wonder whether some of the environment specific conversion logic would be further abstracted into the base class or not, but it does not seem cumbersome to write these few lines of code, so it's not a priority.

Good stuff!

else:
return torch.tensor(x, dtype=torch.long, device=device)


def tint(x, device, int_type):
if isinstance(x, list) and torch.is_tensor(x[0]):
return torch.stack(x).type(int_type).to(device)
return torch.stack(x).to(device=device, dtype=int_type)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a note - if you're constantly doing this, it's a performance hazard. As I'm sure you're aware preallocating and filling an empty tensor will perform better than stacking lists, but of course it can lead to more complex code. Might be a good subject for a different PR.

Copy link
Owner Author

Choose a reason for hiding this comment

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

You're right. Rather for another PR indeed.

@josephdviviano
Copy link
Collaborator

josephdviviano commented Dec 8, 2023

@carriepl I would like to have your advice on how to proceed with this PR. The situation is the following:

  • This branch was off main before main included the crystal's updates.
  • Therefore, this PR does not update the crystal's environments.
  • Therefore, if it is merged to main, then main will be broken, until the changes updating the crystal's environments are applied.

I am thinking that an auxiliary branch off main would do, but I wonder if there is any other better way.

Is there any obstacle to rebasing this branch (or a copy of this branch, to be safer) over the main and then updating the crystal environments in the rebased version of this branch?

That's about what I thought you could say. The only obstacle is that I don't feel super at ease with rebasing yet. Would you mind outlining what the steps should be?

OK one thing you could do is merge locally main -> conversion-simplify(from this branch on your machine, do git pull origin main), then after you've merged everything locally and committed those changes to the conversion-simplify branch, push them to conversion-simplify on github, and then finally complete the pull request here. There will no longer be merge conflicts with main.

I agree that rebasing will work but it's also confusing.

To save yourself heartache, make a zip archive of your local repo before you do the git pull in case the resulting merge conflicts are too confusing. I'm trying it now on my machine and it does not seem too bad, but I'm not familiar enough with the code to whip off the merge quickly without some research.

@alexhernandezgarcia alexhernandezgarcia changed the base branch from main to conversions-simplify-merge December 9, 2023 18:22
@alexhernandezgarcia
Copy link
Owner Author

alexhernandezgarcia commented Dec 9, 2023

So I am doing this the way it is easiest and safest to me.

  1. Create auxiliary branch off current main (conversions-simplify-merge).
  2. Resolve conflicts and merge this conversions-simplify into conversions-simplify-merge (copy of main)
  3. Implement rest of changes related to the simplification of state conversions (on crystal environments) in a new branch off conversions-simplify-merge and merge into main in a new PR (to be done).

@alexhernandezgarcia alexhernandezgarcia changed the title Simplify state conversions Simplify state conversions (excludes Crystal environments) Dec 9, 2023
@alexhernandezgarcia alexhernandezgarcia merged commit fe105d1 into conversions-simplify-merge Dec 9, 2023
1 check failed
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.

4 participants