-
Notifications
You must be signed in to change notification settings - Fork 4
Refactoring GRS with Ensemble Score #10
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
Draft
coreen-mullen
wants to merge
1
commit into
FitSNAP:develop
Choose a base branch
from
coreen-mullen:refactor
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,35 @@ | ||
| #from GRSlib.parallel_tools import ParallelTools | ||
| from GRSlib.Ver0_Files.opt_tools import internal_generate_cell, get_desc_count, * | ||
| from GRSlib.parallel_tools import ParallelTools | ||
| #from GRSlib.motion.lossfunc.moments import Moments | ||
| #from GRSlib.motion.lossfunc import Gradient | ||
| from GRSlib.converters.sections.lammps_base import Base, _extract_compute_np | ||
| from examples.self_test.GRS_protocol import GRSModel, GRSSampler | ||
| import lammps, lammps.mliap | ||
| from lammps.mliap.loader import * | ||
| from functools import partial | ||
| import numpy as np | ||
|
|
||
| import numpy as vnp | ||
| from GRSlib.GRS import * | ||
| #Scoring has to be a class within motion because we want a consistent reference for scores, and this | ||
| #refrence will be LAMMPS using a constructed potential energy surface from the representation loss function. | ||
| #Sub-classes of Scoring will be versions of this representation loss function (Moments, Entropy, etc), allowing | ||
| #for custom verions to be added without trouble. | ||
|
|
||
| n_totconfig = 10 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dont want to bury inputs deep in the code, use the io method and pass the read in config to the functions that need it. |
||
| data_path = 'bcc.data' | ||
| cross_weight =1.000000 | ||
| self_weight = 1.000000 | ||
| randomize_comps= False # # flag to use randomized compositions for elements in the dictionary: target_comps = {'Cr':1.0 } | ||
| mincellsize = 54 | ||
| maxcellsize=55 | ||
| target_comps = {'W:1.0'} | ||
| min_typ_global='box' #box or min | ||
| soft_strength=0.0 | ||
| elems=get_desc_count('coupling_coefficients.yace',return_elems=True) | ||
| nelements= len(elems) | ||
| n_descs= get_desc_count('coupling_coefficients.yace') | ||
| rand_comp =1 | ||
|
|
||
|
|
||
| class Scoring: | ||
|
|
||
| # def __init__(self, pt, config, data, loss_ff, **kwargs): | ||
|
|
@@ -95,3 +113,47 @@ def _extract_commands(self,string): | |
| add_lmp_lines = [x for x in string.splitlines() if x.strip() != ''] | ||
| for line in add_lmp_lines: | ||
| self.lmp.command(line) | ||
|
|
||
| def ensemble_score(self, n_totconfig, data_path, cross_weight, self_weight, randomize_comps, mincellsize, maxcellsize, target_comps, min_typ_global, soft_strength, nelements, n_descs, mask, rand_comp): | ||
| if mask == None: | ||
| mask = range(n_descs) | ||
| self.mask = mask # Generates the multiple structures | ||
| scores = [] # Initialize a list to store scores | ||
|
|
||
| print(f"Starting ensemble_score with {n_totconfig} configurations.") # Debugging line | ||
|
|
||
| for i in range(1, n_totconfig + 1): | ||
| print(f"Configuration {i}/{n_totconfig} - Using indices: {mask}") # Debugging line | ||
|
|
||
| # Generate the cell | ||
| g = internal_generate_cell(i, desired_size=vnp.random.choice(range(mincellsize, maxcellsize)), template=None, desired_comps=target_comps, use_template=None, min_typ=min_typ_global, soft_strength=soft_strength) | ||
| print(g) | ||
| print(f"Cell generated for configuration {i}: {g}") # Debugging line | ||
|
|
||
| em = GRSModel(nelements, n_descs, mask=mask) | ||
| sampler = GRSSampler(em, g) | ||
| em.K_cross = cross_weight | ||
| em.K_self = self_weight | ||
|
|
||
| print(f"Running minimization for configuration {i}.") # Debugging line | ||
| # Run the minimization process | ||
| sampler.run("minimize 1e-6 1e-6 1000 10000") | ||
|
|
||
| print(f"Minimization completed for configuration {i}. Writing data.") # Debugging line | ||
| # Write the data to a file | ||
| sampler.run("write_data %s/sample.%i.dat " % (data_path, i)) | ||
|
|
||
| print(f"Data written for configuration {i}. Updating model.") # Debugging line | ||
| sampler.update_model() # Updating the model combines generated structures | ||
|
|
||
| # Calculate the score for the current configuration | ||
| score = self.get_score(g) # Pass the generated structure to get_score | ||
| print(f"Score for configuration {i}: {score}") # Debugging line | ||
|
|
||
| if score is None: | ||
| print(f"Score for configuration {i} is None.") # Debugging line | ||
|
|
||
| scores.append(score) # Append the score to the list | ||
|
|
||
| print("Final scores list:", scores) # Debugging line | ||
| return scores # Return the list of scores | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These options will need to be moved out of GRS.py. Use the io method and tis sections to append the settings you need, and use the other ones that are already defined.