# aigverse.abc

Bridge to the external ABC logic synthesis system.

aigverse does not ship ABC. This module drives an ABC executable that is
already installed on the machine, transferring networks as binary AIGER files.
Point it at an executable with the `AIGVERSE_ABC` environment variable or
[`set_abc_binary()`](#aigverse.abc.set_abc_binary), or put `abc` on `PATH`.

Importing this module always succeeds, whether or not ABC is installed. Use
[`is_available()`](#aigverse.abc.is_available) to check, and expect [`AbcNotFoundError`](#aigverse.abc.AbcNotFoundError) from any call
that needs the executable.

The ABC9 (`&`-space) commands live in the [`gia`](gia/index.html.md#module-aigverse.abc.gia) namespace,
mirroring ABC’s own prefix: `abc.dc2` runs ABC’s `dc2` while `abc.gia.dc2`
runs its `&dc2`.

### Example

```pycon
>>> from aigverse import abc
>>> from aigverse.generators import ripple_carry_adder
>>> aig = ripple_carry_adder(4)
>>> if abc.is_available():
...     optimized = abc.resyn2(aig)
...     alternative = abc.gia.dc2(aig)
```

## Submodules

* [aigverse.abc.gia](gia/index.html.md)

## Package Contents

### run_many(networks: [Iterable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[aigverse.abc._runner.AigT], commands: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | aigverse.abc._runner.Command | [Sequence](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[str](https://docs.python.org/3/builtins/stdtypes.html#str) | aigverse.abc._runner.Command], , jobs: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = ..., timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = ..., use_init_file: [bool](https://docs.python.org/3/builtins/functions.html#bool) = ..., gia: [bool](https://docs.python.org/3/builtins/functions.html#bool) = ..., binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = ..., return_exceptions: Literal[False] = False) → [list](https://docs.python.org/3/builtins/stdtypes.html#list)[aigverse.abc._runner.AigT]

### run_many(networks: [Iterable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[aigverse.abc._runner.AigT], commands: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | aigverse.abc._runner.Command | [Sequence](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[str](https://docs.python.org/3/builtins/stdtypes.html#str) | aigverse.abc._runner.Command], , jobs: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = ..., timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = ..., use_init_file: [bool](https://docs.python.org/3/builtins/functions.html#bool) = ..., gia: [bool](https://docs.python.org/3/builtins/functions.html#bool) = ..., binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = ..., return_exceptions: Literal[True]) → [list](https://docs.python.org/3/builtins/stdtypes.html#list)[aigverse.abc._runner.AigT | aigverse.abc._errors.AbcError]

### run_many(networks: [Iterable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[aigverse.abc._runner.AigT], commands: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | aigverse.abc._runner.Command | [Sequence](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[str](https://docs.python.org/3/builtins/stdtypes.html#str) | aigverse.abc._runner.Command], , jobs: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = ..., timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = ..., use_init_file: [bool](https://docs.python.org/3/builtins/functions.html#bool) = ..., gia: [bool](https://docs.python.org/3/builtins/functions.html#bool) = ..., binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = ..., return_exceptions: [bool](https://docs.python.org/3/builtins/functions.html#bool)) → [list](https://docs.python.org/3/builtins/stdtypes.html#list)[aigverse.abc._runner.AigT] | [list](https://docs.python.org/3/builtins/stdtypes.html#list)[aigverse.abc._runner.AigT | aigverse.abc._errors.AbcError]

Runs one ABC script over many networks, in parallel.

The same script is applied to every network, each in its own ABC process. The
bridge already isolates a call completely – its own temporary directory, its
own working directory, its own `abc.history` – so the runs simply overlap.
A cross product of scripts and networks is one call per script:

```default
for name, script in recipes.items():
    rows[name] = abc.run_many(designs, script)
```

Results come back in input order, never completion order, so `zip(networks,
results)` is always valid. Every result is held at once regardless of `jobs`,
which is the memory a whole corpus costs.

Expect a speedup below the number of cores: a batch is as slow as its slowest
network.

* **Parameters:**
  * **networks** – The networks to optimize. Consumed in full before any work starts.
  * **commands** – A single `;`-separated ABC command string, a
    [`Command`](#aigverse.abc.Command), or a sequence of individual commands.
    The same script runs on every network. The canonical scripts are
    reachable through [`expand_script()`](#aigverse.abc.expand_script), and a
    parameterized one through each wrapper’s `cmd()`.
  * **jobs** – How many ABC processes to keep running at once. `None` (default)
    uses the number of CPUs available to this process, capped at the number
    of networks; `1` runs inline without a thread pool. On large designs
    memory rather than CPU is what limits this, since each worker holds a
    whole ABC in flight. A CPU *quota* – `docker --cpus=2` – is not
    visible here, so set `jobs` explicitly under one.
  * **timeout** – Seconds to wait for ABC to terminate, **per network** rather than
    for the batch as a whole, or `None` for no limit.
  * **use_init_file** – If `False` (default), ABC is invoked with `-s` so that
    no `abc.rc` is read and results do not depend on the local install.
  * **gia** – If `True`, transfer each network through `&read`/`&write` so it
    lands in ABC9’s GIA store, as [`run_script()`](#aigverse.abc.run_script) does.
  * **binary** – Overrides the resolved ABC executable for this call only. It is
    resolved once for the whole batch.
  * **return_exceptions** – If `False` (default), the first failure aborts the
    batch and is raised, as [`run_script()`](#aigverse.abc.run_script) would. If
    `True`, each failing network yields its [`AbcError`](#aigverse.abc.AbcError) in place of a
    result, so one bad design does not lose a whole sweep. Only an
    `AbcError` is captured: a `TypeError` from an unsupported network
    type, a `ValueError` from an invalid script, and anything else that
    goes wrong are raised either way, because those are faults in the call
    rather than per-item ABC failures.
* **Returns:**
  The optimized networks, in input order, each of the same type as its input
  – with [`AbcError`](#aigverse.abc.AbcError) instances in place of the failures when
  `return_exceptions` is set.
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If any element of `networks` is not an `Aig`.
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `jobs` is below 1, if no command was given, or if `gia`
    is set and a network has a register whose reset value is undefined.
  * [**AbcNotFoundError**](#aigverse.abc.AbcNotFoundError) – If no ABC executable could be located. Resolution
    happens once before any network is run, so this is raised whatever
    `return_exceptions` says.
  * [**AbcTimeoutError**](#aigverse.abc.AbcTimeoutError) – If ABC did not terminate within `timeout` seconds for
    some network and `return_exceptions` is not set.
  * [**AbcExecutionError**](#aigverse.abc.AbcExecutionError) – If ABC reported an error for some network and
    `return_exceptions` is not set.

#### NOTE
Which failure is reported when several networks fail is unspecified; use
`return_exceptions=True` to see all of them. There is no `verbose`:
nothing inside an ABC transcript says which network produced it, so a
failure’s `output` – reachable through `return_exceptions` – is what
carries that.

#### NOTE
Interrupting a batch drops the networks that have not started yet. Ctrl-C in a
terminal reaches the running ABC processes too, because they share the
foreground process group, but an interrupt delivered to the interpreter alone
does not – `run_commands` keeps no handle on what it spawned, so `timeout`
is what bounds those.

### ABC_ENV_VAR *= 'AIGVERSE_ABC'*

### ABC_RC_ENV_VAR *= 'AIGVERSE_ABC_RC'*

### abc_binary() → [Path](https://docs.python.org/3/library/pathlib.html#pathlib.Path)

Resolves the ABC executable.

* **Returns:**
  The resolved absolute path to the ABC executable.
* **Raises:**
  [**AbcNotFoundError**](#aigverse.abc.AbcNotFoundError) – If no ABC executable could be located.

### abc_rc() → [Path](https://docs.python.org/3/library/pathlib.html#pathlib.Path) | [None](https://docs.python.org/3/builtins/constants.html#None)

Resolves the ABC resource file loaded before every command.

Resolution order: an explicit path set via [`set_abc_rc()`](#aigverse.abc.set_abc_rc), then the
`AIGVERSE_ABC_RC` environment variable.

* **Returns:**
  The resolved absolute path, or `None` if no resource file is configured.

### abc_version(, timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = 10.0) → [str](https://docs.python.org/3/builtins/stdtypes.html#str)

Queries the version banner of the resolved ABC executable.

Useful to confirm that whatever was discovered really is Berkeley ABC, since
discovery itself deliberately does not start a process.

* **Parameters:**
  **timeout** – Seconds to wait for ABC to respond, or `None` to wait forever.
* **Returns:**
  The trimmed output of ABC’s `version` command.
* **Raises:**
  * [**AbcNotFoundError**](#aigverse.abc.AbcNotFoundError) – If no ABC executable could be located.
  * [**AbcTimeoutError**](#aigverse.abc.AbcTimeoutError) – If ABC did not terminate within `timeout` seconds.
  * [**AbcExecutionError**](#aigverse.abc.AbcExecutionError) – If the executable did not accept the `version`
    command, which means whatever was discovered is not ABC.

### find_abc_binary() → [Path](https://docs.python.org/3/library/pathlib.html#pathlib.Path) | [None](https://docs.python.org/3/builtins/constants.html#None)

Resolves the ABC executable without raising.

Resolution order: an explicit override set via [`set_abc_binary()`](#aigverse.abc.set_abc_binary), then
the `AIGVERSE_ABC` environment variable, then a `PATH` lookup for `abc`
and `berkeley-abc`.

* **Returns:**
  The resolved absolute path, or `None` if no candidate was found.

### is_available() → [bool](https://docs.python.org/3/builtins/functions.html#bool)

Reports whether an ABC executable can be located.

This never raises and never starts a process, so it is safe to call in a
module guard or a test skip condition.

* **Returns:**
  `True` if an ABC executable was found, `False` otherwise.

### set_abc_binary(path: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None)) → [Path](https://docs.python.org/3/library/pathlib.html#pathlib.Path) | [None](https://docs.python.org/3/builtins/constants.html#None)

Sets or clears an explicit path to the ABC executable.

The explicit override takes precedence over the `AIGVERSE_ABC` environment
variable and over a `PATH` lookup. It applies process-wide and is intended
to be called once during setup; it is not thread-safe.

* **Parameters:**
  **path** – Path to the ABC executable, or `None` to clear a previously set
  override and fall back to environment and `PATH` discovery.
* **Returns:**
  The resolved absolute path, or `None` if the override was cleared.
* **Raises:**
  [**AbcNotFoundError**](#aigverse.abc.AbcNotFoundError) – If `path` does not exist or is not executable.

### set_abc_rc(path: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None)) → [Path](https://docs.python.org/3/library/pathlib.html#pathlib.Path) | [None](https://docs.python.org/3/builtins/constants.html#None)

Sets or clears an ABC resource file to load before every command.

The bridge normally runs ABC with `-s` so that no `abc.rc` is read and
results do not depend on the local installation. Registering a resource file
here keeps that isolation – the file given is the only one loaded – while
making its aliases available to [`run_script()`](#aigverse.abc.run_script) and
[`run_commands()`](#aigverse.abc.run_commands).

It applies process-wide and is intended to be called once during setup; it is
not thread-safe.

* **Parameters:**
  **path** – Path to an ABC resource file, or `None` to clear a previously set
  one and go back to running without any.
* **Returns:**
  The resolved absolute path, or `None` if the resource file was cleared.
* **Raises:**
  [**AbcNotFoundError**](#aigverse.abc.AbcNotFoundError) – If `path` does not exist or is not a file.

### *class* Balance

Bases: `aigverse.abc._runner.CommandWrapper`

Runs ABC’s `balance` command on a network, or builds it as a command.

#### *static* cmd(, minimize_levels: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, exor: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, duplicate: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, duplicate_critical: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False) → aigverse.abc._runner.Command

Builds ABC’s `balance` command without running it.

* **Parameters:**
  * **minimize_levels** – If `True` (ABC’s default), balance for minimal depth.
  * **exor** – If `True`, balance multi-input EXOR structures as well.
  * **duplicate** – If `True`, allow logic to be duplicated.
  * **duplicate_critical** – If `True`, duplicate logic on the critical paths
    only, which buys depth for less area than `duplicate` does.
* **Returns:**
  The command, ready for [`run_script()`](#aigverse.abc.run_script) or
  [`run_many()`](#aigverse.abc.run_many).

#### \_\_call_\_(ntk: aigverse.abc._runner.AigT, , minimize_levels: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, exor: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, duplicate: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, duplicate_critical: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `balance` command on a network.

Restructures the AND trees of the network to reduce its depth.

* **Parameters:**
  * **ntk** – The network to optimize.
  * **minimize_levels** – If `True` (ABC’s default), balance for minimal depth.
  * **exor** – If `True`, balance multi-input EXOR structures as well.
  * **duplicate** – If `True`, allow logic to be duplicated.
  * **duplicate_critical** – If `True`, duplicate logic on the critical paths
    only, which buys depth for less area than `duplicate` does.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.

### *class* Orchestrate

Bases: `aigverse.abc._runner.CommandWrapper`

Runs ABC’s `orchestrate` command on a network, or builds it as a command.

#### *static* cmd(, max_cut_size: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, max_inserts: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, odc_levels: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, preserve_levels: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, zero_cost_rewrite: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, zero_cost_refactor: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True) → aigverse.abc._runner.Command

Builds ABC’s `orchestrate` command without running it.

* **Parameters:**
  * **max_cut_size** – Resubstitution cut size (ABC’s `-K`, 4 to 16), or `None`
    for ABC’s default of 8.
  * **max_inserts** – Nodes resubstitution may add (ABC’s `-N`, 0 to 3), or
    `None` for ABC’s default of 1.
  * **odc_levels** – Fanout levels used for don’t-care computation (ABC’s `-F`),
    or `None` for ABC’s default of 0.
  * **preserve_levels** – If `True` (ABC’s default), never increase the depth.
  * **zero_cost_rewrite** – If `True` (ABC’s default here), let the rewriting
    part apply replacements that do not reduce the size.
  * **zero_cost_refactor** – If `True` (ABC’s default here), the same for the
    refactoring part.
* **Returns:**
  The command, ready for [`run_script()`](#aigverse.abc.run_script) or
  [`run_many()`](#aigverse.abc.run_many).
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If an option is outside the range ABC accepts.

#### \_\_call_\_(ntk: aigverse.abc._runner.AigT, , max_cut_size: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, max_inserts: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, odc_levels: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, preserve_levels: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, zero_cost_rewrite: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, zero_cost_refactor: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `orchestrate` command on a network.

Interleaves rewriting, refactoring and resubstitution rather than running
them one after another, choosing per node which of the three to apply. It is
a single command doing the job of a whole schedule.

Note that ABC enables zero-cost replacements here by default, unlike in the
standalone [`rewrite`](#aigverse.abc.rewrite) and [`refactor`](#aigverse.abc.refactor) commands.

* **Parameters:**
  * **ntk** – The network to optimize.
  * **max_cut_size** – Resubstitution cut size (ABC’s `-K`, 4 to 16), or `None`
    for ABC’s default of 8.
  * **max_inserts** – Nodes resubstitution may add (ABC’s `-N`, 0 to 3), or
    `None` for ABC’s default of 1.
  * **odc_levels** – Fanout levels used for don’t-care computation (ABC’s `-F`),
    or `None` for ABC’s default of 0.
  * **preserve_levels** – If `True` (ABC’s default), never increase the depth.
  * **zero_cost_rewrite** – If `True` (ABC’s default here), let the rewriting
    part apply replacements that do not reduce the size.
  * **zero_cost_refactor** – If `True` (ABC’s default here), the same for the
    refactoring part.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If an option is outside the range ABC accepts.

### *class* Refactor

Bases: `aigverse.abc._runner.CommandWrapper`

Runs ABC’s `refactor` command on a network, or builds it as a command.

#### *static* cmd(, max_support: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, min_saved: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, preserve_levels: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, zero_cost: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False) → aigverse.abc._runner.Command

Builds ABC’s `refactor` command without running it.

* **Parameters:**
  * **max_support** – Maximum support of a collapsed node (ABC’s `-N`, 1 to 15),
    or `None` for ABC’s default of 10. Larger values are slower. ABC
    documents no range but rejects anything above 15.
  * **min_saved** – Minimum number of nodes a single step must save to be applied
    (ABC’s `-M`, at least 0), or `None` for ABC’s default of 1.
    Setting it to 0 accepts steps that save nothing.
  * **preserve_levels** – If `True` (ABC’s default), never increase the depth.
  * **zero_cost** – If `True`, also apply replacements that do not reduce the
    size, which perturbs the structure and can unlock later gains.
* **Returns:**
  The command, ready for [`run_script()`](#aigverse.abc.run_script) or
  [`run_many()`](#aigverse.abc.run_many).
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `max_support` is outside the range ABC accepts.

#### \_\_call_\_(ntk: aigverse.abc._runner.AigT, , max_support: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, min_saved: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, preserve_levels: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, zero_cost: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `refactor` command on a network.

Collapses a cone into a single node and resynthesizes it from its truth
table, which reaches larger cuts than [`rewrite`](#aigverse.abc.rewrite) does.

* **Parameters:**
  * **ntk** – The network to optimize.
  * **max_support** – Maximum support of a collapsed node (ABC’s `-N`, 1 to 15),
    or `None` for ABC’s default of 10. Larger values are slower. ABC
    documents no range but rejects anything above 15.
  * **min_saved** – Minimum number of nodes a single step must save to be applied
    (ABC’s `-M`, at least 0), or `None` for ABC’s default of 1.
    Setting it to 0 accepts steps that save nothing.
  * **preserve_levels** – If `True` (ABC’s default), never increase the depth.
  * **zero_cost** – If `True`, also apply replacements that do not reduce the
    size, which perturbs the structure and can unlock later gains.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `max_support` is outside the range ABC accepts.

### *class* Resub

Bases: `aigverse.abc._runner.CommandWrapper`

Runs ABC’s `resub` command on a network, or builds it as a command.

#### *static* cmd(, max_cut_size: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, max_inserts: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, min_saved: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, odc_levels: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, preserve_levels: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, zero_cost: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False) → aigverse.abc._runner.Command

Builds ABC’s `resub` command without running it.

* **Parameters:**
  * **max_cut_size** – Maximum cut size (ABC’s `-K`, 4 to 16), or `None` for
    ABC’s default of 8. The canonical scripts sweep this from 6 to 12.
  * **max_inserts** – Maximum number of nodes to add (ABC’s `-N`, 0 to 3), or
    `None` for ABC’s default of 1.
  * **min_saved** – Minimum number of nodes a single step must save to be applied
    (ABC’s `-M`, at least 0), or `None` for ABC’s default of 1.
  * **odc_levels** – Fanout levels used for observability-don’t-care computation
    (ABC’s `-F`, at least 0), or `None` for ABC’s default of 0, which
    disables it. Don’t-cares find substitutions that are only valid in
    context, at the cost of a more expensive analysis.
  * **preserve_levels** – If `True` (ABC’s default), never increase the depth.
  * **zero_cost** – If `True`, also apply replacements that do not reduce the
    size, which perturbs the structure and can unlock later gains.
* **Returns:**
  The command, ready for [`run_script()`](#aigverse.abc.run_script) or
  [`run_many()`](#aigverse.abc.run_many).
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `max_cut_size` or `max_inserts` is outside the range
  ABC accepts.

#### \_\_call_\_(ntk: aigverse.abc._runner.AigT, , max_cut_size: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, max_inserts: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, min_saved: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, odc_levels: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, preserve_levels: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, zero_cost: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `resub` command on a network.

Re-expresses a node in terms of other nodes already present, which removes
logic that rewriting and refactoring cannot reach because it is not local.

* **Parameters:**
  * **ntk** – The network to optimize.
  * **max_cut_size** – Maximum cut size (ABC’s `-K`, 4 to 16), or `None` for
    ABC’s default of 8. The canonical scripts sweep this from 6 to 12.
  * **max_inserts** – Maximum number of nodes to add (ABC’s `-N`, 0 to 3), or
    `None` for ABC’s default of 1.
  * **min_saved** – Minimum number of nodes a single step must save to be applied
    (ABC’s `-M`, at least 0), or `None` for ABC’s default of 1.
  * **odc_levels** – Fanout levels used for observability-don’t-care computation
    (ABC’s `-F`, at least 0), or `None` for ABC’s default of 0, which
    disables it. Don’t-cares find substitutions that are only valid in
    context, at the cost of a more expensive analysis.
  * **preserve_levels** – If `True` (ABC’s default), never increase the depth.
  * **zero_cost** – If `True`, also apply replacements that do not reduce the
    size, which perturbs the structure and can unlock later gains.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `max_cut_size` or `max_inserts` is outside the range
  ABC accepts.

### *class* Rewrite

Bases: `aigverse.abc._runner.CommandWrapper`

Runs ABC’s `rewrite` command on a network, or builds it as a command.

#### *static* cmd(, preserve_levels: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, zero_cost: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False) → aigverse.abc._runner.Command

Builds ABC’s `rewrite` command without running it.

* **Parameters:**
  * **preserve_levels** – If `True` (ABC’s default), never increase the depth.
  * **zero_cost** – If `True`, also apply replacements that do not reduce the
    size, which perturbs the structure and can unlock later gains.
* **Returns:**
  The command, ready for [`run_script()`](#aigverse.abc.run_script) or
  [`run_many()`](#aigverse.abc.run_many).

#### \_\_call_\_(ntk: aigverse.abc._runner.AigT, , preserve_levels: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, zero_cost: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `rewrite` command on a network.

Replaces 4-input subgraphs with smaller pre-computed equivalents.

* **Parameters:**
  * **ntk** – The network to optimize.
  * **preserve_levels** – If `True` (ABC’s default), never increase the depth.
  * **zero_cost** – If `True`, also apply replacements that do not reduce the
    size, which perturbs the structure and can unlock later gains.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.

### balance *: Final[[Balance](#aigverse.abc.Balance)]*

Runs ABC’s `balance` command on a network, or builds it as a command; see [`Balance`](#aigverse.abc.Balance).

### orchestrate *: Final[[Orchestrate](#aigverse.abc.Orchestrate)]*

Runs ABC’s `orchestrate` command on a network, or builds it as a command; see [`Orchestrate`](#aigverse.abc.Orchestrate).

### refactor *: Final[[Refactor](#aigverse.abc.Refactor)]*

Runs ABC’s `refactor` command on a network, or builds it as a command; see [`Refactor`](#aigverse.abc.Refactor).

### resub *: Final[[Resub](#aigverse.abc.Resub)]*

Runs ABC’s `resub` command on a network, or builds it as a command; see [`Resub`](#aigverse.abc.Resub).

### rewrite *: Final[[Rewrite](#aigverse.abc.Rewrite)]*

Runs ABC’s `rewrite` command on a network, or builds it as a command; see [`Rewrite`](#aigverse.abc.Rewrite).

### *exception* AbcError

Bases: [`RuntimeError`](https://docs.python.org/3/builtins/exceptions.html#RuntimeError)

Base class for every failure raised by the ABC bridge.

### *exception* AbcExecutionError(message: [str](https://docs.python.org/3/builtins/stdtypes.html#str), , binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str), command: [str](https://docs.python.org/3/builtins/stdtypes.html#str), output: [str](https://docs.python.org/3/builtins/stdtypes.html#str))

Bases: [`AbcError`](#aigverse.abc.AbcError)

Raised when ABC ran but did not produce a usable result.

ABC exits with status 0 even for unknown commands and unreadable files, and
writes everything to standard output, so the captured output is the only
diagnostic available. It is attached to the exception as `output`, next to
the `binary` that was invoked and the `command` it was given.

#### binary

#### command

#### output

### *exception* AbcNotFoundError

Bases: [`AbcError`](#aigverse.abc.AbcError)

Raised when no usable ABC executable could be located.

### *exception* AbcTimeoutError(message: [str](https://docs.python.org/3/builtins/stdtypes.html#str), , binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str), command: [str](https://docs.python.org/3/builtins/stdtypes.html#str), output: [str](https://docs.python.org/3/builtins/stdtypes.html#str))

Bases: [`AbcExecutionError`](#aigverse.abc.AbcExecutionError)

Raised when ABC did not terminate within the requested timeout.

### *class* Command

One ABC command with its switches, built without being run.

Every wrapper’s `cmd()` returns one of these, e.g.
`abc.rewrite.cmd(zero_cost=True)`. It renders as the command ABC takes, and
[`run_script()`](#aigverse.abc.run_script), [`run_commands()`](#aigverse.abc.run_commands) and
[`run_many()`](#aigverse.abc.run_many) accept it wherever they accept a command
string – a whole script is a sequence of them.

#### text *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

#### \_\_str_\_() → [str](https://docs.python.org/3/builtins/stdtypes.html#str)

Renders the command in ABC’s own syntax.

* **Returns:**
  The command as ABC takes it.

### *class* CommandWrapper

What every wrapper is: callable on a network, with a `cmd()` that only builds.

`abc.rewrite` and its siblings are module-level instances of one subclass each,
so a subclass’s lowercased name is the instance’s public name, which is what
`repr()` shows in place of an object address.

#### cmd *: [Callable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[..., [Command](#aigverse.abc.Command)]*

Builds the wrapper’s command without running it.

Each wrapper declares its own options here; its `__call__` takes the same
ones plus the run parameters.

#### \_\_repr_\_() → [str](https://docs.python.org/3/builtins/stdtypes.html#str)

Renders the wrapper as the public name it is reached by.

* **Returns:**
  The dotted name, e.g. `aigverse.abc.rewrite` or `aigverse.abc.gia.dc2`.

### run_commands(commands: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [Command](#aigverse.abc.Command) | [Sequence](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[str](https://docs.python.org/3/builtins/stdtypes.html#str) | [Command](#aigverse.abc.Command)], , timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, use_init_file: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, cwd: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → [str](https://docs.python.org/3/builtins/stdtypes.html#str)

Runs raw ABC commands and returns their combined output.

No network is transferred; this is the escape hatch for commands such as
`version` or `print_stats` on files the caller manages themselves.

* **Parameters:**
  * **commands** – A single `;`-separated command string, a [`Command`](#aigverse.abc.Command),
    or a sequence of individual commands.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **use_init_file** – If `False` (default), ABC is invoked with `-s` so that
    no `abc.rc` is read and behaviour does not depend on the local
    install. Set to `True` to let ABC pick up an `abc.rc` from the
    working directory. Prefer [`set_abc_rc()`](#aigverse.abc.set_abc_rc), which
    loads one specific file and keeps the isolation.
  * **cwd** – Working directory for the ABC process. Defaults to a fresh
    temporary directory, because ABC writes an `abc.history` file into
    wherever it runs. Pass a directory explicitly if the commands refer
    to files by relative path.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  Everything ABC wrote to its output.
* **Raises:**
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If no command was given.
  * [**AbcNotFoundError**](#aigverse.abc.AbcNotFoundError) – If no ABC executable could be located.
  * [**AbcTimeoutError**](#aigverse.abc.AbcTimeoutError) – If ABC did not terminate within `timeout` seconds.
  * [**AbcExecutionError**](#aigverse.abc.AbcExecutionError) – If ABC reported an error.

### run_script(ntk: AigT, commands: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [Command](#aigverse.abc.Command) | [Sequence](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[str](https://docs.python.org/3/builtins/stdtypes.html#str) | [Command](#aigverse.abc.Command)], , timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, use_init_file: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, gia: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → AigT

Optimizes a network by piping it through an external ABC process.

The network is written to a temporary binary AIGER file, ABC is invoked with
a read command, the given commands, and a write command, and the result is
read back. The returned network has the same type as `ntk`: an `Aig`
yields an `Aig`, a `NamedAig` yields a `NamedAig` with its input and
output names preserved, and a `SequentialAig` yields a `SequentialAig`
with its registers and their reset values intact.

ABC keeps two independent network stores, and a command only ever sees the
one it belongs to. By default the network is loaded with `read_aiger` into
the classic store, where the commands without a `&` prefix operate
(`balance`, `rewrite`, `refactor`, `resub`, and hence every script in
[`SCRIPTS`](#aigverse.abc.SCRIPTS)). The `&`-prefixed commands of ABC9 operate
on a separate store, the GIA, which stays empty in that mode – a script such
as `"&syn2"` fails with *there is no AIG* unless it starts with `&get`.
Set `gia=True` to load the network straight into the GIA with `&read`
instead, which is the cheaper and lossless way to run a `&` script.

`commands` must not contain the read and write steps; they are added
automatically. Only commands the resolved ABC binary knows are valid –
`resyn2` and friends are `abc.rc` aliases rather than builtins, so use
the wrappers in this module or [`SCRIPTS`](#aigverse.abc.SCRIPTS).

* **Parameters:**
  * **ntk** – The network to optimize.
  * **commands** – A single `;`-separated ABC command string, a
    [`Command`](#aigverse.abc.Command), or a sequence of individual commands.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **use_init_file** – If `False` (default), ABC is invoked with `-s` so that
    no `abc.rc` is read and results do not depend on the local install.
    A resource file registered with [`set_abc_rc()`](#aigverse.abc.set_abc_rc) is
    loaded regardless, making its aliases available.
  * **gia** – If `True`, transfer the network through `&read`/`&write` so it
    lands in ABC9’s GIA store and `&`-prefixed commands can be used
    directly. The classic commands then see nothing instead. Mixing the
    two within one script is possible with `&get`/`&put`, but those
    do not carry I/O names across, whereas `&read`/`&write` do.
  * **verbose** – If `True`, print everything ABC wrote. This is the captured
    output, not ABC’s own `-v` reporting – that differs per command and
    is left to the caller to add to `commands`.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If `ntk` is not an `Aig`.
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If no command was given, or if `gia` is set and `ntk` has
    a register whose reset value is undefined.
  * [**AbcNotFoundError**](#aigverse.abc.AbcNotFoundError) – If no ABC executable could be located.
  * [**AbcTimeoutError**](#aigverse.abc.AbcTimeoutError) – If ABC did not terminate within `timeout` seconds.
  * [**AbcExecutionError**](#aigverse.abc.AbcExecutionError) – If ABC reported an error or produced no usable output.

### SCRIPTS *: Final[[Mapping](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), ...]]]*

### expand_script(name: [str](https://docs.python.org/3/builtins/stdtypes.html#str)) → [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), ...]

Expands a canonical ABC script name into builtin commands.

* **Parameters:**
  **name** – The script name, e.g. `"resyn2"`. See [`SCRIPTS`](#aigverse.abc.SCRIPTS) for the
  available names.
* **Returns:**
  The commands the script consists of, all of them ABC builtins.
* **Raises:**
  [**KeyError**](https://docs.python.org/3/builtins/exceptions.html#KeyError) – If `name` is not a known script.

### *class* AbcStats

What ABC reports about a network.

ABC’s own network name is deliberately absent: the bridge transfers through
a temporary file, so it is always that file’s stem and never says anything
about the network. It survives verbatim in [`raw`](#aigverse.abc.AbcStats.raw).

#### num_pis *: [int](https://docs.python.org/3/builtins/functions.html#int)*

#### num_pos *: [int](https://docs.python.org/3/builtins/functions.html#int)*

#### num_gates *: [int](https://docs.python.org/3/builtins/functions.html#int)*

#### num_levels *: [int](https://docs.python.org/3/builtins/functions.html#int)*

#### num_registers *: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None)* *= None*

#### average_level *: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None)* *= None*

#### memory_mb *: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None)* *= None*

#### raw *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)* *= ''*

### stats(ntk: [Aig](../networks/index.html.md#aigverse.networks.Aig), , timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → [AbcStats](#aigverse.abc.AbcStats)

Reports ABC’s `print_stats` for a network.

#### WARNING
These are ABC’s counts, not `aigverse`’s, and the two can differ for the
very same network. ABC structurally hashes as it reads, so any structural
redundancy the network carried is gone before `print_stats` sees it: a
16-bit carry-lookahead adder that `aigverse` reports as 186 gates comes
back from here as 182. Use [`num_gates`](../networks/index.html.md#aigverse.networks.Aig.num_gates) to
describe the network you hold, and this to describe what ABC worked on.

* **Parameters:**
  * **ntk** – The network to measure.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  What ABC reports about the network.
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If `ntk` is not an `Aig`.
  * [**AbcNotFoundError**](#aigverse.abc.AbcNotFoundError) – If no ABC executable could be located.
  * [**AbcTimeoutError**](#aigverse.abc.AbcTimeoutError) – If ABC did not terminate within `timeout` seconds.
  * [**AbcExecutionError**](#aigverse.abc.AbcExecutionError) – If ABC reported an error or printed nothing usable.

### compress(ntk: aigverse.abc._runner.AigT, , timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `compress` script on a network.

Like `resyn`, but every command is given `-l`, which turns ABC’s default
level preservation *off* and lets it trade depth for size.

The script is expanded into builtin ABC commands, so it does not depend on
an `abc.rc` being present. See [`SCRIPTS`](#aigverse.abc.SCRIPTS) for the exact expansion.
Errors are reported the same way as by [`run_script()`](#aigverse.abc.run_script).

* **Parameters:**
  * **ntk** – The network to optimize.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.

### compress2(ntk: aigverse.abc._runner.AigT, , timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `compress2` script on a network.

Like `resyn2`, but every command is given `-l`, which turns ABC’s default
level preservation *off* and lets it trade depth for size.

The script is expanded into builtin ABC commands, so it does not depend on
an `abc.rc` being present. See [`SCRIPTS`](#aigverse.abc.SCRIPTS) for the exact expansion.
Errors are reported the same way as by [`run_script()`](#aigverse.abc.run_script).

* **Parameters:**
  * **ntk** – The network to optimize.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.

### compress2rs(ntk: aigverse.abc._runner.AigT, , timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `compress2rs` script on a network.

`resyn2rs` with level preservation turned off; the strongest of these
scripts, and the slowest.

The script is expanded into builtin ABC commands, so it does not depend on
an `abc.rc` being present. See [`SCRIPTS`](#aigverse.abc.SCRIPTS) for the exact expansion.
Errors are reported the same way as by [`run_script()`](#aigverse.abc.run_script).

* **Parameters:**
  * **ntk** – The network to optimize.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.

### dc2(ntk: aigverse.abc._runner.AigT, , timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `dc2` script on a network.

ABC’s builtin combinational don’t-care-based optimization.

The script is expanded into builtin ABC commands, so it does not depend on
an `abc.rc` being present. See [`SCRIPTS`](#aigverse.abc.SCRIPTS) for the exact expansion.
Errors are reported the same way as by [`run_script()`](#aigverse.abc.run_script).

* **Parameters:**
  * **ntk** – The network to optimize.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.

### resyn(ntk: aigverse.abc._runner.AigT, , timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `resyn` script on a network.

A short balance/rewrite loop; the lightest of the standard scripts.

The script is expanded into builtin ABC commands, so it does not depend on
an `abc.rc` being present. See [`SCRIPTS`](#aigverse.abc.SCRIPTS) for the exact expansion.
Errors are reported the same way as by [`run_script()`](#aigverse.abc.run_script).

* **Parameters:**
  * **ntk** – The network to optimize.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.

### resyn2(ntk: aigverse.abc._runner.AigT, , timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `resyn2` script on a network.

The most widely used ABC size-reduction script.

The script is expanded into builtin ABC commands, so it does not depend on
an `abc.rc` being present. See [`SCRIPTS`](#aigverse.abc.SCRIPTS) for the exact expansion.
Errors are reported the same way as by [`run_script()`](#aigverse.abc.run_script).

* **Parameters:**
  * **ntk** – The network to optimize.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.

### resyn2rs(ntk: aigverse.abc._runner.AigT, , timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `resyn2rs` script on a network.

`resyn2` extended with resubstitution passes; slower and usually smaller.

The script is expanded into builtin ABC commands, so it does not depend on
an `abc.rc` being present. See [`SCRIPTS`](#aigverse.abc.SCRIPTS) for the exact expansion.
Errors are reported the same way as by [`run_script()`](#aigverse.abc.run_script).

* **Parameters:**
  * **ntk** – The network to optimize.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.

### resyn3(ntk: aigverse.abc._runner.AigT, , timeout: [float](https://docs.python.org/3/builtins/functions.html#float) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, verbose: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, binary: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [PathLike](https://docs.python.org/3/library/os.html#os.PathLike)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None) → aigverse.abc._runner.AigT

Runs ABC’s `resyn3` script on a network.

A resubstitution-driven variant of `resyn`.

The script is expanded into builtin ABC commands, so it does not depend on
an `abc.rc` being present. See [`SCRIPTS`](#aigverse.abc.SCRIPTS) for the exact expansion.
Errors are reported the same way as by [`run_script()`](#aigverse.abc.run_script).

* **Parameters:**
  * **ntk** – The network to optimize.
  * **timeout** – Seconds to wait for ABC to terminate, or `None` for no limit.
  * **verbose** – If `True`, print everything ABC wrote.
  * **binary** – Overrides the resolved ABC executable for this call only.
* **Returns:**
  The optimized network, of the same type as `ntk`.

### *class* CecStatus(\*args, \*\*kwds)

Bases: [`enum.Enum`](https://docs.python.org/3/library/enum.html#enum.Enum)

The outcome of an equivalence check.

Deliberately not usable as a boolean: `if cec(a, b):` would read as
“equivalent” while quietly also firing for [`UNDECIDED`](#aigverse.abc.CecStatus.UNDECIDED) and
[`TIMEOUT`](#aigverse.abc.CecStatus.TIMEOUT), which are not the same claim at all. Compare explicitly:

```default
if abc.gia.cec(a, b) is abc.gia.CecStatus.EQUIVALENT:
    ...
```

#### EQUIVALENT *= 'equivalent'*

#### NOT_EQUIVALENT *= 'not equivalent'*

#### UNDECIDED *= 'undecided'*

#### TIMEOUT *= 'timeout'*

#### \_\_bool_\_() → [bool](https://docs.python.org/3/builtins/functions.html#bool)

Refuses truth testing.

* **Raises:**
  [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – Always. Compare against a member instead.
