Giter Club home page Giter Club logo

epoch-cheats's Introduction

epoch-cheats

Installation

$ git clone https://github.com/jmsplank/epoch-cheats.git
$ cd epoch-cheats
$ pip install -e .

Usage

In Command Prompt

$ epoch-cheats deck eval tests.test_input.deck

begin: constant
   qe  =  1.602e-19
  mu0  =  1.257e-06
   kb  =  1.381e-23
   pi  =  3.140e+00
    g  =  9.810e+00
end: constant
Successfully evaluated tests/test_input.deck

In Python

Will load an input.deck file from any location and return the evaluated constants as a dict.


# Load Imports
from pathlib import Path
from epoch_cheats import get_deck_constants

# Create Path object pointing to test_input.deck
deck_path = Path("tests/test_input.deck")
# Get the constants block as a dict
constants = get_deck_constants(deck_path)

# constants contains each constant as a key and its value as a float
constants

Output:

{'qe': 1.60217663e-19,
 'mu0': 1.25663706212e-06,
 'kb': 1.380649e-23,
 'pi': 3.14,
 'g': 9.81}

# Extract using the normal syntax
g = constants["g"]
g

Output:

9.81

# use get_constants_sym() to get a dict with sympy symbols as keys
from epoch_cheats import get_deck_constants_sym
sympy_constants = get_deck_constants_sym(deck_path)
sympy_constants

Output:

{qe: 1.60217663e-19,
 mu0: 1.25663706212e-06,
 kb: 1.380649e-23,
 pi: 3.14,
 g: 9.81}

# Access keys using sympy Symbols
from sympy import Symbol
keys = list(sympy_constants.keys())
print("Keys:")
print('\n'.join([f"{k} {type(k)}" for k in keys]))
print("\nGet 'g' using Symbol('g'):")
print(f"g = {sympy_constants[Symbol('g')]}")

Output:

Keys:
qe  <class 'sympy.core.symbol.Symbol'>
mu0 <class 'sympy.core.symbol.Symbol'>
kb  <class 'sympy.core.symbol.Symbol'>
pi  <class 'sympy.core.symbol.Symbol'>
g   <class 'sympy.core.symbol.Symbol'>

Get 'g' using Symbol('g'):
g = 9.81

epoch-cheats's People

Contributors

jmsplank avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.