<a id="clocking-schemes"></a>

# Clocking Schemes

**Header:** `fiction/layouts/clocking_scheme.hpp`

Clocking is one of the most important differences between conventional CMOS technologies and the FCN domain. Clocking
directs information flow and provides a notion of timing for both combinational and sequential circuits alike. Usually,
clocking information is assigned to the coordinates of a layout by the means of a clocking scheme.

This header provides the `clocking::scheme` value type, which assigns a clock number to every tile position
$(x, y)$ of a gate-level or tile-clocked cell-level layout by repeating a rectangular cutout in all directions, as well
as pre-defined schemes from the literature. Schemes can be copied, assigned, and compared, and individual clock numbers
can be overridden.

## Scheme Types

### class unsupported_scheme_exception : public std::exception

Exception to be thrown when an unsupported clocking scheme is requested. 

### Public Functions

### inline explicit unsupported_scheme_exception() noexcept

### inline const char \*what() const noexcept override

Returns the diagnostic message for an unsupported clocking scheme.

* **Returns:**
  A null-terminated diagnostic message. 

### class scheme

Clocking scheme that assigns a clock number to every tile position $(x, y)$. Clocking schemes are owned by gate and tile-clocked cell layouts. A clock zone spans every layer, so a scheme has no z-coordinate.

A clocking scheme is defined by a rectangular cutout that repeats seamlessly in all directions, including negative coordinates. Clock numbers can be overridden per tile. Many regular clocking schemes have been proposed in the literature; the factories below construct them.

Schemes are values: they can be copied, assigned, and compared. Two schemes are equal iff their names, phase counts, degrees, cutouts, regularity, and overridden clock numbers are equal. 

### Public Types

### using clock_number = uint8_t

Clock phase index. 

### using degree = uint8_t

Number of inputs or outputs of a clock zone. 

### Public Functions

### scheme() noexcept = default

Creates a four-phase OPEN scheme without allocating storage. 

### inline scheme(std::string n, const std::vector<std::vector<[clock_number](#_CPPv4N7fiction7layouts8clocking6scheme12clock_numberE)>> &cutout, const [clock_number](#_CPPv4N7fiction7layouts8clocking6scheme12clock_numberE) num_clocks, const [degree](#_CPPv4N7fiction7layouts8clocking6scheme6degreeE) max_in_degree, const [degree](#_CPPv4N7fiction7layouts8clocking6scheme6degreeE) max_out_degree, const bool regular = true)

Standard constructor.

* **Parameters:**
  * **n** – The clocking scheme’s stored name. Construction does not register the scheme with `get_scheme`. 
  * **cutout** – Rows of clock numbers. Row `y`, column `x` holds the clock number of every tile $(x + i \cdot w, y + j \cdot h)$ for all integers $i, j$, where $w$ and $h$ are the width and height of `cutout`. 
  * **num_clocks** – Number of clock phases that make up one clock cycle. Must be 3 or 4. 
  * **max_in_degree** – Maximum number of inputs the scheme supports per clock zone. 
  * **max_out_degree** – Maximum number of outputs the scheme supports per clock zone. 
  * **regular** – Flag to identify the scheme as regular. 
* **Throws:**
  std::invalid_argument – if `cutout` is empty or not rectangular, if `[num_clocks](#classfiction_1_1layouts_1_1clocking_1_1scheme_1a213333d1546fcb1e54a0df0f15b99398)` is neither 3 nor 4, or if an entry of `cutout` is not below `[num_clocks](#classfiction_1_1layouts_1_1clocking_1_1scheme_1a213333d1546fcb1e54a0df0f15b99398)`. 

### scheme(const [scheme](#_CPPv4N7fiction7layouts8clocking6scheme6schemeERK6scheme)&) = default

Copies the complete clocking scheme. 

### scheme([scheme](#_CPPv4N7fiction7layouts8clocking6scheme6schemeERR6scheme)&&) noexcept = default

Moves the clocking scheme. 

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) &operator=(const [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) &other)

Replaces the scheme with an independent copy. Copy failure preserves this scheme. 

* **Parameters:**
  **other** – Scheme to copy. 
* **Throws:**
  std::bad_alloc – If allocation fails. 
* **Returns:**
  This scheme. 

### [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) &operator=([scheme](#_CPPv4N7fiction7layouts8clocking6schemeE)&&) noexcept = default

Moves the clocking scheme. 

* **Returns:**
  This scheme. 

### ~scheme() = default

Releases owned clocking state. 

### inline [clock_number](#_CPPv4N7fiction7layouts8clocking6scheme12clock_numberE) operator()(const int64_t x, const int64_t y) const noexcept

Returns the clock number of the tile at $(x, y)$: its overridden clock number if one exists, and the repeated cutout entry otherwise.

* **Parameters:**
  * **x** – x-coordinate of the tile. 
  * **y** – y-coordinate of the tile. 
* **Returns:**
  Clock number of $(x, y)$. 

### inline void override_clock_number(const int64_t x, const int64_t y, const [clock_number](#_CPPv4N7fiction7layouts8clocking6scheme12clock_numberE) cn)

Overrides the clock number of the tile at $(x, y)$. An overridden scheme is irregular.

* **Parameters:**
  * **x** – x-coordinate of the tile. 
  * **y** – y-coordinate of the tile. 
  * **cn** – Clock number to assign. The scheme stores `cn % [num_clocks()](#classfiction_1_1layouts_1_1clocking_1_1scheme_1a213333d1546fcb1e54a0df0f15b99398)`. 
* **Throws:**
  std::bad_alloc – If allocation fails. 

### inline bool is_regular() const noexcept

Checks for the clocking scheme’s regularity.

* **Returns:**
  `true` iff the scheme is regular and no clock number is overridden. 

### inline std::string_view name() const noexcept

Name of the clocking scheme.

The view borrows storage from this scheme. Keep the scheme alive and unchanged while using the view, or copy it with `std::string{[scheme.name()](#classfiction_1_1layouts_1_1clocking_1_1scheme_1aebf9bca78e7b4e1a486f21e618ef0520)}`.

* **Returns:**
  The name supplied at construction, or `"OPEN"` for a default-constructed scheme. Catalog factories use canonical names, e.g., `"2DDWAVE"`, without a phase-count suffix. 

### inline [clock_number](#_CPPv4N7fiction7layouts8clocking6scheme12clock_numberE) num_clocks() const noexcept

Number of clock phases in this scheme.

* **Returns:**
  3 or 4. 

### inline [degree](#_CPPv4N7fiction7layouts8clocking6scheme6degreeE) max_in_degree() const noexcept

Maximum number of inputs the scheme supports per clock zone.

* **Returns:**
  Maximum in-degree, or `[UNBOUNDED](#classfiction_1_1layouts_1_1clocking_1_1scheme_1ae08cba421ab8ac1a65cbc3f641ce36fc)`. 

### inline [degree](#_CPPv4N7fiction7layouts8clocking6scheme6degreeE) max_out_degree() const noexcept

Maximum number of outputs the scheme supports per clock zone.

* **Returns:**
  Maximum out-degree, or `[UNBOUNDED](#classfiction_1_1layouts_1_1clocking_1_1scheme_1ae08cba421ab8ac1a65cbc3f641ce36fc)`. 

### inline bool operator==(const [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) &other) const

Compares all properties of two schemes, overridden clock numbers included.

* **Parameters:**
  **other** – Scheme to compare against. 
* **Returns:**
  `true` iff both schemes are equal. 

### template<typename Fn>inline void foreach_override([Fn](#_CPPv4I0ENK7fiction7layouts8clocking6scheme16foreach_overrideEvRR2Fn) &&fn) const

Visits manually overridden clock numbers. 

* **Template Parameters:**
  **Fn** – Callable accepting x, y, and clock number. 
* **Parameters:**
  **fn** – Callback for each override. 

### Public Static Attributes

### static constexpr [degree](#_CPPv4N7fiction7layouts8clocking6scheme6degreeE) UNBOUNDED = std::numeric_limits<[degree](#_CPPv4N7fiction7layouts8clocking6scheme6degreeE)>::max()

Degree of a scheme that imposes no bound beyond the fan-in of the layout topology. 

### enum class [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::num_clks : uint8_t

Number of clock phases of a clocking scheme. 

*Values:*

### enumerator THREE

Three clocks. 

### enumerator FOUR

Four clocks. 

The [Hexagonal Layout](hexagonal_layout.html.md) page documents the `arrangement` type.

<a id="pre-defined-schemes"></a>

## Pre-Defined Schemes

### Open

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::open(const [num_clks](#_CPPv4N7fiction7layouts8clocking8num_clksE) n = [num_clks](#_CPPv4N7fiction7layouts8clocking8num_clksE)::[FOUR](#_CPPv4N7fiction7layouts8clocking8num_clks4FOURE))

Returns an irregular clocking that maps every tile to clock number 0. It is intended to be overridden. Its degrees are `[scheme::UNBOUNDED](#classfiction_1_1layouts_1_1clocking_1_1scheme_1ae08cba421ab8ac1a65cbc3f641ce36fc)`, i.e., only the layout topology bounds them.

* **Parameters:**
  **n** – Number of clocks. 
* **Returns:**
  Irregular clocking scheme. 

### Columnar

![Columnar clocking scheme with phases progressing across columns](_static/columnar.png)

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::columnar(const [num_clks](#_CPPv4N7fiction7layouts8clocking8num_clksE) n = [num_clks](#_CPPv4N7fiction7layouts8clocking8num_clksE)::[FOUR](#_CPPv4N7fiction7layouts8clocking8num_clks4FOURE))

Returns a linear 1D clocking as originally introduced in “A device architecture for computing with quantum dots” by C. S. Lent and P. D. Tougaw in the Proceedings of the IEEE 1997.

* **Parameters:**
  **n** – Number of clocks. 
* **Returns:**
  Columnar clocking scheme. 

### Row

![Row clocking scheme with phases progressing across rows](_static/row.png)

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::row(const [num_clks](#_CPPv4N7fiction7layouts8clocking8num_clksE) n = [num_clks](#_CPPv4N7fiction7layouts8clocking8num_clksE)::[FOUR](#_CPPv4N7fiction7layouts8clocking8num_clks4FOURE))

Returns a 90° rotated linear 1D clocking based on the one originally introduced in “A device architecture for computing with quantum dots” by C. S. Lent and P. D. Tougaw in the Proceedings of the IEEE 1997.

* **Parameters:**
  **n** – Number of clocks. 
* **Returns:**
  Row-based clocking scheme. 

### 2DDWave

![2DDWave clocking scheme with phases progressing along two dimensions](_static/2ddwave.png)

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::twoddwave(const [num_clks](#_CPPv4N7fiction7layouts8clocking8num_clksE) n = [num_clks](#_CPPv4N7fiction7layouts8clocking8num_clksE)::[FOUR](#_CPPv4N7fiction7layouts8clocking8num_clks4FOURE))

Returns the 2DDWave clocking as defined in “Clocking and Cell Placement for QCA” by V. Vankamamidi, M. Ottavi, and F. Lombardi in IEEE Conference on Nanotechnology 2006.

* **Parameters:**
  **n** – Number of clocks. 
* **Returns:**
  2DDWave clocking scheme. 

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::twoddwave_hex(const [arrangement](hexagonal_layout.html.md#_CPPv4N7fiction7layouts11arrangementE) a, const [num_clks](#_CPPv4N7fiction7layouts8clocking8num_clksE) n = [num_clks](#_CPPv4N7fiction7layouts8clocking8num_clksE)::[FOUR](#_CPPv4N7fiction7layouts8clocking8num_clks4FOURE))

Returns a hexagonal variation of the 2DDWave clocking as originally defined in “Clocking and Cell Placement for QCA” by V. Vankamamidi, M. Ottavi, and F. Lombardi in IEEE Conference on Nanotechnology 2006.

* **Parameters:**
  * **a** – Arrangement of the hexagonal layout’s shifted rows or columns. 
  * **n** – Number of clocks. 
* **Returns:**
  Hexagonal 2DDWave clocking scheme. 

### USE

![USE clocking scheme](_static/use.png)

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::use()

Returns the USE clocking as defined in “USE: A Universal, Scalable, and Efficient Clocking Scheme for QCA” by Caio Araujo T. Campos, Abner L. Marciano, Omar P. Vilela Neto, and Frank Sill Torres in TCAD 2015.

* **Returns:**
  USE clocking scheme. 

### RES

![RES clocking scheme](_static/res.png)

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::res()

Returns the RES clocking as defined in “An efficient clocking scheme for quantum-dot cellular automata” by Mrinal Goswami, Anindan Mondal, Mahabub Hasan Mahalat, Bibhash Sen, and Biplab K. Sikdar in International Journal of Electronics Letters 2019.

* **Returns:**
  RES clocking scheme. 

### ESR

![ESR clocking scheme](_static/esr.png)

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::esr()

Returns the ESR clocking as defined in “An efficient, scalable, regular clocking scheme based on quantum dot cellular automata” by Jayanta Pal, Amit Kumar Pramanik, Jyotirmoy Sil Sharma, Apu Kumar Saha, and Bibhash Sen in Analog Integrated Circuits and Signal Processing 2021.

* **Returns:**
  ESR clocking scheme. 

### CFE

![CFE clocking scheme](_static/cfe.png)

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::cfe()

Returns the CFE clocking as defined in “CFE: a convenient, flexible, and efficient clocking scheme for quantum-dot cellular automata” by Feifei Deng, Guang-Jun Xie, Xin Cheng, Zhang Zhang, and Yongqiang Zhang in IET Circuits, Devices & Systems 2020.

* **Returns:**
  CFE clocking scheme. 

### Ripple

![Ripple clocking scheme](_static/ripple.png)

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::ripple()

Returns the Ripple clocking as defined in “Ripple Clock Schemes for Quantum-dot Cellular Automata Circuits” by Prafull Purohit, Master Thesis, Rochester Institute of Technology, 2012.

* **Returns:**
  Ripple clocking scheme. 

### SRS

![SRS clocking scheme](_static/srs.png)

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::srs()

Returns the SRS clocking as defined in “Simple, robust and systematic QCA clocking scheme for area-efficient nanocircuits” by Mrinal Goswami, Tonmoy Jyoti Sharma, and Arpita Nath Boruah in International Journal of Electronics Letters 2025.

* **Returns:**
  SRS clocking scheme. 

### BANCS

![BANCS clocking scheme](_static/bancs.png)

### inline [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::bancs()

Returns the BANCS clocking as defined in “BANCS: Bidirectional Alternating Nanomagnetic Clocking Scheme” by Ruan Evangelista Formigoni, Omar P. Vilela Neto, and Jose Augusto M. Nacif in SBCCI 2018.

* **Returns:**
  BANCS clocking scheme. 

## Utility Functions

### inline bool [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::is_linear(const [scheme](#_CPPv4N7fiction7layouts8clocking6schemeE) &scm) noexcept

Checks whether a given clocking scheme is registered as a cycle-free one. These currently are

* COLUMNAR
* ROW
* 2DDWAVE
* 2DDWAVEHEX

* **Parameters:**
  **scm** – Clocking scheme to check. 
* **Returns:**
  `true` iff `scm` is listed as one of the linear clocking schemes. 

### inline std::optional<[scheme](#_CPPv4N7fiction7layouts8clocking6schemeE)> [fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::get_scheme(const std::string_view scheme_name, const std::optional<[arrangement](hexagonal_layout.html.md#_CPPv4N7fiction7layouts11arrangementE)> hex = std::nullopt)

Returns a catalog clocking scheme by name. The lookup ignores case and accepts a trailing `3` or `4` that selects the phase count of a scheme that supports it. Without a suffix, a scheme has its default phase count: 3 for BANCS and 4 for all others. `2DDWAVEHEX` requires a hexagonal arrangement and falls back to `2DDWAVE` without one.

* **Parameters:**
  * **scheme_name** – Name of the desired clocking scheme. 
  * **hex** – Arrangement of the hexagonal layout the scheme is for, or `std::nullopt` for a non-hexagonal layout. 
* **Returns:**
  Clocking scheme that matches `scheme_name`, or `std::nullopt` if no clocking scheme by that name exists or the scheme does not support the requested phase count. 

## Scheme Names

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::OPEN_NAME = "OPEN"

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::COLUMNAR_NAME = "COLUMNAR"

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::ROW_NAME = "ROW"

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::TWODDWAVE_NAME = "2DDWAVE"

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::TWODDWAVE_HEX_NAME = "2DDWAVEHEX"

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::USE_NAME = "USE"

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::RES_NAME = "RES"

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::ESR_NAME = "ESR"

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::CFE_NAME = "CFE"

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::RIPPLE_NAME = "RIPPLE"

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::SRS_NAME = "SRS"

### constexpr const char \*[fiction](traits.html.md#_CPPv47fiction)::layouts::clocking::BANCS_NAME = "BANCS"
