CIRCT Python Bindings
raw JSON → 1.145.1 verified Mon Apr 27 auth: no python
CIRCT (Circuit IR Compilers and Tools) Python bindings for interacting with MLIR-based hardware compilation tools. Current version 1.145.1. Released roughly monthly.
pip install circt Common errors
error ImportError: cannot import name 'Module' from 'circt' ↓
cause Module is in circt.ir, not top-level.
fix
Use 'from circt.ir import Module'.
error RuntimeError: Cannot create context: another context is already active ↓
cause Multiple Context instances without proper cleanup.
fix
Use 'with Context():' block to ensure single active context.
Warnings
breaking CIRCT uses MLIR's Python bindings with breaking changes across versions. Ensure circt version matches the MLIR version used. ↓
fix Pin circt version in requirements.txt and check with MLIR version.
deprecated The 'circt.support' module is deprecated; use 'circt.ir' directly. ↓
fix Replace imports from circt.support with circt.ir.
gotcha Context creation is mandatory before any IR operations; forgetting leads to cryptic errors. ↓
fix Always use 'with circt.ir.Context() as ctx:' block.
Imports
- circt wrong
import circt.ircorrectimport circt - Module wrong
from circt import Modulecorrectfrom circt.ir import Module
Quickstart
import circt
from circt.ir import Context, Location, Module
with Context() as ctx:
loc = Location.unknown(ctx)
module = Module.parse(ctx, '''
module {
func.func @main() -> i32 {
%0 = arith.constant 42 : i32
return %0 : i32
}
}
''')
print(module)