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

Remove seemingly unnecessary parsing of material name string #219

Merged
merged 6 commits into from Sep 15, 2022

Conversation

phoebe-p
Copy link
Member

@phoebe-p phoebe-p commented Aug 4, 2022

Currently, when trying to get parameters using the material_system module, the get_parameters function parses the material string, strips out the numbers (to pass them as alloy fractions), and then tries to look up the parameter. This works as expected for Solcore built-in materials, and custom materials which do not have numbers in the name. However, if you define a custom material with numbers in the name (for instance 'Al0.8Ga0.2AsP'), providing not just the optical constant but also further material parameters like bandgaps and effective masses, an error will happen since the numbers will get stripped out and get_parameter attempts to look up parameters under the heading 'AlGaAsP', which is not in the database (and even if it was in the database, it would not be the material entry we want to get the parameter from!).

This behaviour seems to exist so that you could define a material as something like material('In0.1Ga0.9As') and let Solcore figure out the alloy fractions, rather than specifying material('InGaAs')(In=0.1) but actually this sort of usage doesn't happen in any current tests or examples (maybe there is a historical reason for it?). Removing this step (stripping out the numbers from the material name) altogether currently only breaks the create_adachi_alpha function, which should be pretty easy to fix. I just want to make sure there isn't some deeper reason for this behaviour which I am not aware of.

@codecov
Copy link

codecov bot commented Aug 12, 2022

Codecov Report

Merging #219 (df5cc8a) into develop (c0c05aa) will decrease coverage by 0.10%.
The diff coverage is 90.90%.

@@             Coverage Diff             @@
##           develop     #219      +/-   ##
===========================================
- Coverage    45.86%   45.75%   -0.11%     
===========================================
  Files           84       84              
  Lines         9101     9090      -11     
===========================================
- Hits          4174     4159      -15     
- Misses        4927     4931       +4     
Impacted Files Coverage Δ
solcore/material_system/material_system.py 69.69% <ø> (-1.69%) ⬇️
solcore/absorption_calculator/adachi_alpha.py 76.28% <89.47%> (-1.38%) ⬇️
solcore/parameter_system/parameter_system.py 74.72% <100.00%> (-0.52%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@phoebe-p phoebe-p requested a review from dalonsoa August 12, 2022 07:27
Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

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

Main change is related to update the dosctrings.

Having said that, the fact that the approach you are removing is not used in the tests does not mean that the end users are not using it. I agree it is unnecessary and should be removed, but it is also a breaking change that might affect other people.

I suggest the following:

  • Add a warning that pops up when using get_parameter explaining the change and how it needs to be used now.
  • Move the version number one step, to 5.8.0

@@ -53,6 +53,7 @@ def __init__(self, sources: Optional[Callable] = None):
"([A-Z][a-z]*)")

def get_parameter(self, material, parameter, verbose=False, **others):

Copy link
Collaborator

@dalonsoa dalonsoa Aug 12, 2022

Choose a reason for hiding this comment

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

Why is there a blank line here?

Anyway, since this functionhas changed its behavior - now providing "In0.2GaAsP0.1" will not be enough to retrieve the material, the docstring will need to be updated explaining what it expect for inputs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Blank line was accidental... I have updated the docstring and added a DeprecationWarning.

solcore/parameter_system/parameter_system.py Outdated Show resolved Hide resolved
@phoebe-p phoebe-p requested a review from dalonsoa August 21, 2022 08:24
@phoebe-p
Copy link
Member Author

Ok, have made the suggested changes and bumped version to 5.8.0.

Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

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

Just spotted an error in the Adachi part. I'm sorry I missed that in the first pass.

Good used of the warning!!

solcore/absorption_calculator/adachi_alpha.py Outdated Show resolved Hide resolved
@phoebe-p
Copy link
Member Author

Good catch, thanks - I have just removed checking for the string. Hopefully this does not break functionality anyone is currently using, but in order to look up the parameters in that function the material should be in the database anyway, so even if anyone is passing the name as a string it should be a simple fix.

Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

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

All looks good!

@phoebe-p phoebe-p merged commit 95a2b01 into develop Sep 15, 2022
@phoebe-p phoebe-p deleted the mat_strings branch February 13, 2023 05:20
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.

None yet

2 participants