From c225fd9ac7be7e33b19a08a331e9738dede7dd68 Mon Sep 17 00:00:00 2001 From: Chaoming Wang Date: Sat, 8 Jun 2024 16:29:39 +0800 Subject: [PATCH] update doc --- brainunit/_base.py | 12 +- brainunit/math/_utils.py | 2 +- docs/apis/brainunit.rst | 42 ++ docs/apis/functional.rst | 76 -- docs/apis/{init.rst => math.rst} | 58 +- docs/apis/metric.rst | 121 --- docs/apis/optim.rst | 50 -- docs/auto_generater.py | 41 +- docs/tutorials/physical_units.ipynb | 1054 ++++++++++++++++++--------- docs/tutorials/physical_units.rst | 7 - 10 files changed, 811 insertions(+), 652 deletions(-) create mode 100644 docs/apis/brainunit.rst delete mode 100644 docs/apis/functional.rst rename docs/apis/{init.rst => math.rst} (93%) delete mode 100644 docs/apis/metric.rst delete mode 100644 docs/apis/optim.rst delete mode 100644 docs/tutorials/physical_units.rst diff --git a/brainunit/_base.py b/brainunit/_base.py index 5dd68a0..fa0764c 100644 --- a/brainunit/_base.py +++ b/brainunit/_base.py @@ -947,11 +947,17 @@ def __init__( self, value: Any, dtype: bst.typing.DTypeLike = None, - unit: Dimension = DIMENSIONLESS, + unit: Union[Dimension, 'Unit'] = DIMENSIONLESS, ): + if isinstance(unit, Unit): + s = unit.value + unit = unit.unit + else: + s = None + if isinstance(value, numbers.Number) and _allow_python_scalar_value: self._unit = unit - self._value = value + self._value = (value if s is None else (value * s)) return if isinstance(value, (list, tuple)): @@ -984,7 +990,7 @@ def __init__( raise TypeError(f"Invalid type for value: {type(value)}") # value - self._value = value + self._value = (value if s is None else (value * s)) # unit self._unit = unit diff --git a/brainunit/math/_utils.py b/brainunit/math/_utils.py index 30dc2e4..f30ec85 100644 --- a/brainunit/math/_utils.py +++ b/brainunit/math/_utils.py @@ -19,7 +19,7 @@ from jax.tree_util import tree_map -from brainunit import Quantity +from .._base import Quantity def _as_jax_array_(obj): diff --git a/docs/apis/brainunit.rst b/docs/apis/brainunit.rst new file mode 100644 index 0000000..5507e43 --- /dev/null +++ b/docs/apis/brainunit.rst @@ -0,0 +1,42 @@ +``brainunit`` module +==================== + +.. currentmodule:: brainunit +.. automodule:: brainunit + + + +Base Classes +------------ + +.. autosummary:: + :toctree: generated/ + :nosignatures: + :template: classtemplate.rst + + Quantity + Unit + DIMENSIONLESS + DimensionMismatchError + + +Helper Functions +---------------- + +.. autosummary:: + :toctree: generated/ + :nosignatures: + :template: classtemplate.rst + + get_or_create_dimension + get_unit + get_basic_unit + is_unitless + have_same_unit + in_unit + in_best_unit + register_new_unit + check_units + is_scalar_type + fail_for_dimension_mismatch + diff --git a/docs/apis/functional.rst b/docs/apis/functional.rst deleted file mode 100644 index ee1bcf6..0000000 --- a/docs/apis/functional.rst +++ /dev/null @@ -1,76 +0,0 @@ -``brainunit.functional`` module -================================ - -.. currentmodule:: brainunit.functional -.. automodule:: brainunit.functional - -Activation Functions --------------------- - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - tanh - relu - squareplus - softplus - soft_sign - sigmoid - silu - swish - log_sigmoid - elu - leaky_relu - hard_tanh - celu - selu - gelu - glu - logsumexp - log_softmax - softmax - standardize - one_hot - relu6 - hard_sigmoid - hard_silu - hard_swish - hard_shrink - rrelu - mish - soft_shrink - prelu - tanh_shrink - softmin - - -Normalization -------------- - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - weight_standardization - - -Spike Operations ----------------- - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - spike_bitwise_or - spike_bitwise_and - spike_bitwise_iand - spike_bitwise_not - spike_bitwise_xor - spike_bitwise_ixor - spike_bitwise - - diff --git a/docs/apis/init.rst b/docs/apis/math.rst similarity index 93% rename from docs/apis/init.rst rename to docs/apis/math.rst index 065a0a9..620915f 100644 --- a/docs/apis/init.rst +++ b/docs/apis/math.rst @@ -1,29 +1,29 @@ -``brainunit.init`` module -========================== - -.. currentmodule:: brainunit.init -.. automodule:: brainunit.init - -.. autosummary:: - :toctree: generated/ - - parameter - state - noise - to_size - Initializer - ZeroInit - Constant - Identity - Normal - TruncatedNormal - Uniform - VarianceScaling - KaimingUniform - KaimingNormal - XavierUniform - XavierNormal - LecunUniform - LecunNormal - Orthogonal - DeltaOrthogonal +``brainunit.init`` module +========================== + +.. currentmodule:: brainunit.init +.. automodule:: brainunit.init + +.. autosummary:: + :toctree: generated/ + + parameter + state + noise + to_size + Initializer + ZeroInit + Constant + Identity + Normal + TruncatedNormal + Uniform + VarianceScaling + KaimingUniform + KaimingNormal + XavierUniform + XavierNormal + LecunUniform + LecunNormal + Orthogonal + DeltaOrthogonal diff --git a/docs/apis/metric.rst b/docs/apis/metric.rst deleted file mode 100644 index bcda0d1..0000000 --- a/docs/apis/metric.rst +++ /dev/null @@ -1,121 +0,0 @@ -``brainunit.metric`` module -============================ - -.. currentmodule:: brainunit.metric -.. automodule:: brainunit.metric - -Classification Losses ---------------------- - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - sigmoid_binary_cross_entropy - hinge_loss - perceptron_loss - softmax_cross_entropy - softmax_cross_entropy_with_integer_labels - multiclass_hinge_loss - multiclass_perceptron_loss - poly_loss_cross_entropy - kl_divergence - kl_divergence_with_log_targets - convex_kl_divergence - ctc_loss - ctc_loss_with_forward_probs - sigmoid_focal_loss - - -Correlation ------------ - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - cross_correlation - voltage_fluctuation - matrix_correlation - weighted_correlation - functional_connectivity - functional_connectivity_dynamics - - -Fenchel-Young Loss ------------------- - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - make_fenchel_young_loss - - -Spike Firing ------------- - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - raster_plot - firing_rate - - -Local Field Potential ---------------------- - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - unitary_LFP - - -Ranking Losses --------------- - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - ranking_softmax_loss - - -Regression Losses ------------------ - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - squared_error - absolute_error - l1_loss - l2_loss - l2_norm - huber_loss - log_cosh - cosine_similarity - cosine_distance - - -Smoothing Losses ----------------- - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - smooth_labels - - diff --git a/docs/apis/optim.rst b/docs/apis/optim.rst deleted file mode 100644 index 31c7a53..0000000 --- a/docs/apis/optim.rst +++ /dev/null @@ -1,50 +0,0 @@ -``brainunit.optim`` module -=========================== - -.. currentmodule:: brainunit.optim -.. automodule:: brainunit.optim - -SGD Optimizers --------------- - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - to_same_dict_tree - OptimState - Optimizer - SGD - Momentum - MomentumNesterov - Adagrad - Adadelta - RMSProp - Adam - LARS - Adan - AdamW - - -Learning Rate Schedulers ------------------------- - -.. autosummary:: - :toctree: generated/ - :nosignatures: - :template: classtemplate.rst - - LearningRateScheduler - ConstantLR - StepLR - MultiStepLR - CosineAnnealingLR - CosineAnnealingWarmRestarts - ExponentialLR - ExponentialDecayLR - InverseTimeDecayLR - PolynomialDecayLR - PiecewiseConstantLR - - diff --git a/docs/auto_generater.py b/docs/auto_generater.py index b3220c7..212649c 100644 --- a/docs/auto_generater.py +++ b/docs/auto_generater.py @@ -319,47 +319,10 @@ def _section(header, numpy_mod, brainpy_mod, jax_mod, klass=None, is_jax=False): def main(): os.makedirs('apis/auto/', exist_ok=True) - _write_module(module_name='brainunit.init', - filename='apis/init.rst', + _write_module(module_name='brainunit', + filename='apis/math.rst', header='``brainunit.init`` module') - module_and_name = [ - ('_classification', 'Classification Losses'), - ('_correlation', 'Correlation'), - ('_fenchel_young', 'Fenchel-Young Loss'), - ('_firings', 'Spike Firing'), - ('_lfp', 'Local Field Potential'), - ('_ranking', 'Ranking Losses'), - ('_regression', 'Regression Losses'), - ('_smoothing', 'Smoothing Losses'), - ] - _write_submodules(module_name='brainunit.metric', - filename='apis/metric.rst', - header='``brainunit.metric`` module', - submodule_names=[k[0] for k in module_and_name], - section_names=[k[1] for k in module_and_name]) - - module_and_name = [ - ('_activations', 'Activation Functions'), - ('_normalization', 'Normalization'), - ('_spikes', 'Spike Operations'), - ] - _write_submodules(module_name='brainunit.functional', - filename='apis/functional.rst', - header='``brainunit.functional`` module', - submodule_names=[k[0] for k in module_and_name], - section_names=[k[1] for k in module_and_name]) - - module_and_name = [ - ('_sgd_optimizer', 'SGD Optimizers'), - ('_lr_scheduler', 'Learning Rate Schedulers'), - ] - _write_submodules(module_name='brainunit.optim', - filename='apis/optim.rst', - header='``brainunit.optim`` module', - submodule_names=[k[0] for k in module_and_name], - section_names=[k[1] for k in module_and_name]) - if __name__ == '__main__': main() diff --git a/docs/tutorials/physical_units.ipynb b/docs/tutorials/physical_units.ipynb index 36b33ac..12edc32 100644 --- a/docs/tutorials/physical_units.ipynb +++ b/docs/tutorials/physical_units.ipynb @@ -33,24 +33,22 @@ "## Importing units\n", "Braincore generates standard names for units, combining the unit name (e.g. “siemens”) with a prefixes (e.g. “m”), and also generates squared and cubed versions by appending a number. For example, the units “msiemens”, “siemens2”, “usiemens3” are all predefined. You can import these units from the package `briancore.units` – accordingly, an `from braincore.units import *` will result in everything being imported.\n", "\n", - "We recommend importing only the units you need, to have a cleaner namespace. For example, `import braincore.units as U` and then using `U.msiemens` instead of `msiemens`." + "We recommend importing only the units you need, to have a cleaner namespace. For example, `import braincore.units as U` and then using `bu.msiemens` instead of `msiemens`." ] }, { "cell_type": "code", "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "c:\\Users\\13107\\.conda\\envs\\brainpy-dev\\lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:18:06.720762Z", + "start_time": "2024-06-08T08:18:06.566328Z" } - ], - "source": "import brainunit as U" + }, + "outputs": [], + "source": [ + "import brainunit as bu" + ] }, { "cell_type": "markdown", @@ -77,7 +75,7 @@ } ], "source": [ - "tau = 20 * U.ms\n", + "tau = 20 * bu.ms\n", "tau" ] }, @@ -98,7 +96,7 @@ } ], "source": [ - "rates = [10, 20, 30] * U.Hz\n", + "rates = [10, 20, 30] * bu.Hz\n", "rates" ] }, @@ -120,7 +118,7 @@ } ], "source": [ - "rates = [[10, 20, 30], [20, 30, 40]] * U.Hz\n", + "rates = [[10, 20, 30], [20, 30, 40]] * bu.Hz\n", "rates" ] }, @@ -166,7 +164,7 @@ ], "source": [ "try:\n", - " 3 * U.kgram + 3 * U.amp \n", + " 3 * bu.kgram + 3 * bu.amp\n", "except Exception as e:\n", " print(e)" ] @@ -296,8 +294,8 @@ "outputs": [], "source": [ "import jax.numpy as jnp\n", - "import braincore as bc\n", - "bc.environ.set(precision=64) # we recommend using 64-bit precision for better numerical stability" + "import brainstate as bst\n", + "bst.environ.set(precision=64) # we recommend using 64-bit precision for better numerical stability" ] }, { @@ -326,7 +324,7 @@ } ], "source": [ - "5 * U.ms" + "5 * bu.ms" ] }, { @@ -353,7 +351,7 @@ } ], "source": [ - "jnp.float64(5) * U.ms" + "jnp.float64(5) * bu.ms" ] }, { @@ -380,7 +378,7 @@ } ], "source": [ - "jnp.array([1, 2, 3]) * U.ms" + "jnp.array([1, 2, 3]) * bu.ms" ] }, { @@ -407,7 +405,7 @@ } ], "source": [ - "[1, 2, 3] * U.ms" + "[1, 2, 3] * bu.ms" ] }, { @@ -417,15 +415,6 @@ "#### Direct Quantity Creation\n" ] }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [], - "source": [ - "from braincore.units import Quantity" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -435,7 +424,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -444,13 +433,13 @@ "Quantity(5.)" ] }, - "execution_count": 17, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "Quantity(5)" + "bu.Quantity(5)" ] }, { @@ -468,7 +457,7 @@ { "data": { "text/plain": [ - "5. * second" + "5. * msecond" ] }, "execution_count": 18, @@ -477,7 +466,7 @@ } ], "source": [ - "Quantity(5, unit=U.ms.unit)" + "bu.Quantity(5, unit=bu.ms)" ] }, { @@ -495,7 +484,7 @@ { "data": { "text/plain": [ - "ArrayImpl([1., 2., 3.]) * second" + "ArrayImpl([1., 2., 3.]) * msecond" ] }, "execution_count": 19, @@ -504,7 +493,7 @@ } ], "source": [ - "Quantity(jnp.array([1, 2, 3]), unit=U.ms.unit)" + "bu.Quantity(jnp.array([1, 2, 3]), unit=bu.ms)" ] }, { @@ -522,7 +511,7 @@ { "data": { "text/plain": [ - "ArrayImpl([1., 2., 3.]) * second" + "ArrayImpl([1., 2., 3.]) * msecond" ] }, "execution_count": 20, @@ -531,7 +520,7 @@ } ], "source": [ - "Quantity([1, 2, 3], unit=U.ms.unit)" + "bu.Quantity([1, 2, 3], unit=bu.ms)" ] }, { @@ -558,7 +547,7 @@ } ], "source": [ - "Quantity([500 * U.ms, 1 * U.second])" + "bu.Quantity([500 * bu.ms, 1 * bu.second])" ] }, { @@ -585,7 +574,7 @@ } ], "source": [ - "Quantity.with_units(jnp.array([0.5, 1]), second=1)" + "bu.Quantity.with_units(jnp.array([0.5, 1]), second=1)" ] }, { @@ -613,7 +602,7 @@ } ], "source": [ - "Quantity([1, 2, 3])" + "bu.Quantity([1, 2, 3])" ] }, { @@ -633,7 +622,7 @@ } ], "source": [ - "Quantity(jnp.array([1, 2, 3]))" + "bu.Quantity(jnp.array([1, 2, 3]))" ] }, { @@ -653,7 +642,7 @@ } ], "source": [ - "Quantity([])" + "bu.Quantity([])" ] }, { @@ -679,7 +668,7 @@ ], "source": [ "try:\n", - " Quantity([500 * U.ms, 1])\n", + " bu.Quantity([500 * bu.ms, 1])\n", "except Exception as e:\n", " print(e)" ] @@ -699,7 +688,7 @@ ], "source": [ "try:\n", - " Quantity([\"some\", \"nonsense\"])\n", + " bu.Quantity([\"some\", \"nonsense\"])\n", "except Exception as e:\n", " print(e)" ] @@ -719,7 +708,7 @@ ], "source": [ "try:\n", - " Quantity([500 * U.ms, 1 * U.volt])\n", + " bu.Quantity([500 * bu.ms, 1 * bu.volt])\n", "except Exception as e:\n", " print(e)" ] @@ -749,8 +738,8 @@ } ], "source": [ - "a = [20, 30, 40, 50] * U.mV\n", - "b = jnp.arange(4) * U.mV\n", + "a = [20, 30, 40, 50] * bu.mV\n", + "b = jnp.arange(4) * bu.mV\n", "b" ] }, @@ -813,7 +802,7 @@ } ], "source": [ - "a < 35 * U.mV" + "a < 35 * bu.mV" ] }, { @@ -841,8 +830,8 @@ } ], "source": [ - "A = jnp.array([[1, 2], [3, 4]]) * U.mV\n", - "B = jnp.array([[2, 3], [4, 5]]) * U.mV\n", + "A = jnp.array([[1, 2], [3, 4]]) * bu.mV\n", + "B = jnp.array([[2, 3], [4, 5]]) * bu.mV\n", "\n", "A * B" ] @@ -913,8 +902,8 @@ } ], "source": [ - "a = jnp.ones(3, dtype=jnp.int32) * U.mV\n", - "b = jnp.linspace(0, jnp.pi, 3) * U.mV\n", + "a = jnp.ones(3, dtype=jnp.int32) * bu.mV\n", + "b = jnp.linspace(0, jnp.pi, 3) * bu.mV\n", "\n", "b.dtype.name" ] @@ -922,7 +911,12 @@ { "cell_type": "code", "execution_count": 37, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:11.930344Z", + "start_time": "2024-06-08T08:17:11.917832Z" + } + }, "outputs": [ { "data": { @@ -950,13 +944,18 @@ { "cell_type": "code", "execution_count": 38, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:12.930783Z", + "start_time": "2024-06-08T08:17:12.915631Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([[225.53381666, 346.90286176, 31.43644236],\n", - " [258.49739247, 240.52782238, 584.5029428 ]]) * uvolt" + "ArrayImpl([[0.6437081 , 0.66346343, 0.92401136],\n", + " [0.07923831, 0.78219192, 0.28288394]]) * mvolt" ] }, "execution_count": 38, @@ -965,19 +964,24 @@ } ], "source": [ - "a = bc.random.random((2, 3)) * U.mV\n", + "a = bst.random.random((2, 3)) * bu.mV\n", "a" ] }, { "cell_type": "code", "execution_count": 39, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:13.077406Z", + "start_time": "2024-06-08T08:17:13.061209Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "1.68740128 * mvolt" + "3.37549707 * mvolt" ] }, "execution_count": 39, @@ -992,12 +996,17 @@ { "cell_type": "code", "execution_count": 40, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:13.173170Z", + "start_time": "2024-06-08T08:17:13.154985Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "31.43644236 * uvolt" + "79.23830773 * uvolt" ] }, "execution_count": 40, @@ -1012,12 +1021,17 @@ { "cell_type": "code", "execution_count": 41, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:13.258559Z", + "start_time": "2024-06-08T08:17:13.245139Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "0.58450294 * mvolt" + "0.92401136 * mvolt" ] }, "execution_count": 41, @@ -1039,7 +1053,12 @@ { "cell_type": "code", "execution_count": 42, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:13.317596Z", + "start_time": "2024-06-08T08:17:13.303347Z" + } + }, "outputs": [ { "data": { @@ -1055,14 +1074,19 @@ } ], "source": [ - "b = jnp.arange(12).reshape(3, 4) * U.mV\n", + "b = jnp.arange(12).reshape(3, 4) * bu.mV\n", "b" ] }, { "cell_type": "code", "execution_count": 43, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:13.440592Z", + "start_time": "2024-06-08T08:17:13.423512Z" + } + }, "outputs": [ { "data": { @@ -1082,7 +1106,12 @@ { "cell_type": "code", "execution_count": 44, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:13.508794Z", + "start_time": "2024-06-08T08:17:13.493763Z" + } + }, "outputs": [ { "data": { @@ -1102,7 +1131,12 @@ { "cell_type": "code", "execution_count": 45, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:13.635798Z", + "start_time": "2024-06-08T08:17:13.623775Z" + } + }, "outputs": [ { "data": { @@ -1133,7 +1167,12 @@ { "cell_type": "code", "execution_count": 46, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:13.740123Z", + "start_time": "2024-06-08T08:17:13.724137Z" + } + }, "outputs": [ { "data": { @@ -1147,14 +1186,19 @@ } ], "source": [ - "B = Quantity(jnp.arange(3))\n", + "B = bu.Quantity(jnp.arange(3))\n", "B" ] }, { "cell_type": "code", "execution_count": 47, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:13.849402Z", + "start_time": "2024-06-08T08:17:13.835550Z" + } + }, "outputs": [ { "data": { @@ -1168,13 +1212,18 @@ } ], "source": [ - "bc.math.exp(B)" + "bu.math.exp(B)" ] }, { "cell_type": "code", "execution_count": 48, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:13.916280Z", + "start_time": "2024-06-08T08:17:13.899481Z" + } + }, "outputs": [ { "data": { @@ -1188,13 +1237,18 @@ } ], "source": [ - "bc.math.sqrt(B)" + "bu.math.sqrt(B)" ] }, { "cell_type": "code", "execution_count": 49, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:14.031528Z", + "start_time": "2024-06-08T08:17:14.017580Z" + } + }, "outputs": [ { "data": { @@ -1208,8 +1262,8 @@ } ], "source": [ - "C = Quantity(jnp.arange(3))\n", - "bc.math.add(B, C)" + "C = bu.Quantity(jnp.arange(3))\n", + "bu.math.add(B, C)" ] }, { @@ -1223,7 +1277,12 @@ { "cell_type": "code", "execution_count": 50, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:14.092294Z", + "start_time": "2024-06-08T08:17:14.077645Z" + } + }, "outputs": [ { "data": { @@ -1237,14 +1296,19 @@ } ], "source": [ - "a = jnp.arange(10) ** 3 * U.mV\n", + "a = jnp.arange(10) ** 3 * bu.mV\n", "a" ] }, { "cell_type": "code", "execution_count": 51, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:14.246749Z", + "start_time": "2024-06-08T08:17:14.233917Z" + } + }, "outputs": [ { "data": { @@ -1264,7 +1328,12 @@ { "cell_type": "code", "execution_count": 52, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:14.336180Z", + "start_time": "2024-06-08T08:17:14.323023Z" + } + }, "outputs": [ { "data": { @@ -1291,7 +1360,12 @@ { "cell_type": "code", "execution_count": 53, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:14.438363Z", + "start_time": "2024-06-08T08:17:14.423077Z" + } + }, "outputs": [ { "data": { @@ -1308,14 +1382,19 @@ "source": [ "# equivalent to a[0:6:2] = 1000;\n", "# from start to position 6, exclusive, set every 2nd element to 1000\n", - "a[:6:2] = 1000 * U.mV\n", + "a[:6:2] = 1000 * bu.mV\n", "a" ] }, { "cell_type": "code", "execution_count": 54, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:14.497547Z", + "start_time": "2024-06-08T08:17:14.484540Z" + } + }, "outputs": [ { "data": { @@ -1336,7 +1415,12 @@ { "cell_type": "code", "execution_count": 55, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:14.641478Z", + "start_time": "2024-06-08T08:17:14.626722Z" + } + }, "outputs": [ { "name": "stdout", @@ -1370,7 +1454,12 @@ { "cell_type": "code", "execution_count": 56, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:14.689531Z", + "start_time": "2024-06-08T08:17:14.675521Z" + } + }, "outputs": [ { "data": { @@ -1390,14 +1479,19 @@ "source": [ "def f(x, y):\n", " return 10 * x + y\n", - "b = jnp.fromfunction(f, (5, 4), dtype=jnp.int32) * U.mV\n", + "b = jnp.fromfunction(f, (5, 4), dtype=jnp.int32) * bu.mV\n", "b" ] }, { "cell_type": "code", "execution_count": 57, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:14.826661Z", + "start_time": "2024-06-08T08:17:14.810619Z" + } + }, "outputs": [ { "data": { @@ -1417,7 +1511,12 @@ { "cell_type": "code", "execution_count": 58, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:14.904908Z", + "start_time": "2024-06-08T08:17:14.890825Z" + } + }, "outputs": [ { "data": { @@ -1437,7 +1536,12 @@ { "cell_type": "code", "execution_count": 59, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:15.024474Z", + "start_time": "2024-06-08T08:17:15.010562Z" + } + }, "outputs": [ { "data": { @@ -1457,7 +1561,12 @@ { "cell_type": "code", "execution_count": 60, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:15.081864Z", + "start_time": "2024-06-08T08:17:15.069946Z" + } + }, "outputs": [ { "data": { @@ -1485,7 +1594,12 @@ { "cell_type": "code", "execution_count": 61, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:15.180883Z", + "start_time": "2024-06-08T08:17:15.169438Z" + } + }, "outputs": [ { "data": { @@ -1517,7 +1631,12 @@ { "cell_type": "code", "execution_count": 62, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:15.237918Z", + "start_time": "2024-06-08T08:17:15.224044Z" + } + }, "outputs": [ { "data": { @@ -1531,14 +1650,19 @@ } ], "source": [ - "c = jnp.array([[[0, 1, 2], [10, 12, 13]], [[100, 101, 102], [110, 112, 113]]]) * U.mV # a 3D array (two stacked 2D arrays)\n", + "c = jnp.array([[[0, 1, 2], [10, 12, 13]], [[100, 101, 102], [110, 112, 113]]]) * bu.mV # a 3D array (two stacked 2D arrays)\n", "c.shape" ] }, { "cell_type": "code", "execution_count": 63, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:15.378222Z", + "start_time": "2024-06-08T08:17:15.364283Z" + } + }, "outputs": [ { "data": { @@ -1559,7 +1683,12 @@ { "cell_type": "code", "execution_count": 64, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:15.483103Z", + "start_time": "2024-06-08T08:17:15.467641Z" + } + }, "outputs": [ { "data": { @@ -1587,7 +1716,12 @@ { "cell_type": "code", "execution_count": 65, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:15.584500Z", + "start_time": "2024-06-08T08:17:15.568297Z" + } + }, "outputs": [ { "name": "stdout", @@ -1618,14 +1752,19 @@ { "cell_type": "code", "execution_count": 66, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:15.643100Z", + "start_time": "2024-06-08T08:17:15.628497Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([[5., 5., 3., 3.],\n", - " [6., 2., 3., 9.],\n", - " [0., 3., 2., 7.]]) * mvolt" + "ArrayImpl([[0., 8., 8., 9.],\n", + " [1., 6., 2., 0.],\n", + " [2., 0., 5., 0.]]) * mvolt" ] }, "execution_count": 66, @@ -1634,14 +1773,19 @@ } ], "source": [ - "a = jnp.floor(10 * bc.random.random((3, 4))) * U.mV\n", + "a = jnp.floor(10 * bst.random.random((3, 4))) * bu.mV\n", "a" ] }, { "cell_type": "code", "execution_count": 67, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:15.786100Z", + "start_time": "2024-06-08T08:17:15.774172Z" + } + }, "outputs": [ { "data": { @@ -1668,12 +1812,17 @@ { "cell_type": "code", "execution_count": 68, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:15.863373Z", + "start_time": "2024-06-08T08:17:15.851908Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([5., 5., 3., 3., 6., 2., 3., 9., 0., 3., 2., 7.]) * mvolt" + "ArrayImpl([0., 8., 8., 9., 1., 6., 2., 0., 2., 0., 5., 0.]) * mvolt" ] }, "execution_count": 68, @@ -1688,17 +1837,22 @@ { "cell_type": "code", "execution_count": 69, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:15.984087Z", + "start_time": "2024-06-08T08:17:15.972194Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([[5., 5.],\n", - " [3., 3.],\n", - " [6., 2.],\n", - " [3., 9.],\n", - " [0., 3.],\n", - " [2., 7.]]) * mvolt" + "ArrayImpl([[0., 8.],\n", + " [8., 9.],\n", + " [1., 6.],\n", + " [2., 0.],\n", + " [2., 0.],\n", + " [5., 0.]]) * mvolt" ] }, "execution_count": 69, @@ -1713,15 +1867,20 @@ { "cell_type": "code", "execution_count": 70, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:16.070664Z", + "start_time": "2024-06-08T08:17:16.058519Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([[5., 6., 0.],\n", - " [5., 2., 3.],\n", - " [3., 3., 2.],\n", - " [3., 9., 7.]]) * mvolt" + "ArrayImpl([[0., 1., 2.],\n", + " [8., 6., 0.],\n", + " [8., 2., 5.],\n", + " [9., 0., 0.]]) * mvolt" ] }, "execution_count": 70, @@ -1736,7 +1895,12 @@ { "cell_type": "code", "execution_count": 71, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:16.172288Z", + "start_time": "2024-06-08T08:17:16.160362Z" + } + }, "outputs": [ { "data": { @@ -1756,7 +1920,12 @@ { "cell_type": "code", "execution_count": 72, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:16.238443Z", + "start_time": "2024-06-08T08:17:16.224359Z" + } + }, "outputs": [ { "data": { @@ -1792,14 +1961,19 @@ { "cell_type": "code", "execution_count": 73, - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:16.397219Z", + "start_time": "2024-06-08T08:17:16.311537Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([[5., 5., 3., 3.],\n", - " [6., 2., 3., 9.],\n", - " [0., 3., 2., 7.]]) * mvolt" + "ArrayImpl([[0., 8., 8., 9.],\n", + " [1., 6., 2., 0.],\n", + " [2., 0., 5., 0.]]) * mvolt" ] }, "execution_count": 73, @@ -1821,90 +1995,110 @@ }, { "cell_type": "code", - "execution_count": 75, - "metadata": {}, + "execution_count": 74, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:16.418810Z", + "start_time": "2024-06-08T08:17:16.403141Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([[0., 2.],\n", - " [4., 3.]]) * mvolt" + "ArrayImpl([[9., 1.],\n", + " [0., 0.]]) * mvolt" ] }, - "execution_count": 75, + "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "a = jnp.floor(10 * bc.random.random((2, 2))) * U.mV\n", + "a = jnp.floor(10 * bst.random.random((2, 2))) * bu.mV\n", "a" ] }, { "cell_type": "code", - "execution_count": 76, - "metadata": {}, + "execution_count": 75, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:16.579043Z", + "start_time": "2024-06-08T08:17:16.565752Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([[1., 8.],\n", - " [2., 2.]]) * mvolt" + "ArrayImpl([[6., 3.],\n", + " [2., 9.]]) * mvolt" ] }, - "execution_count": 76, + "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "b = jnp.floor(10 * bc.random.random((2, 2))) * U.mV\n", + "b = jnp.floor(10 * bst.random.random((2, 2))) * bu.mV\n", "b" ] }, { "cell_type": "code", - "execution_count": 77, - "metadata": {}, + "execution_count": 76, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:16.673916Z", + "start_time": "2024-06-08T08:17:16.658982Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([[0., 2.],\n", - " [4., 3.],\n", - " [1., 8.],\n", - " [2., 2.]]) * mvolt" + "ArrayImpl([[9., 1.],\n", + " [0., 0.],\n", + " [6., 3.],\n", + " [2., 9.]]) * mvolt" ] }, - "execution_count": 77, + "execution_count": 76, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "bc.math.vstack((a, b))" + "bu.math.vstack((a, b))" ] }, { "cell_type": "code", - "execution_count": 78, - "metadata": {}, + "execution_count": 77, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:16.746660Z", + "start_time": "2024-06-08T08:17:16.732009Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([[0., 2., 1., 8.],\n", - " [4., 3., 2., 2.]]) * mvolt" + "ArrayImpl([[9., 1., 6., 3.],\n", + " [0., 0., 2., 9.]]) * mvolt" ] }, - "execution_count": 78, + "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "bc.math.hstack((a, b))" + "bu.math.hstack((a, b))" ] }, { @@ -1916,29 +2110,39 @@ }, { "cell_type": "code", - "execution_count": 79, - "metadata": {}, + "execution_count": 78, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:16.847453Z", + "start_time": "2024-06-08T08:17:16.835479Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([[0., 2., 1., 8.],\n", - " [4., 3., 2., 2.]]) * mvolt" + "ArrayImpl([[9., 1., 6., 3.],\n", + " [0., 0., 2., 9.]]) * mvolt" ] }, - "execution_count": 79, + "execution_count": 78, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "bc.math.column_stack((a, b)) # with 2D arrays" + "bu.math.column_stack((a, b)) # with 2D arrays" ] }, { "cell_type": "code", - "execution_count": 80, - "metadata": {}, + "execution_count": 79, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:16.933347Z", + "start_time": "2024-06-08T08:17:16.919138Z" + } + }, "outputs": [ { "data": { @@ -1947,21 +2151,26 @@ " [2., 8.]]) * mvolt" ] }, - "execution_count": 80, + "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "a = jnp.array([4., 2.]) * U.mV\n", - "b = jnp.array([2., 8.]) * U.mV\n", - "bc.math.column_stack((a, b)) # returns a 2D array" + "a = jnp.array([4., 2.]) * bu.mV\n", + "b = jnp.array([2., 8.]) * bu.mV\n", + "bu.math.column_stack((a, b)) # returns a 2D array" ] }, { "cell_type": "code", - "execution_count": 81, - "metadata": {}, + "execution_count": 80, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:17.086885Z", + "start_time": "2024-06-08T08:17:17.074655Z" + } + }, "outputs": [ { "data": { @@ -1969,19 +2178,24 @@ "ArrayImpl([4., 2., 2., 8.]) * mvolt" ] }, - "execution_count": 81, + "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "bc.math.hstack((a, b)) # the result is different" + "bu.math.hstack((a, b)) # the result is different" ] }, { "cell_type": "code", - "execution_count": 82, - "metadata": {}, + "execution_count": 81, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:17.150330Z", + "start_time": "2024-06-08T08:17:17.137485Z" + } + }, "outputs": [ { "data": { @@ -1990,7 +2204,7 @@ " [2.]]) * mvolt" ] }, - "execution_count": 82, + "execution_count": 81, "metadata": {}, "output_type": "execute_result" } @@ -2001,8 +2215,13 @@ }, { "cell_type": "code", - "execution_count": 83, - "metadata": {}, + "execution_count": 82, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:17.242410Z", + "start_time": "2024-06-08T08:17:17.226299Z" + } + }, "outputs": [ { "data": { @@ -2011,19 +2230,24 @@ " [2., 8.]]) * mvolt" ] }, - "execution_count": 83, + "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "bc.math.column_stack((a[:, jnp.newaxis], b[:, jnp.newaxis]))" + "bu.math.column_stack((a[:, jnp.newaxis], b[:, jnp.newaxis]))" ] }, { "cell_type": "code", - "execution_count": 84, - "metadata": {}, + "execution_count": 83, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:17.298740Z", + "start_time": "2024-06-08T08:17:17.284862Z" + } + }, "outputs": [ { "data": { @@ -2032,13 +2256,13 @@ " [2., 8.]]) * mvolt" ] }, - "execution_count": 84, + "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "bc.math.hstack((a[:, jnp.newaxis], b[:, jnp.newaxis])) # the result is the same" + "bu.math.hstack((a[:, jnp.newaxis], b[:, jnp.newaxis])) # the result is the same" ] }, { @@ -2051,74 +2275,89 @@ }, { "cell_type": "code", - "execution_count": 85, - "metadata": {}, + "execution_count": 84, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:17.392633Z", + "start_time": "2024-06-08T08:17:17.378675Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "ArrayImpl([[9., 4., 4., 6., 3., 9., 6., 9., 7., 0., 0., 8.],\n", - " [0., 2., 4., 4., 9., 0., 5., 0., 3., 3., 8., 8.]]) * mvolt" + "ArrayImpl([[3., 6., 6., 8., 0., 0., 5., 8., 9., 1., 5., 1.],\n", + " [7., 3., 0., 2., 3., 9., 3., 7., 3., 4., 0., 8.]]) * mvolt" ] }, - "execution_count": 85, + "execution_count": 84, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "a = jnp.floor(10 * bc.random.random((2, 12))) * U.mV\n", + "a = jnp.floor(10 * bst.random.random((2, 12))) * bu.mV\n", "a" ] }, { "cell_type": "code", - "execution_count": 86, - "metadata": {}, + "execution_count": 85, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:17.469052Z", + "start_time": "2024-06-08T08:17:17.454110Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "[ArrayImpl([[9., 4., 4., 6.],\n", - " [0., 2., 4., 4.]]) * mvolt,\n", - " ArrayImpl([[3., 9., 6., 9.],\n", - " [9., 0., 5., 0.]]) * mvolt,\n", - " ArrayImpl([[7., 0., 0., 8.],\n", - " [3., 3., 8., 8.]]) * mvolt]" + "[ArrayImpl([[3., 6., 6., 8.],\n", + " [7., 3., 0., 2.]]) * mvolt,\n", + " ArrayImpl([[0., 0., 5., 8.],\n", + " [3., 9., 3., 7.]]) * mvolt,\n", + " ArrayImpl([[9., 1., 5., 1.],\n", + " [3., 4., 0., 8.]]) * mvolt]" ] }, - "execution_count": 86, + "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "bc.math.hsplit(a, 3) # Split a into 3" + "bu.math.hsplit(a, 3) # Split a into 3" ] }, { "cell_type": "code", - "execution_count": 87, - "metadata": {}, + "execution_count": 86, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:17.603174Z", + "start_time": "2024-06-08T08:17:17.590257Z" + } + }, "outputs": [ { "data": { "text/plain": [ - "[ArrayImpl([[9., 4., 4.],\n", - " [0., 2., 4.]]) * mvolt,\n", - " ArrayImpl([[6.],\n", - " [4.]]) * mvolt,\n", - " ArrayImpl([[3., 9., 6., 9., 7., 0., 0., 8.],\n", - " [9., 0., 5., 0., 3., 3., 8., 8.]]) * mvolt]" + "[ArrayImpl([[3., 6., 6.],\n", + " [7., 3., 0.]]) * mvolt,\n", + " ArrayImpl([[8.],\n", + " [2.]]) * mvolt,\n", + " ArrayImpl([[0., 0., 5., 8., 9., 1., 5., 1.],\n", + " [3., 9., 3., 7., 3., 4., 0., 8.]]) * mvolt]" ] }, - "execution_count": 87, + "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "bc.math.hsplit(a, (3, 4)) # Split `a` after the third and the fourth column" + "bu.math.hsplit(a, (3, 4)) # Split `a` after the third and the fourth column" ] }, { @@ -2140,8 +2379,13 @@ }, { "cell_type": "code", - "execution_count": 90, - "metadata": {}, + "execution_count": 87, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:17.664616Z", + "start_time": "2024-06-08T08:17:17.651627Z" + } + }, "outputs": [ { "data": { @@ -2149,22 +2393,25 @@ "3. * volt" ] }, - "execution_count": 90, + "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "from braincore.units import in_unit\n", - "\n", - "q = 3. * U.volt\n", + "q = 3. * bu.volt\n", "q" ] }, { "cell_type": "code", - "execution_count": 91, - "metadata": {}, + "execution_count": 88, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:17.788887Z", + "start_time": "2024-06-08T08:17:17.774669Z" + } + }, "outputs": [ { "data": { @@ -2172,13 +2419,13 @@ "'3000. mV'" ] }, - "execution_count": 91, + "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "in_unit(q, U.mvolt)" + "bu.in_unit(q, bu.mvolt)" ] }, { @@ -2191,8 +2438,13 @@ }, { "cell_type": "code", - "execution_count": 92, - "metadata": {}, + "execution_count": 89, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:17.850100Z", + "start_time": "2024-06-08T08:17:17.836718Z" + } + }, "outputs": [ { "data": { @@ -2200,20 +2452,25 @@ "5. * mvolt" ] }, - "execution_count": 92, + "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "q = 5. * U.mV\n", + "q = 5. * bu.mV\n", "q" ] }, { "cell_type": "code", - "execution_count": 96, - "metadata": {}, + "execution_count": 90, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:17.946008Z", + "start_time": "2024-06-08T08:17:17.932601Z" + } + }, "outputs": [ { "data": { @@ -2221,7 +2478,7 @@ "-5. * mvolt" ] }, - "execution_count": 96, + "execution_count": 90, "metadata": {}, "output_type": "execute_result" } @@ -2233,8 +2490,13 @@ }, { "cell_type": "code", - "execution_count": 97, - "metadata": {}, + "execution_count": 91, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:18.018108Z", + "start_time": "2024-06-08T08:17:18.005084Z" + } + }, "outputs": [ { "data": { @@ -2242,7 +2504,7 @@ "-5. * mvolt" ] }, - "execution_count": 97, + "execution_count": 91, "metadata": {}, "output_type": "execute_result" } @@ -2254,8 +2516,13 @@ }, { "cell_type": "code", - "execution_count": 98, - "metadata": {}, + "execution_count": 92, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:18.153598Z", + "start_time": "2024-06-08T08:17:18.139911Z" + } + }, "outputs": [ { "data": { @@ -2263,7 +2530,7 @@ "5. * mvolt" ] }, - "execution_count": 98, + "execution_count": 92, "metadata": {}, "output_type": "execute_result" } @@ -2275,8 +2542,13 @@ }, { "cell_type": "code", - "execution_count": 102, - "metadata": {}, + "execution_count": 93, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:18.200189Z", + "start_time": "2024-06-08T08:17:18.184689Z" + } + }, "outputs": [ { "data": { @@ -2284,21 +2556,26 @@ "(Quantity(5.), Quantity(-6.))" ] }, - "execution_count": 102, + "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "q1 = Quantity(0b101)\n", - "q2 = Quantity(-0b110)\n", + "q1 = bu.Quantity(0b101)\n", + "q2 = bu.Quantity(-0b110)\n", "q1, q2" ] }, { "cell_type": "code", - "execution_count": 103, - "metadata": {}, + "execution_count": 94, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:18.300811Z", + "start_time": "2024-06-08T08:17:18.286532Z" + } + }, "outputs": [ { "data": { @@ -2306,7 +2583,7 @@ "(Quantity(-6.), Quantity(5.))" ] }, - "execution_count": 103, + "execution_count": 94, "metadata": {}, "output_type": "execute_result" } @@ -2325,8 +2602,13 @@ }, { "cell_type": "code", - "execution_count": 112, - "metadata": {}, + "execution_count": 95, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:18.350568Z", + "start_time": "2024-06-08T08:17:18.335369Z" + } + }, "outputs": [ { "data": { @@ -2335,21 +2617,26 @@ " ArrayImpl([ 8., 12., 16., 20., 24.]) * mvolt)" ] }, - "execution_count": 112, + "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "q1 = jnp.arange(10, 20, 2) * U.mV\n", - "q2 = jnp.arange(8, 27, 4) * U.mV\n", + "q1 = jnp.arange(10, 20, 2) * bu.mV\n", + "q2 = jnp.arange(8, 27, 4) * bu.mV\n", "q1, q2" ] }, { "cell_type": "code", - "execution_count": 116, - "metadata": {}, + "execution_count": 96, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:18.463131Z", + "start_time": "2024-06-08T08:17:18.448183Z" + } + }, "outputs": [ { "data": { @@ -2358,7 +2645,7 @@ " Array([ True, False, True, True, True], dtype=bool))" ] }, - "execution_count": 116, + "execution_count": 96, "metadata": {}, "output_type": "execute_result" } @@ -2369,8 +2656,13 @@ }, { "cell_type": "code", - "execution_count": 117, - "metadata": {}, + "execution_count": 97, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:18.536630Z", + "start_time": "2024-06-08T08:17:18.523328Z" + } + }, "outputs": [ { "data": { @@ -2379,7 +2671,7 @@ " Array([False, True, True, True, True], dtype=bool))" ] }, - "execution_count": 117, + "execution_count": 97, "metadata": {}, "output_type": "execute_result" } @@ -2390,8 +2682,13 @@ }, { "cell_type": "code", - "execution_count": 118, - "metadata": {}, + "execution_count": 98, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:18.658605Z", + "start_time": "2024-06-08T08:17:18.644318Z" + } + }, "outputs": [ { "data": { @@ -2400,7 +2697,7 @@ " Array([ True, True, False, False, False], dtype=bool))" ] }, - "execution_count": 118, + "execution_count": 98, "metadata": {}, "output_type": "execute_result" } @@ -2419,8 +2716,13 @@ }, { "cell_type": "code", - "execution_count": 134, - "metadata": {}, + "execution_count": 99, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:18.750090Z", + "start_time": "2024-06-08T08:17:18.733415Z" + } + }, "outputs": [ { "data": { @@ -2428,21 +2730,26 @@ "(ArrayImpl([1., 2., 3.]) * mvolt, ArrayImpl([2., 3., 4.]) * mvolt)" ] }, - "execution_count": 134, + "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "q1 = jnp.array([1, 2, 3]) * U.mV\n", - "q2 = jnp.array([2, 3, 4]) * U.mV\n", + "q1 = jnp.array([1, 2, 3]) * bu.mV\n", + "q2 = jnp.array([2, 3, 4]) * bu.mV\n", "q1, q2" ] }, { "cell_type": "code", - "execution_count": 135, - "metadata": {}, + "execution_count": 100, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:18.855866Z", + "start_time": "2024-06-08T08:17:18.840386Z" + } + }, "outputs": [ { "data": { @@ -2450,7 +2757,7 @@ "(ArrayImpl([3., 5., 7.]) * mvolt, ArrayImpl([-1., -1., -1.]) * mvolt)" ] }, - "execution_count": 135, + "execution_count": 100, "metadata": {}, "output_type": "execute_result" } @@ -2461,8 +2768,13 @@ }, { "cell_type": "code", - "execution_count": 136, - "metadata": {}, + "execution_count": 101, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:18.941214Z", + "start_time": "2024-06-08T08:17:18.927264Z" + } + }, "outputs": [ { "data": { @@ -2470,7 +2782,7 @@ "ArrayImpl([ 2., 6., 12.]) * mvolt2" ] }, - "execution_count": 136, + "execution_count": 101, "metadata": {}, "output_type": "execute_result" } @@ -2481,8 +2793,13 @@ }, { "cell_type": "code", - "execution_count": 137, - "metadata": {}, + "execution_count": 102, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:19.058063Z", + "start_time": "2024-06-08T08:17:19.045255Z" + } + }, "outputs": [ { "data": { @@ -2492,7 +2809,7 @@ " ArrayImpl([1., 2., 3.]) * mvolt)" ] }, - "execution_count": 137, + "execution_count": 102, "metadata": {}, "output_type": "execute_result" } @@ -2503,8 +2820,13 @@ }, { "cell_type": "code", - "execution_count": 138, - "metadata": {}, + "execution_count": 103, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:19.137905Z", + "start_time": "2024-06-08T08:17:19.125338Z" + } + }, "outputs": [ { "data": { @@ -2512,7 +2834,7 @@ "(Array([0., 0., 0.], dtype=float64), ArrayImpl([1., 2., 3.]) * mvolt)" ] }, - "execution_count": 138, + "execution_count": 103, "metadata": {}, "output_type": "execute_result" } @@ -2523,8 +2845,13 @@ }, { "cell_type": "code", - "execution_count": 139, - "metadata": {}, + "execution_count": 104, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:19.289789Z", + "start_time": "2024-06-08T08:17:19.275896Z" + } + }, "outputs": [ { "data": { @@ -2532,7 +2859,7 @@ "ArrayImpl([1., 4., 9.]) * mvolt2" ] }, - "execution_count": 139, + "execution_count": 104, "metadata": {}, "output_type": "execute_result" } @@ -2543,8 +2870,13 @@ }, { "cell_type": "code", - "execution_count": 140, - "metadata": {}, + "execution_count": 105, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:19.347106Z", + "start_time": "2024-06-08T08:17:19.334827Z" + } + }, "outputs": [ { "data": { @@ -2552,7 +2884,7 @@ "20. * mvolt2" ] }, - "execution_count": 140, + "execution_count": 105, "metadata": {}, "output_type": "execute_result" } @@ -2563,8 +2895,13 @@ }, { "cell_type": "code", - "execution_count": 132, - "metadata": {}, + "execution_count": 106, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:19.472101Z", + "start_time": "2024-06-08T08:17:19.456793Z" + } + }, "outputs": [ { "data": { @@ -2573,20 +2910,25 @@ " ArrayImpl([0., 0., 0., 0., 1.]) * volt)" ] }, - "execution_count": 132, + "execution_count": 106, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "q1 = Quantity(jnp.arange(5, dtype=jnp.int32), unit=U.mV.unit)\n", + "q1 = bu.Quantity(jnp.arange(5, dtype=jnp.int32), unit=bu.mV.unit)\n", "q1 << 2, q1 >> 2" ] }, { "cell_type": "code", - "execution_count": 151, - "metadata": {}, + "execution_count": 107, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:19.531264Z", + "start_time": "2024-06-08T08:17:19.514038Z" + } + }, "outputs": [ { "name": "stdout", @@ -2599,9 +2941,9 @@ } ], "source": [ - "q1 = 80.23456 * U.mV\n", - "q2 = 100.000056 * U.mV\n", - "q3 = -100.000056 * U.mV\n", + "q1 = 80.23456 * bu.mV\n", + "q2 = 100.000056 * bu.mV\n", + "q3 = -100.000056 * bu.mV\n", "print(\"round(80.23456, 2) : \", q1.round(5))\n", "print(\"round(100.000056, 3) : \", q2.round(6))\n", "print(\"round(-100.000056, 3) : \", q3.round(6))" @@ -2617,8 +2959,13 @@ }, { "cell_type": "code", - "execution_count": 152, - "metadata": {}, + "execution_count": 108, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:19.688835Z", + "start_time": "2024-06-08T08:17:19.670457Z" + } + }, "outputs": [ { "data": { @@ -2627,20 +2974,25 @@ " [3., 4.]]) * mvolt" ] }, - "execution_count": 152, + "execution_count": 108, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "q = [[1, 2], [3, 4]] * U.mV\n", + "q = [[1, 2], [3, 4]] * bu.mV\n", "q" ] }, { "cell_type": "code", - "execution_count": 153, - "metadata": {}, + "execution_count": 109, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:19.754912Z", + "start_time": "2024-06-08T08:17:19.743837Z" + } + }, "outputs": [ { "data": { @@ -2648,7 +3000,7 @@ "ArrayImpl([1., 2., 3., 4.]) * mvolt" ] }, - "execution_count": 153, + "execution_count": 109, "metadata": {}, "output_type": "execute_result" } @@ -2659,8 +3011,13 @@ }, { "cell_type": "code", - "execution_count": 154, - "metadata": {}, + "execution_count": 110, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:19.867999Z", + "start_time": "2024-06-08T08:17:19.854522Z" + } + }, "outputs": [ { "data": { @@ -2669,7 +3026,7 @@ " [2., 4.]]) * mvolt" ] }, - "execution_count": 154, + "execution_count": 110, "metadata": {}, "output_type": "execute_result" } @@ -2680,8 +3037,13 @@ }, { "cell_type": "code", - "execution_count": 156, - "metadata": {}, + "execution_count": 111, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:19.923531Z", + "start_time": "2024-06-08T08:17:19.907391Z" + } + }, "outputs": [ { "data": { @@ -2689,7 +3051,7 @@ "ArrayImpl([1., 3.]) * mvolt" ] }, - "execution_count": 156, + "execution_count": 111, "metadata": {}, "output_type": "execute_result" } @@ -2700,8 +3062,13 @@ }, { "cell_type": "code", - "execution_count": 157, - "metadata": {}, + "execution_count": 112, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:20.036298Z", + "start_time": "2024-06-08T08:17:20.023150Z" + } + }, "outputs": [ { "data": { @@ -2710,7 +3077,7 @@ " [2., 4.]]) * mvolt" ] }, - "execution_count": 157, + "execution_count": 112, "metadata": {}, "output_type": "execute_result" } @@ -2721,8 +3088,13 @@ }, { "cell_type": "code", - "execution_count": 158, - "metadata": {}, + "execution_count": 113, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:20.122048Z", + "start_time": "2024-06-08T08:17:20.109833Z" + } + }, "outputs": [ { "data": { @@ -2731,7 +3103,7 @@ " [3., 4., 3., 4.]]) * mvolt" ] }, - "execution_count": 158, + "execution_count": 113, "metadata": {}, "output_type": "execute_result" } @@ -2742,8 +3114,13 @@ }, { "cell_type": "code", - "execution_count": 159, - "metadata": {}, + "execution_count": 114, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:20.228759Z", + "start_time": "2024-06-08T08:17:20.213853Z" + } + }, "outputs": [ { "data": { @@ -2752,7 +3129,7 @@ " [3., 4.]]]) * mvolt" ] }, - "execution_count": 159, + "execution_count": 114, "metadata": {}, "output_type": "execute_result" } @@ -2763,8 +3140,13 @@ }, { "cell_type": "code", - "execution_count": 162, - "metadata": {}, + "execution_count": 115, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:20.294326Z", + "start_time": "2024-06-08T08:17:20.279806Z" + } + }, "outputs": [ { "data": { @@ -2773,7 +3155,7 @@ " [3., 4.]]]) * mvolt" ] }, - "execution_count": 162, + "execution_count": 115, "metadata": {}, "output_type": "execute_result" } @@ -2784,8 +3166,13 @@ }, { "cell_type": "code", - "execution_count": 163, - "metadata": {}, + "execution_count": 116, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:20.410465Z", + "start_time": "2024-06-08T08:17:20.397348Z" + } + }, "outputs": [ { "data": { @@ -2794,7 +3181,7 @@ " [3., 4.]]]) * mvolt" ] }, - "execution_count": 163, + "execution_count": 116, "metadata": {}, "output_type": "execute_result" } @@ -2806,8 +3193,13 @@ }, { "cell_type": "code", - "execution_count": 173, - "metadata": {}, + "execution_count": 117, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:20.473612Z", + "start_time": "2024-06-08T08:17:20.454902Z" + } + }, "outputs": [ { "data": { @@ -2816,21 +3208,26 @@ " [10., 4.]]) * mvolt" ] }, - "execution_count": 173, + "execution_count": 117, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "q_put = [[1, 2], [3, 4]] * U.mV\n", - "q_put.put([[1, 0], [0, 1]], [10, 30] * U.mV)\n", + "q_put = [[1, 2], [3, 4]] * bu.mV\n", + "q_put.put([[1, 0], [0, 1]], [10, 30] * bu.mV)\n", "q_put" ] }, { "cell_type": "code", - "execution_count": 174, - "metadata": {}, + "execution_count": 118, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:20.586577Z", + "start_time": "2024-06-08T08:17:20.573505Z" + } + }, "outputs": [ { "data": { @@ -2839,20 +3236,25 @@ " [3., 4.]]) * mvolt" ] }, - "execution_count": 174, + "execution_count": 118, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "q_squeeze = [[1, 2], [3, 4]] * U.mV\n", + "q_squeeze = [[1, 2], [3, 4]] * bu.mV\n", "q_squeeze.squeeze()" ] }, { "cell_type": "code", - "execution_count": 175, - "metadata": {}, + "execution_count": 119, + "metadata": { + "ExecuteTime": { + "end_time": "2024-06-08T08:17:20.667592Z", + "start_time": "2024-06-08T08:17:20.652077Z" + } + }, "outputs": [ { "data": { @@ -2860,13 +3262,13 @@ "[ArrayImpl([[1., 2.]]) * mvolt, ArrayImpl([[3., 4.]]) * mvolt]" ] }, - "execution_count": 175, + "execution_count": 119, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "q_spilt = [[1, 2], [3, 4]] * U.mV\n", + "q_spilt = [[1, 2], [3, 4]] * bu.mV\n", "q_spilt.split(2)" ] }, @@ -2972,7 +3374,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -2986,9 +3388,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.11.5" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 4 } diff --git a/docs/tutorials/physical_units.rst b/docs/tutorials/physical_units.rst deleted file mode 100644 index 3cf79e4..0000000 --- a/docs/tutorials/physical_units.rst +++ /dev/null @@ -1,7 +0,0 @@ -Physical Units -============== - -.. toctree:: - :maxdepth: 1 - - physical_units.ipynb \ No newline at end of file