Skip to content

Commit

Permalink
✨ Added support for optional input parameter points in flood fill (#518)
Browse files Browse the repository at this point in the history
* ✨ adding additional input for parameter points and add operational_to_total_ratio.

* 🎨 change illustration of positively charged SiDB.

* 📝 Update pyfiction docstrings

Signed-off-by: GitHub Actions <[email protected]>

* 📝 add docu.

* 🎨 update experiments after change.

* 🎨 Incorporated pre-commit fixes

* 🎨 clang-tidy fixes.

* 🎨 small fix.

* 🎨 small fix.

* 🎨 Incorporated pre-commit fixes

* 🎨 small fix.

* 🎨 small fix.

* 📝 Update pyfiction docstrings

Signed-off-by: GitHub Actions <[email protected]>

* 🎨 use circles for positive sidbs.

* ✨ new function to compute operational domain ratio.

* 🎨 restructuring

* 🎨 Incorporated pre-commit fixes

* 📝 Update pyfiction docstrings

Signed-off-by: GitHub Actions <[email protected]>

* 🎨 small fix.

* 🎨 Incorporated pre-commit fixes

* 🎨 small fix.

* 🎨 Incorporated pre-commit fixes

* 📝 Update pyfiction docstrings

Signed-off-by: GitHub Actions <[email protected]>

* 🎨 small fix.

* 🎨 small fix.

* 🎨 Incorporated pre-commit fixes

* 🎨 small fix.

* 🐛 fix python unittest.

* 📝 Update pyfiction docstrings

Signed-off-by: GitHub Actions <[email protected]>

* 🎨 delete redundant header.

* 📝 small bug fix.

* 🎨 implement Marcel's comments.

* 🎨 Incorporated pre-commit fixes

* 📝 Update pyfiction docstrings

Signed-off-by: GitHub Actions <[email protected]>

* 🎨 small fix.

* 🎨 Incorporated pre-commit fixes

* 🎨 small fix.

* 🎨 small fix.

* 🎨 update test-tag

* 📝 small fix.

---------

Signed-off-by: GitHub Actions <[email protected]>
Co-authored-by: GitHub Actions <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 20, 2024
1 parent a2971b4 commit 18bafd2
Show file tree
Hide file tree
Showing 19 changed files with 690 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Created by Jan Drewniok on 13.09.24.
//

#ifndef PYFICTION_COMPUTE_OPERATIONAL_RATIO_HPP
#define PYFICTION_COMPUTE_OPERATIONAL_RATIO_HPP

#include "pyfiction/documentation.hpp"
#include "pyfiction/types.hpp"

#include <fiction/algorithms/simulation/sidb/compute_operational_ratio.hpp>

#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace pyfiction
{

namespace detail
{

template <typename Lyt>
void compute_operational_ratio(pybind11::module& m)
{
namespace py = pybind11;
using namespace pybind11::literals;

m.def("compute_operational_ratio", &fiction::compute_operational_ratio<Lyt, py_tt>, "lyt"_a, "spec"_a, "pp"_a,
"params"_a = fiction::operational_domain_params{}, DOC(fiction_compute_operational_ratio));
}

} // namespace detail

inline void compute_operational_ratio(pybind11::module& m)
{
namespace py = pybind11;
using namespace pybind11::literals;

py::class_<fiction::compute_operational_ratio_params>(m, "compute_operational_ratio_params",
DOC(fiction_compute_operational_ratio_params))
.def(py::init<>())
.def_readwrite("op_domain_params", &fiction::compute_operational_ratio_params::op_domain_params,
DOC(fiction_compute_operational_ratio_params_op_domain_params));

// NOTE be careful with the order of the following calls! Python will resolve the first matching overload!

detail::compute_operational_ratio<py_sidb_100_lattice>(m);
detail::compute_operational_ratio<py_sidb_111_lattice>(m);
}

} // namespace pyfiction

#endif // PYFICTION_COMPUTE_OPERATIONAL_RATIO_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ inline void operational_domain(pybind11::module& m)
.def_readonly("num_non_operational_parameter_combinations",
&fiction::operational_domain_stats::num_non_operational_parameter_combinations,
DOC(fiction_operational_domain_stats_num_non_operational_parameter_combinations))
.def_readonly("num_total_parameter_points", &fiction::operational_domain_stats::num_total_parameter_points,
DOC(fiction_operational_domain_stats_num_total_parameter_points))

;

Expand Down
51 changes: 51 additions & 0 deletions bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2515,6 +2515,50 @@ Parameter ``n``:
Returns:
Columnar clocking scheme.)doc";

static const char *__doc_fiction_compute_operational_ratio =
R"doc(Calculates the ratio of operational parameter points surrounding a
specified parameter point to the total number of parameter points in
the given parameter space. This function is useful for assessing how
robust a gate design is to variations in its parameters.

A ratio close to 1 indicates that the gate is robust, meaning it
functions correctly across a broad range of parameter values. A ratio
close to 0 indicates that the gate is highly sensitive to parameter
variations and may fail to operate correctly.

Template parameter ``Lyt``:
SiDB cell-level layout type.

Template parameter ``TT``:
Truth table type.

Parameter ``lyt``:
The SiDB layout for which to compute the ratio of operational
parameter points surrounding a specified parameter point to the
total number of parameter points.

Parameter ``spec``:
The expected Boolean function of the layout, provided as a multi-
output truth table.

Parameter ``params``:
Parameters.

Parameter ``pp``:
The specific parameter point around which the operational ratio is
computed.

Returns:
The ratio of operational parameter points to the total number of
parameter points in the parameter space.)doc";

static const char *__doc_fiction_compute_operational_ratio_params =
R"doc(Parameters for computing the ratio of operational parameter points
around a specified parameter point to the total number of parameter
points in the given parameter space.)doc";

static const char *__doc_fiction_compute_operational_ratio_params_op_domain_params = R"doc(Parameters for the operational domain computation.)doc";

static const char *__doc_fiction_convert_array =
R"doc(Converts an array of size `N` and type `T` to an array of size `N` and
type `ElementType` by applying `static_cast` at compile time.
Expand Down Expand Up @@ -6638,6 +6682,11 @@ one pixel wide border around the domain.
Parameter ``samples``:
Maximum number of random samples to be taken before flood fill.

Parameter ``given_parameter_point``:
Optional parameter point in the parameter space. If it lies within
the operational region, it is used as a starting point for flood
fill.

Returns:
The (partial) operational domain of the layout.)doc";

Expand Down Expand Up @@ -13810,6 +13859,8 @@ static const char *__doc_fiction_operational_domain_stats_num_operational_parame

static const char *__doc_fiction_operational_domain_stats_num_simulator_invocations = R"doc(Number of simulator invocations.)doc";

static const char *__doc_fiction_operational_domain_stats_num_total_parameter_points = R"doc(Total number of parameter points in the parameter space.)doc";

static const char *__doc_fiction_operational_domain_value_range =
R"doc(A range of values for a dimension sweep. The range is defined by a
minimum value, a maximum value and a step size.)doc";
Expand Down
2 changes: 2 additions & 0 deletions bindings/pyfiction/pyfiction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "pyfiction/algorithms/simulation/logic_simulation.hpp"
#include "pyfiction/algorithms/simulation/sidb/calculate_energy_and_state_type.hpp"
#include "pyfiction/algorithms/simulation/sidb/can_positive_charges_occur.hpp"
#include "pyfiction/algorithms/simulation/sidb/compute_operational_ratio.hpp"
#include "pyfiction/algorithms/simulation/sidb/critical_temperature.hpp"
#include "pyfiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp"
#include "pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp"
Expand Down Expand Up @@ -149,6 +150,7 @@ PYBIND11_MODULE(pyfiction, m)
pyfiction::check_simulation_results_for_equivalence(m);
pyfiction::determine_physically_valid_parameters(m);
pyfiction::determine_displacement_robustness_domain(m);
pyfiction::compute_operational_ratio(m);
/**
* Algorithms: Iterators
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import unittest

from mnt.pyfiction import *

dir_path = os.path.dirname(os.path.realpath(__file__))

class TestComputeOperationalRatioAtPoint(unittest.TestCase):
def test_and_gate_100_lattice(self):
lyt = read_sqd_layout_100(dir_path + "/../../../resources/21_hex_inputsdbp_and_v19.sqd")

params = operational_domain_params()
params.sim_engine = sidb_simulation_engine.QUICKEXACT
params.simulation_parameters.base = 2

params.sweep_dimensions = [operational_domain_value_range(sweep_parameter.EPSILON_R, 5.00, 6.00, 0.1),
operational_domain_value_range(sweep_parameter.LAMBDA_TF, 5.00, 6.00, 0.1)]

ratio_params = compute_operational_ratio_params()
ratio_params.op_domain_params = params

self.assertEqual(ratio_params.op_domain_params.simulation_parameters.base, 2)

operational_domain_ratio = compute_operational_ratio(lyt, [create_and_tt()], parameter_point([5.6, 5.0]), ratio_params)

self.assertAlmostEqual(operational_domain_ratio, 23/121, delta=10E-6)

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_is_operational(self):
self.assertEqual(op_status, operational_status.NON_OPERATIONAL)

def test_and_gate_111_lattice_11_input_pattern(self):
lyt = read_sqd_layout_111(dir_path + "/../../../resources/AND_mu_032_0.sqd")
lyt = read_sqd_layout_111(dir_path + "/../../../resources/AND_mu_032_111_surface.sqd")

params = is_operational_params()
params.simulation_parameters = sidb_simulation_parameters(2, -0.32)
Expand All @@ -58,7 +58,7 @@ def test_and_gate_111_lattice_11_input_pattern(self):
self.assertEqual(op_status, operational_status.NON_OPERATIONAL)

def test_and_gate_111_lattice_operational_input_pattern(self):
lyt = read_sqd_layout_111(dir_path + "/../../../resources/AND_mu_032_0.sqd")
lyt = read_sqd_layout_111(dir_path + "/../../../resources/AND_mu_032_111_surface.sqd")

params = is_operational_params()
params.simulation_parameters = sidb_simulation_parameters(2, -0.30)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from mnt.pyfiction import *
import unittest
import os
import unittest

from mnt.pyfiction import *

dir_path = os.path.dirname(os.path.realpath(__file__))

Expand All @@ -18,46 +19,46 @@ def test_xor_gate_100_lattice(self):
operational_domain_value_range(sweep_parameter.LAMBDA_TF, 4.95, 5.05, 0.01)]

stats_grid = operational_domain_stats()
opdomain = operational_domain_grid_search(lyt, [create_xor_tt()], params, stats_grid)
operational_domain_grid_search(lyt, [create_xor_tt()], params, stats_grid)
self.assertGreater(stats_grid.num_operational_parameter_combinations, 0)

stats_flood_fill = operational_domain_stats()
opdomain = operational_domain_flood_fill(lyt, [create_xor_tt()], 100, params, stats_flood_fill)
operational_domain_flood_fill(lyt, [create_xor_tt()], 100, params, stats_flood_fill)
self.assertGreater(stats_flood_fill.num_operational_parameter_combinations, 0)

stats_random_sampling = operational_domain_stats()
opdomain = operational_domain_random_sampling(lyt, [create_xor_tt()], 100, params, stats_random_sampling)
operational_domain_random_sampling(lyt, [create_xor_tt()], 100, params, stats_random_sampling)
self.assertGreater(stats_random_sampling.num_operational_parameter_combinations, 0)

stats_contour_tracing = operational_domain_stats()
opdomain = operational_domain_contour_tracing(lyt, [create_xor_tt()], 100, params, stats_contour_tracing)
operational_domain_contour_tracing(lyt, [create_xor_tt()], 100, params, stats_contour_tracing)
self.assertGreater(stats_contour_tracing.num_operational_parameter_combinations, 0)

def test_and_gate_111_lattice(self):
lyt = read_sqd_layout_111(dir_path + "/../../../resources/AND_mu_032_0.sqd")
lyt = read_sqd_layout_111(dir_path + "/../../../resources/AND_mu_032_111_surface.sqd")

params = operational_domain_params()

params.sim_engine = sidb_simulation_engine.QUICKEXACT
params.simulation_parameters.base = 2

params.sweep_dimensions = [operational_domain_value_range(sweep_parameter.EPSILON_R, 5.60, 5.64, 0.01),
operational_domain_value_range(sweep_parameter.LAMBDA_TF, 5.00, 5.01, 0.01)];
operational_domain_value_range(sweep_parameter.LAMBDA_TF, 5.00, 5.01, 0.01)]

stats_grid = operational_domain_stats()
opdomain = operational_domain_grid_search(lyt, [create_and_tt()], params, stats_grid)
operational_domain_grid_search(lyt, [create_and_tt()], params, stats_grid)
self.assertGreater(stats_grid.num_operational_parameter_combinations, 0)

stats_flood_fill = operational_domain_stats()
opdomain = operational_domain_flood_fill(lyt, [create_and_tt()], 100, params, stats_flood_fill)
operational_domain_flood_fill(lyt, [create_and_tt()], 100, params, stats_flood_fill)
self.assertGreater(stats_flood_fill.num_operational_parameter_combinations, 0)

stats_random_sampling = operational_domain_stats()
opdomain = operational_domain_random_sampling(lyt, [create_and_tt()], 100, params, stats_random_sampling)
operational_domain_random_sampling(lyt, [create_and_tt()], 100, params, stats_random_sampling)
self.assertGreater(stats_random_sampling.num_operational_parameter_combinations, 0)

stats_contour_tracing = operational_domain_stats()
opdomain = operational_domain_contour_tracing(lyt, [create_and_tt()], 100, params, stats_contour_tracing)
operational_domain_contour_tracing(lyt, [create_and_tt()], 100, params, stats_contour_tracing)
self.assertGreater(stats_contour_tracing.num_operational_parameter_combinations, 0)


Expand Down
Loading

0 comments on commit 18bafd2

Please sign in to comment.