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

Code scanning alerts #406

Merged
merged 55 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
d00e4a8
reprted by code scanning
DavidPCoster Nov 10, 2023
32d0682
Removed unused variables (comment below describes them already).
djgroen Nov 10, 2023
d23c9d8
reprted by code scanning: print a message rather than completely ignore
DavidPCoster Nov 10, 2023
2365f3b
Merge branch 'code_scanning_alerts' of github.com:UCL-CCS/EasyVVUQ in…
DavidPCoster Nov 10, 2023
dd2a983
reported by code scanning
DavidPCoster Nov 10, 2023
d636994
reported by code scanning
DavidPCoster Nov 10, 2023
0a73190
reported by code scanning
DavidPCoster Nov 10, 2023
b8793d7
reported by code scanning
DavidPCoster Nov 10, 2023
6cb5238
Fixed test_sobol and made it a proper pytest.
djgroen Nov 10, 2023
2f9f39d
Sharpened the assert criterion in test_sobol.
djgroen Nov 10, 2023
f627cbb
Merge branch 'code_scanning_alerts' of github.com:UCL-CCS/EasyVVUQ in…
djgroen Nov 10, 2023
5dd2841
reported by code scanning
DavidPCoster Nov 10, 2023
63be3ea
Merge branch 'code_scanning_alerts' of github.com:UCL-CCS/EasyVVUQ in…
DavidPCoster Nov 10, 2023
1947eda
Removed several more code scanning issues.
djgroen Nov 10, 2023
0adb5cc
Merge branch 'code_scanning_alerts' of github.com:UCL-CCS/EasyVVUQ in…
djgroen Nov 10, 2023
ebea00c
Code scanning.
djgroen Nov 10, 2023
73ab8ce
remove unnecessary import of CleanUp
DavidPCoster Dec 1, 2023
f9e5618
fix problem from code scanning report
DavidPCoster Dec 1, 2023
986f0b7
state_file was removed as an option
DavidPCoster Dec 1, 2023
885e882
minor cleanup for .gitignore
DavidPCoster Dec 1, 2023
52ebc5d
Merge branch 'code_scanning_alerts' of github.com:UCL-CCS/EasyVVUQ in…
djgroen Dec 4, 2023
da44ce8
decreased the number of cases from 1010 to 910 so that the limit of 9…
DavidPCoster Dec 4, 2023
a87239a
Attempted fix to #409.
djgroen Dec 4, 2023
0960178
Merge branch 'code_scanning_alerts' of github.com:UCL-CCS/EasyVVUQ in…
djgroen Dec 4, 2023
63d76b2
Set autoescape to True. D'oh!
djgroen Dec 4, 2023
29d87e9
Update of installation instructions process for EasyVVUQ, remove defu…
JonMcCullough Dec 4, 2023
46695a9
Merge branch 'code_scanning_alerts' of https://github.com/UCL-CCS/Eas…
JonMcCullough Dec 4, 2023
b8343a0
Attempt to remove one warning.
djgroen Dec 4, 2023
cab3168
Merge branch 'code_scanning_alerts' of github.com:UCL-CCS/EasyVVUQ in…
djgroen Dec 4, 2023
4d1d5d5
Update coveralls.yml
JonMcCullough Dec 4, 2023
5c6c117
Update python-package.yml
JonMcCullough Dec 4, 2023
f152d70
Addressing code scanning alert #146.
djgroen Dec 4, 2023
b7e310a
Merge branch 'code_scanning_alerts' of github.com:UCL-CCS/EasyVVUQ in…
djgroen Dec 4, 2023
80067d7
Code scanning issue #147.
djgroen Dec 4, 2023
134dd30
Fixed several unused variable issues.
djgroen Dec 4, 2023
256d835
Update sql.py to remove legacy implementation warnings
JonMcCullough Dec 4, 2023
c09cc37
Merge branch 'code_scanning_alerts' of https://github.com/UCL-CCS/Eas…
JonMcCullough Dec 4, 2023
6d33000
Clean sql.py file
JonMcCullough Dec 4, 2023
aa13ffc
Edit qmc.py to correct legacy deprecation warning
JonMcCullough Dec 4, 2023
99aa7c2
only print diagnostic information when EasyVVUQ_Debug set
DavidPCoster Dec 4, 2023
1614a29
only print diagnostic information when EasyVVUQ_Debug set
DavidPCoster Dec 4, 2023
c477522
replace .append by .concat
DavidPCoster Dec 4, 2023
bb5c017
only print diagnostic information when EasyVVUQ_Debug set
DavidPCoster Dec 4, 2023
0dba9c5
got this one working again
DavidPCoster Dec 4, 2023
7f8ea9b
tomli seems to be required
DavidPCoster Dec 4, 2023
9f70130
Modify test value of N to remove warning on number of samples not bei…
JonMcCullough Dec 4, 2023
39911e1
Merge branch 'code_scanning_alerts' of https://github.com/UCL-CCS/Eas…
JonMcCullough Dec 4, 2023
232d1e9
drop a nuisance field from the params
DavidPCoster Dec 4, 2023
2cc076c
Merge branch 'code_scanning_alerts' of github.com:UCL-CCS/EasyVVUQ in…
DavidPCoster Dec 4, 2023
f690e2c
add fipy as a requirement for one of the tests
DavidPCoster Dec 4, 2023
f4c2a88
test case now works
DavidPCoster Dec 4, 2023
5511dc0
Simple typo fix.
djgroen Dec 5, 2023
dcecc7a
place the 'Sensitivity Analysis: Derivative based' code in a try/exce…
DavidPCoster Dec 5, 2023
12c1737
get the path to the campaign.db from an environment variable DIR; upd…
DavidPCoster Dec 5, 2023
185c5a8
resolve conflict
DavidPCoster Dec 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions easyvvuq/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def git_get_keywords(versionfile_abs):
keywords["date"] = mo.group(1)
f.close()
except EnvironmentError:
pass
print('EnvironmentError raised and ignored')
return keywords


Expand Down Expand Up @@ -513,7 +513,7 @@ def get_versions():
if cfg.parentdir_prefix:
return versions_from_parentdir(cfg.parentdir_prefix, root, verbose)
except NotThisMethod:
pass
print('NotThisMethod raised and ignored')

return {"version": "0+unknown", "full-revisionid": None,
"dirty": None,
Expand Down
4 changes: 3 additions & 1 deletion easyvvuq/actions/execute_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def start(self, previous=None):
try:
previous['encoder_filename'] = self.encoder.target_filename
except AttributeError:
pass
print('AttributeError raised and ignored')
return previous

def finished(self):
Expand Down Expand Up @@ -233,6 +233,8 @@ def start(self, previous=None):
self.ret = subprocess.run(
self.full_cmd, cwd=target_dir,
stdout=stdout, stderr=stderr)
if isinstance(self.stdout, str): close(stdout)
if isinstance(self.stderr, str): close(stderr)
return previous

def finished(self):
Expand Down
4 changes: 1 addition & 3 deletions easyvvuq/db/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import numpy as np
from sqlalchemy.sql import case
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import sessionmaker, declarative_base
from sqlalchemy import MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import text
from sqlalchemy.engine import Engine
from sqlalchemy import event
Expand Down
4 changes: 2 additions & 2 deletions easyvvuq/sampling/mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ def update(self, result, invalid):
ignored_runs += list(result.loc[result[('chain_id', 0)]
== chain_id]['run_id'].values)
except KeyError:
pass
print('KeyError raised and ignored')
try:
ignored_runs += list(invalid.loc[invalid[('chain_id', 0)]
== chain_id]['run_id'].values)
except KeyError:
pass
print('KeyError raised and ignored')
ignored_runs = [run[0] for run in ignored_runs]
self.iteration += 1
return ignored_runs
Expand Down
44 changes: 15 additions & 29 deletions tests/sc/test_sobol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import easyvvuq as uq
import numpy as np
import chaospy as cp

from easyvvuq.actions import CreateRunDirectory, Encode, Decode, CleanUp, ExecuteLocal, Actions
Fixed Show fixed Hide fixed

def print_exact_sobols():
V_i = np.zeros(d)
Expand All @@ -18,9 +18,7 @@
print('Exact 1st-order Sobol indices: ', V_i / V)


if __name__ == '__main__':
import matplotlib.pyplot as plt
plt.close('all')
def test_sobol_basic():

# number of unknown variables
d = 5
Expand Down Expand Up @@ -79,20 +77,17 @@
target_filename='sobol_in.json')
decoder = uq.decoders.SimpleCSV(target_filename=output_filename,
output_columns=output_columns)
execute = ExecuteLocal(f"{HOME}/sobol_model.py sobol_in.json")

# Add the SC app (automatically set as current app)
my_campaign.add_app(name="sc",
params=params,
encoder=encoder,
decoder=decoder)
actions = Actions(CreateRunDirectory(HOME),
Encode(encoder), execute, Decode(decoder))

campaign = uq.Campaign(name='sc', params=params, actions=actions)

# Create the sampler
vary = {
"x1": cp.Uniform(0.0, 1.0),
"x2": cp.Uniform(0.0, 1.0),
"x3": cp.Uniform(0.0, 1.0),
"x4": cp.Uniform(0.0, 1.0),
"x5": cp.Uniform(0.0, 1.0)}
"x2": cp.Uniform(0.0, 1.0)}

"""
SPARSE GRID PARAMETERS
Expand All @@ -102,32 +97,23 @@
of 1D collocation points per level. Used to make e.g. clenshaw-curtis
quadrature nested.
"""

my_sampler = uq.sampling.SCSampler(vary=vary, polynomial_order=2,
quadrature_rule="G", sparse=False,
growth=False)

# Associate the sampler with the campaign
my_campaign.set_sampler(my_sampler)
campaign.set_sampler(my_sampler)

# Will draw all (of the finite set of samples)
my_campaign.draw_samples()
my_campaign.populate_runs_dir()

# Use this instead to run the samples using EasyVVUQ on the localhost
my_campaign.apply_for_each_run_dir(uq.actions.ExecuteLocal(
"tests/sc/sobol_model.py sobol_in.json"))

my_campaign.collate()
campaign.execute().collate()

# Post-processing analysis
analysis = uq.analysis.SCAnalysis(sampler=my_sampler, qoi_cols=output_columns)

my_campaign.apply_analysis(analysis)

results = my_campaign.get_last_analysis()
results = campaign.analyse(qoi_cols=output_columns)

print(results.sobols_first())

print_exact_sobols()
assert results.sobols_first()["f"]["x1"] > 0.5

plt.show()
if __name__ == '__main__':
test_sobol_basic()
2 changes: 1 addition & 1 deletion tests/test_actions_execute_slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def test_action_status_slurm(mock_subprocess_run):
mock_subprocess_run.return_value = slurm_result

action = ExecuteSLURM('tutorials/epidemic/example.slurm', '$target_dir')
previous = {'rundir': '/tmp'}
# previous = {'rundir': '/tmp'}
# action.start(previous)
# assert(status.job_id == '65541')
2 changes: 1 addition & 1 deletion tests/test_ensemble_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
def test_confidence_interval():
dist = np.array([])
with pytest.raises(ValueError):
stat, low, high = confidence_interval(dist, 0.0, 0.05)
confidence_interval(dist, 0.0, 0.05)
dist = np.array([0.0])
stat, low, high = confidence_interval(dist, 0.0, 0.05)
assert (stat == low == high == 0.0)
Expand Down
1 change: 0 additions & 1 deletion tests/test_mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np
import chaospy as cp
import json
import matplotlib.pyplot as plt
import pytest
import sys
from easyvvuq.actions import ExecutePython, Actions
Expand Down
1 change: 0 additions & 1 deletion tests/test_sampling_mc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
import chaospy as cp
from easyvvuq.sampling import MCSampler
from easyvvuq.sampling.base import Vary


def test_sampling():
Expand Down
1 change: 0 additions & 1 deletion tests/test_sampling_qmc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
import chaospy as cp
from easyvvuq.sampling import QMCSampler
from easyvvuq.sampling.base import Vary


def test_init():
Expand Down
7 changes: 1 addition & 6 deletions tests/test_vector.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import easyvvuq as uq
import chaospy as cp
import os
import sys
import pytest
import logging
from pprint import pformat, pprint
from .gauss.encoder_gauss import GaussEncoder
from .gauss.decoder_gauss import GaussDecoder
from easyvvuq.decoders.json import JSONDecoder
from easyvvuq.actions import Actions, Encode, Decode, CreateRunDirectory

__copyright__ = """
Expand Down Expand Up @@ -88,7 +83,7 @@ def test_gauss_vector_sc(tmpdir):
data = my_campaign.get_collation_result()
analysis = uq.analysis.SCAnalysis(sampler=sampler, qoi_cols=["numbers"])
my_campaign.apply_analysis(analysis)
results = my_campaign.get_last_analysis()
my_campaign.get_last_analysis()


def test_gauss_vector_pce(tmpdir):
Expand Down
2 changes: 1 addition & 1 deletion tutorials/fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def solve_Te(Qe_tot=2e6, H0=0, Hw=0.1, Te_bc=100, chi=1, a0=1, R0=3, E0=1.5, b_p
return Te.value, ne.value, mesh.cellCenters.value[0], mesh.cellCenters.value[0]/a

if __name__ == '__main__':
Te, ne, rho, rho_norm = solve_Te()
solve_Te()

"""
to test:
Expand Down
25 changes: 13 additions & 12 deletions versioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def get_root():
print("Warning: build in %s is using versioneer.py from %s"
% (os.path.dirname(me), versioneer_py))
except NameError:
pass
print('NameError raised and ignored')
return root


Expand Down Expand Up @@ -574,7 +574,7 @@ def git_get_keywords(versionfile_abs):
keywords["date"] = mo.group(1)
f.close()
except EnvironmentError:
pass
print('EnvironmentError raised and ignored')
return keywords


Expand Down Expand Up @@ -908,7 +908,7 @@ def get_versions():
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
verbose)
except NotThisMethod:
pass
print('NotThisMethod raised and ignored')

try:
root = os.path.realpath(__file__)
Expand All @@ -927,13 +927,13 @@ def get_versions():
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
return render(pieces, cfg.style)
except NotThisMethod:
pass
print('NotThisMethod raised and ignored')

try:
if cfg.parentdir_prefix:
return versions_from_parentdir(cfg.parentdir_prefix, root, verbose)
except NotThisMethod:
pass
print('NotThisMethod raised and ignored')

return {"version": "0+unknown", "full-revisionid": None,
"dirty": None,
Expand Down Expand Up @@ -966,7 +966,7 @@ def git_get_keywords(versionfile_abs):
keywords["date"] = mo.group(1)
f.close()
except EnvironmentError:
pass
print('EnvironmentError raised and ignored')
return keywords


Expand Down Expand Up @@ -1146,7 +1146,7 @@ def do_vcs_install(manifest_in, versionfile_source, ipy):
present = True
f.close()
except EnvironmentError:
pass
print('EnvironmentError raised and ignored')
if not present:
f = open(".gitattributes", "a+")
f.write("%s export-subst\n" % versionfile_source)
Expand Down Expand Up @@ -1437,15 +1437,15 @@ def get_versions(verbose=False):
print("got version from expanded keyword %s" % ver)
return ver
except NotThisMethod:
pass
print('NotThisMethod raised and ignored')

try:
ver = versions_from_file(versionfile_abs)
if verbose:
print("got version from file %s %s" % (versionfile_abs, ver))
return ver
except NotThisMethod:
pass
print('NotThisMethod raised and ignored')

from_vcs_f = handlers.get("pieces_from_vcs")
if from_vcs_f:
Expand All @@ -1456,7 +1456,7 @@ def get_versions(verbose=False):
print("got version from VCS %s" % ver)
return ver
except NotThisMethod:
pass
print('NotThisMethod raised and ignored')

try:
if cfg.parentdir_prefix:
Expand All @@ -1465,7 +1465,7 @@ def get_versions(verbose=False):
print("got version from parentdir %s" % ver)
return ver
except NotThisMethod:
pass
print('NotThisMethod raised and ignored')

if verbose:
print("unable to compute version")
Expand Down Expand Up @@ -1750,7 +1750,8 @@ def do_setup():
for include in line.split()[1:]:
simple_includes.add(include)
except EnvironmentError:
pass
print('EnvironmentError raised and ignored')

# That doesn't cover everything MANIFEST.in can do
# (http://docs.python.org/2/distutils/sourcedist.html#commands), so
# it might give some false negatives. Appending redundant 'include'
Expand Down
Loading