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

Add telemetry #4441

Merged
merged 30 commits into from
Nov 12, 2024
Merged

Add telemetry #4441

merged 30 commits into from
Nov 12, 2024

Conversation

valentinsulzer
Copy link
Member

@valentinsulzer valentinsulzer commented Sep 15, 2024

Description

Adds very basic telemetry - records when a simulation is solved.

The following section has been added to the user guide to explain the telemetry we are doing:

PyBaMM collects anonymous usage data to help improve the library. This telemetry is enabled by default but can be easily disabled. Here's what you need to know:

  • What is collected: Basic usage information like PyBaMM version, Python version, and which functions are run.
  • Why: To understand how PyBaMM is used and prioritize development efforts.
  • Opt-out: To disable telemetry, set the environment variable PYBAMM_OPTOUT_TELEMETRY=true or use pybamm.telemetry.disable() in your code.
  • Privacy: No personal information (name, email, etc) or sensitive information (parameter values, simulation results) is ever collected.

Copy link

codecov bot commented Sep 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.27%. Comparing base (9ac0b5b) to head (1022c6b).
Report is 31 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4441   +/-   ##
========================================
  Coverage    99.27%   99.27%           
========================================
  Files          300      302    +2     
  Lines        22795    22868   +73     
========================================
+ Hits         22630    22703   +73     
  Misses         165      165           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@agriyakhetarpal
Copy link
Member

agriyakhetarpal commented Sep 15, 2024

We could also make pybamm.telemetry.disable() a top-level pytest fixture as a cleaner way to disable telemetry when running tests

@valentinsulzer
Copy link
Member Author

We could also make pybamm.telemetry.disable() a top-level pytest fixture as a cleaner way to disable telemetry when running tests

Yes, but we also want to disable it when our dependencies run their tests, so that wouldn't be enough right?

@agriyakhetarpal
Copy link
Member

agriyakhetarpal commented Sep 15, 2024

We could also make pybamm.telemetry.disable() a top-level pytest fixture as a cleaner way to disable telemetry when running tests

Yes, but we also want to disable it when our dependencies run their tests, so that wouldn't be enough right?

Oh, yes, forgot about that! In that case, we would need both the logic you added and the fixture to call it.

Copy link
Contributor

@kratman kratman left a comment

Choose a reason for hiding this comment

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

I understand why we want to know which parts of PyBaMM our users are using, but I am not sure this is the best approach.

My concerns:

  • I feel like I would be upset to find out a free research tool was tracking my usage and sending it to a server. I think for a paid tool the expectation that they want to know your usage is a little more reasonable.
  • Users installing through pip might not realize we are tracking their usage. It would be better to allow an opt-in instead so that users know we are collecting their data.
  • Are we only going to be tracking simulation data so that we can just keep it in the simulation class or are we going to have to add the tracking to a lot of different places and make sure we add it to new functionality?

examples/scripts/compare_lithium_ion.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
Copy link
Contributor

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

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

Thanks @valentinsulzer. I suggest a timeout with default opt-out so we don't break ppl's CI, see below

src/pybamm/config.py Show resolved Hide resolved
src/pybamm/config.py Outdated Show resolved Hide resolved
@valentinsulzer
Copy link
Member Author

Added an input with timeout but can't figure out why the docs are failing as I can't reproduce it locally

Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

The code looks fine, the only thing problematic here, at least to me, seems to be the dependency added on inputimeout: https://pypi.org/project/inputimeout hasn't had a release in the last six years. Could we replace it with a different dependency that can do the same task? I'm just worried on the prospect of it causing issues with constraints or with us upgrading to new Python versions as they come some time down the line.

Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Thanks, @valentinsulzer! There are many #pragma: no cover statements here, I think they can be cleaned up. We can add this to .github/codecov.yml:

ignore:
  - src/pybamm/config.py
  # and so on

Also, there is another problem here that I feel deserves another look. I tried a notebook from this branch, and there's no option for me to provide a Y/n answer for opting in/out of telemetry. One would have to wait for ten seconds to default to a "no", which isn't a lot, but this doesn't make for good UX. Is there a way to detect if one is in an IPython kernel and reduce the timeout (or accept stdin in a different manner)?

docs/source/user_guide/index.md Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
src/pybamm/config.py Outdated Show resolved Hide resolved
src/pybamm/config.py Outdated Show resolved Hide resolved
src/pybamm/config.py Outdated Show resolved Hide resolved
src/pybamm/telemetry.py Show resolved Hide resolved
@valentinsulzer
Copy link
Member Author

valentinsulzer commented Oct 28, 2024

Updated to work for notebooks. Re: coverage, I don't want to skip the whole file since it's possible to test some parts of the file. I'll look into covering more parts with some pytest magic

agriyakhetarpal
agriyakhetarpal previously approved these changes Nov 3, 2024
Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Thanks, @valentinsulzer! Two more things:

  • I started a PR to include this in the release notes just in case we forget it (please feel free to modify what I wrote and push any changes to it directly): Release notes for next release pybamm.org#214 and I read up a bit on PostHog's data protection policies: https://posthog.com/docs/privacy/gdpr-compliance. Should we switch to their EU-based cloud instance instead of the current US one to better achieve GDPR compliance (not that we collect anything non-anonymised right now, but just in case we start collecting more data points in the future)? We use Plausible for the docs analytics already which is compliant, so that makes an additional case for changing.
  • Since we're tracking when a simulation is solved, it might also make sense to capture the host operating system (just once at the time of initial config setup) since our compiled solvers are in some ways supported differently across platforms and that can help with platform-specific issues later on.

@agriyakhetarpal
Copy link
Member

Thanks, @valentinsulzer, I've approved the code changes already but my points above still apply

@valentinsulzer valentinsulzer merged commit 0eae1a4 into develop Nov 12, 2024
23 checks passed
@valentinsulzer valentinsulzer deleted the telemetry branch November 12, 2024 16:05
@valentinsulzer
Copy link
Member Author

Thanks @agriyakhetarpal , let's chat on the pybamm.org PR about the announcement. Feel free to open additional PRs with more logging as necessary

kratman added a commit to kratman/PyBaMM that referenced this pull request Nov 14, 2024
brosaplanella added a commit to pybamm-team/pybamm.org that referenced this pull request Nov 22, 2024
- [x] Telemetry collection in
pybamm-team/PyBaMM#4441
- [x]  Solver improvements
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.

5 participants