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
muslpy 3.10–3.910 runs
build_error
glibcpy 3.10–3.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()`.fixConsult 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'.fixAlways 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.fixExplicitly 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.