Registry / data / magma-lang

magma-lang

JSON →
library3.0.2pypypiunverified

Magma-lang is an embedded domain-specific language (eDSL) in Python for designing and generating hardware circuits. It enables hierarchical and compositional circuit design, targeting various hardware description languages like Verilog. The current version is 3.0.2, with active development incorporating community feedback and feature enhancements.

pip install magma-lang
INSTALL
IMPORT
SIG · MAGMA-LANG
M
magma-lang
datapythonv3.0.2
Install
26.9s avg
Import
3830ms
Disk
400MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
installs and imports cleanly · install 26.9s · import 2.298s · 246MB
400MB installed
● package 400MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Circuit
from magma import Circuit
Bit, In, Out
from magma import Bit, In, Out
PythonSimulator
from magma.simulator import PythonSimulator
import magma.simulator
Import specific classes or functions, not just the module.
DeclareCircuit
from magma import Circuit
from magma import DeclareCircuit
DeclareCircuit was used in Magma v2; v3 uses class-based Circuit definitions.

This example defines a basic 2-input AND gate using Magma's class-based circuit definition and then simulates its behavior using the PythonSimulator.

import magma from magma import Circuit, In, Out, Bit from magma.simulator import PythonSimulator # Define a simple 2-input AND gate circuit class And2(Circuit): name = "And2" io = In(a=Bit, b=Bit), Out(o=Bit) def definition(self): # Use the @= operator for wiring self.o @= self.a & self.b # Instantiate the circuit and_gate = And2() # Print a representation of the circuit print(f"Defined circuit: {and_gate.name}") # Simulate the circuit simulator = PythonSimulator(and_gate) # Test case: 1 AND 0 simulator.set_value(and_gate.a, 1) simulator.set_value(and_gate.b, 0) simulator.evaluate() result_1_0 = simulator.get_value(and_gate.o) print(f"1 AND 0 = {result_1_0}") # Expected: 0 # Test case: 1 AND 1 simulator.set_value(and_gate.a, 1) simulator.set_value(and_gate.b, 1) simulator.evaluate() result_1_1 = simulator.get_value(and_gate.o) print(f"1 AND 1 = {result_1_1}") # Expected: 1
magma --version
Debug
Known issues
breakingMagma v3 introduced significant breaking changes from v2, including a shift from functional `DeclareCircuit` to class-based `Circuit` definitions, and a new `@=` operator for wiring instead of `magma.wire()`.
fix
Consult the 'V2 to V3 Migration Guide' in the official Magma documentation. Redefine circuits as classes inheriting `magma.Circuit` and use the `@=` or `<<=` operators for connections.
affects: All v3.x versions (compared to v2.x)
gotchaThe wiring operator `@=` connects the left-hand side to the right-hand side. It's crucial to understand the data flow direction in hardware. E.g., `a @= b` means 'a is driven by b'.
fix
Always ensure the source (driver) is on the right-hand side and the destination (driven) is on the left-hand side of `@=`. For multiple drivers, ensure the correct priority or avoid conflicts.
affects: All v3.x versions
gotchaDistinction between single bits (`magma.Bit`) and arrays of bits (`magma.Bits(n)` or `magma.Array[n, Bit]`). Type mismatches during wiring (e.g., connecting a `Bit` to `Bits(4)`) are a common source of errors.
fix
Explicitly define the correct type for each port. Use type conversion functions like `magma.bits()` or slicing (`[idx]`) to match types when connecting signals of different widths.
affects: All v3.x versions
Upgrade
Version history
3.0.2latest on PyPI · released Mar 20, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
magma-lang — pip install magma-lang · libregistry