<jupyter_start><jupyter_text>Magma Simulator<jupyter_code>import magma as m
import mantle<jupyter_output>/opt/homebrew/lib/python3.7/site-packages/pysmt/walkers/generic.py:43: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
  if len(nodetypes) == 1 and isinstance(nodetypes[0], collections.Iterable):
/opt/homebrew/lib/python3.7/site-packages/ast_tools/immutable_ast.py:10: UserWarning: /opt/homebrew/lib/python3.7/site-packages/ast_tools/immutable_ast.py generated for (3, 6)does not match system version (3, 7)
  warnings.warn(f"{__file__} generated for (3, 6)"
[33mWARNING[0m:magma:'IO = [...]' syntax is deprecated, use 'io = IO(...)' syntax instead[0m
[33mWARNING[0m:magma:'IO = [...]' syntax is deprecated, use 'io = IO(...)' syntax instead[0m
[33mWARNING[0m:magma:'definition' class method syntax is deprecated, use inline definition syntax instead[0m
[33mWARNING[0m:magma:'IO = [...]' syntax is deprecated, use 'io = IO(...)' syntax instead[0m
[33mWARNING[0m:magma:'I[...]<jupyter_text>Simulating Combinational CircuitsCreate a 2-input multiplexor.<jupyter_code>Mux2 = mantle.Mux2
print(Mux2)
from magma.simulator import PythonSimulator

simulator = PythonSimulator(Mux2)

print('I0 I1 S O')
for i0 in [0, 1]:
    for i1 in [0, 1]:
        for s in [0, 1]:
            simulator.set_value(Mux2.I0, i0)
            simulator.set_value(Mux2.I1, i1)
            simulator.set_value(Mux2.S, s)
            simulator.evaluate()
            print(i0, i1, s, int(simulator.get_value(Mux2.O)))<jupyter_output>I0 I1 S O
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1<jupyter_text>Simulating Sequential Logic Circuits with ClocksCreate a 2-bit Counter.<jupyter_code>Counter = mantle.DefineCounter(2)

print(Counter)<jupyter_output>[33mWARNING[0m:magma:'IO = [...]' syntax is deprecated, use 'io = IO(...)' syntax instead[0m
[33mWARNING[0m:magma:'IO = [...]' syntax is deprecated, use 'io = IO(...)' syntax instead[0m
[33mWARNING[0m:magma:'IO = [...]' syntax is deprecated, use 'io = IO(...)' syntax instead[0m
[33mWARNING[0m:magma:'definition' class method syntax is deprecated, use inline definition syntax instead[0m
[33mWARNING[0m:magma:'IO = [...]' syntax is deprecated, use 'io = IO(...)' syntax instead[0m
[33mWARNING[0m:magma:'IO = [...]' syntax is deprecated, use 'io = IO(...)' syntax instead[0m<jupyter_text>Create a python simulator for the ice40.<jupyter_code>from magma.simulator import PythonSimulator
from hwtypes import BitVector

simulator = PythonSimulator(Counter, clock=Counter.CLK)
O0 = []
O1 = []
COUT = []
for i in range(16):
    for j in range(2):
        simulator.advance()
        O = BitVector[2](simulator.get_value(Counter.O))
        O0.append(int(O[0]))
        O1.append(int(O[1]))
        COUT.append(simulator.get_value(Counter.COUT))<jupyter_output><empty_output><jupyter_text>Use `matplotlib` to plot the output of the simulator.<jupyter_code>import matplotlib.pyplot as plt
import numpy as np

n = len(O1) // 2
t = np.repeat(0.5 * np.arange(2*n + 1) ,2)[1:-1]
clock = np.tile(np.array([1, 1, 0, 0]), n)

O0 = np.repeat(np.array(O0), 2)
O1 = np.repeat(np.array(O1), 2)
COUT = np.repeat(np.array(COUT), 2)


plt.text(-1.5, 3.25, 'clock')
plt.plot(t, 0.5*clock + 3, 'r', linewidth=2)
plt.text(-1.5, 2.25, 'O[0]')
plt.plot(t, 0.5*O0 + 2,    'r', linewidth=2)
plt.text(-1.5, 1.25, 'O[1]')
plt.plot(t, 0.5*O1 + 1,    'r', linewidth=2)
plt.text(-1.5, 0.25, 'COUT')
plt.plot(t, 0.5*COUT,      'r', linewidth=2)
plt.xlim([0, n])
plt.ylim([0, 4])

plt.gca().axis('off')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1718454471764388, 'fraction_numerical': 0.054039448797622264, 'mean_word_length': 4.357452966714906, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '511033', 'license': 'MIT', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1430, 'n_words': 344, 'path': 'notebooks/advanced/simulate.ipynb', 'repo_name': 'phanrahan/magmathon', 'size': '3701'}