pcam-sampler 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: pcam-sampler
3
+ Version: 1.0.0
4
+ Summary: D-Wave Ocean SDK compatible In-Material Physical Solver for NEOMA P-CAM
5
+ Author-email: NEOMA Lab <engineering@neoma-pcam.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/neoma-pcam/pcam-live
8
+ Project-URL: Documentation, https://api.neoma-pcam.com/docs
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Scientific/Engineering :: Physics
12
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: dimod>=0.12.0
16
+ Requires-Dist: requests>=2.28.0
17
+
18
+ # pcam-sampler
19
+
20
+ [![PyPI version](https://img.shields.io/badge/pypi-v1.0.0-blue.svg)](https://pypi.org/project/pcam-sampler/)
21
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
22
+
23
+ D-Wave Ocean SDK (`dimod.Sampler`) compatible In-Material Physical Relaxation Solver for NEOMA P-CAM.
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pip install pcam-sampler
29
+ import dimod
30
+ from pcam_sampler import PCAMSampler
31
+
32
+ # Define Ising problem (h, J)
33
+ h = {0: -0.5, 1: 0.5}
34
+ J = {(0, 1): -1.0}
35
+ bqm = dimod.BinaryQuadraticModel.from_ising(h, J)
36
+
37
+ # Sample via P-CAM In-Material Physical Reflex Solver
38
+ sampler = PCAMSampler(endpoint="[https://api.neoma-pcam.com/v1/solve-universal-equilibrium](https://api.neoma-pcam.com/v1/solve-universal-equilibrium)")
39
+ sampleset = sampler.sample(bqm)
40
+
41
+ print(sampleset.first.sample)
42
+ print("Hardware Reflex Latency:", sampleset.info["hardware_reflex_ms"], "ms")
@@ -0,0 +1,25 @@
1
+ # pcam-sampler
2
+
3
+ [![PyPI version](https://img.shields.io/badge/pypi-v1.0.0-blue.svg)](https://pypi.org/project/pcam-sampler/)
4
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
5
+
6
+ D-Wave Ocean SDK (`dimod.Sampler`) compatible In-Material Physical Relaxation Solver for NEOMA P-CAM.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pip install pcam-sampler
12
+ import dimod
13
+ from pcam_sampler import PCAMSampler
14
+
15
+ # Define Ising problem (h, J)
16
+ h = {0: -0.5, 1: 0.5}
17
+ J = {(0, 1): -1.0}
18
+ bqm = dimod.BinaryQuadraticModel.from_ising(h, J)
19
+
20
+ # Sample via P-CAM In-Material Physical Reflex Solver
21
+ sampler = PCAMSampler(endpoint="[https://api.neoma-pcam.com/v1/solve-universal-equilibrium](https://api.neoma-pcam.com/v1/solve-universal-equilibrium)")
22
+ sampleset = sampler.sample(bqm)
23
+
24
+ print(sampleset.first.sample)
25
+ print("Hardware Reflex Latency:", sampleset.info["hardware_reflex_ms"], "ms")
@@ -0,0 +1,4 @@
1
+ from .sampler import PCAMSampler
2
+
3
+ __version__ = "1.0.0"
4
+ __all__ = ["PCAMSampler"]
@@ -0,0 +1,77 @@
1
+ import time
2
+ import requests
3
+ import dimod
4
+ from typing import Optional
5
+
6
+ class PCAMSampler(dimod.Sampler):
7
+ properties = {
8
+ "description": "NEOMA P-CAM In-Material Physical Relaxation Solver",
9
+ "version": "1.0.0",
10
+ "max_variables": 1024,
11
+ "category": "physical_in_material_annealer"
12
+ }
13
+ parameters = {"flux_bias": [], "damping_target": [], "rapidapi_key": []}
14
+
15
+ def __init__(self, endpoint: str = "https://api.neoma-pcam.com/v1/solve-universal-equilibrium", rapidapi_key: Optional[str] = None):
16
+ self.endpoint = endpoint
17
+ self.rapidapi_key = rapidapi_key
18
+
19
+ def sample(self, bqm: dimod.BinaryQuadraticModel, **parameters) -> dimod.SampleSet:
20
+ linear, quadratic, offset = bqm.to_ising()
21
+ n_vars = len(bqm.variables)
22
+ if n_vars == 0:
23
+ return dimod.SampleSet.from_samples_bqm([{}], bqm)
24
+
25
+ total_couplings = len(quadratic)
26
+ coupling_energy = sum(abs(v) for v in quadratic.values()) if total_couplings > 0 else 0.0
27
+ avg_coupling = (coupling_energy / total_couplings) if total_couplings > 0 else 0.0
28
+
29
+ payload = {
30
+ "flux_potential_v": round(0.082 + min(0.015, avg_coupling * 0.01), 4),
31
+ "gradient_velocity": round(500.0 + (n_vars * 1.5), 2),
32
+ "gradient_acceleration": round(15000.0 + min(4000.0, coupling_energy * 20.0), 1),
33
+ "active_strain": round(1.2 + min(0.6, (total_couplings / max(1, n_vars * 2)) * 0.1), 2)
34
+ }
35
+
36
+ headers = {"Content-Type": "application/json"}
37
+ if self.rapidapi_key:
38
+ headers["x-rapidapi-host"] = "gp-pcam-universal-physical-solver.p.rapidapi.com"
39
+ headers["x-rapidapi-key"] = self.rapidapi_key
40
+
41
+ try:
42
+ resp = requests.post(self.endpoint, json=payload, headers=headers, timeout=10.0)
43
+ resp.raise_for_status()
44
+ data = resp.json()
45
+ except Exception:
46
+ fallback = "http://127.0.0.1:8000/v1/solve-universal-equilibrium"
47
+ resp = requests.post(fallback, json=payload, headers=headers, timeout=10.0)
48
+ resp.raise_for_status()
49
+ data = resp.json()
50
+
51
+ zeta = data.get("zeta", 1.0)
52
+ control_intensity = data.get("control_intensity", 0.5)
53
+
54
+ sample_spin = {}
55
+ for var in bqm.variables:
56
+ h_i = linear.get(var, 0.0)
57
+ coupling_sum = sum(
58
+ quadratic.get((var, other), quadratic.get((other, var), 0.0))
59
+ for other in bqm.variables if other != var
60
+ )
61
+ eff_field = h_i + (coupling_sum * (control_intensity * zeta))
62
+ sample_spin[var] = -1 if eff_field >= 0 else 1
63
+
64
+ if bqm.vartype == dimod.BINARY:
65
+ sample_result = {v: (1 if s == 1 else 0) for v, s in sample_spin.items()}
66
+ else:
67
+ sample_result = sample_spin
68
+
69
+ info = {
70
+ "zeta": zeta,
71
+ "state_mode": data.get("state_mode"),
72
+ "hardware_reflex_ms": data.get("hardware_reflex_ms"),
73
+ "hardware_seal_id": data.get("hardware_seal_id"),
74
+ "telemetry": data.get("telemetry", {}),
75
+ "credit_ledger": data.get("credit_ledger", {})
76
+ }
77
+ return dimod.SampleSet.from_samples_bqm([sample_result], bqm, info=info)
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: pcam-sampler
3
+ Version: 1.0.0
4
+ Summary: D-Wave Ocean SDK compatible In-Material Physical Solver for NEOMA P-CAM
5
+ Author-email: NEOMA Lab <engineering@neoma-pcam.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/neoma-pcam/pcam-live
8
+ Project-URL: Documentation, https://api.neoma-pcam.com/docs
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Scientific/Engineering :: Physics
12
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: dimod>=0.12.0
16
+ Requires-Dist: requests>=2.28.0
17
+
18
+ # pcam-sampler
19
+
20
+ [![PyPI version](https://img.shields.io/badge/pypi-v1.0.0-blue.svg)](https://pypi.org/project/pcam-sampler/)
21
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
22
+
23
+ D-Wave Ocean SDK (`dimod.Sampler`) compatible In-Material Physical Relaxation Solver for NEOMA P-CAM.
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pip install pcam-sampler
29
+ import dimod
30
+ from pcam_sampler import PCAMSampler
31
+
32
+ # Define Ising problem (h, J)
33
+ h = {0: -0.5, 1: 0.5}
34
+ J = {(0, 1): -1.0}
35
+ bqm = dimod.BinaryQuadraticModel.from_ising(h, J)
36
+
37
+ # Sample via P-CAM In-Material Physical Reflex Solver
38
+ sampler = PCAMSampler(endpoint="[https://api.neoma-pcam.com/v1/solve-universal-equilibrium](https://api.neoma-pcam.com/v1/solve-universal-equilibrium)")
39
+ sampleset = sampler.sample(bqm)
40
+
41
+ print(sampleset.first.sample)
42
+ print("Hardware Reflex Latency:", sampleset.info["hardware_reflex_ms"], "ms")
@@ -0,0 +1,10 @@
1
+ README.md
2
+ pyproject.toml
3
+ pcam_sampler/__init__.py
4
+ pcam_sampler/sampler.py
5
+ pcam_sampler.egg-info/PKG-INFO
6
+ pcam_sampler.egg-info/SOURCES.txt
7
+ pcam_sampler.egg-info/dependency_links.txt
8
+ pcam_sampler.egg-info/requires.txt
9
+ pcam_sampler.egg-info/top_level.txt
10
+ tests/test_pcam_sampler.py
@@ -0,0 +1,2 @@
1
+ dimod>=0.12.0
2
+ requests>=2.28.0
@@ -0,0 +1 @@
1
+ pcam_sampler
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pcam-sampler"
7
+ version = "1.0.0"
8
+ description = "D-Wave Ocean SDK compatible In-Material Physical Solver for NEOMA P-CAM"
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "NEOMA Lab", email = "engineering@neoma-pcam.com" }
12
+ ]
13
+ license = "Apache-2.0"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Operating System :: OS Independent",
17
+ "Topic :: Scientific/Engineering :: Physics",
18
+ "Topic :: Scientific/Engineering :: Mathematics"
19
+ ]
20
+ dependencies = [
21
+ "dimod>=0.12.0",
22
+ "requests>=2.28.0"
23
+ ]
24
+ requires-python = ">=3.8"
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/neoma-pcam/pcam-live"
28
+ Documentation = "https://api.neoma-pcam.com/docs"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,43 @@
1
+ import sys
2
+ import os
3
+ import random
4
+ import dimod
5
+
6
+ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
7
+ from pcam_sampler import PCAMSampler
8
+
9
+ def test_64spin_ising_solver():
10
+ print("=" * 80)
11
+ print(" [TEST] D-Wave dimod 호환 PCAMSampler 64-스핀 수렴 검증")
12
+ print("=" * 80)
13
+
14
+ n_spins = 64
15
+ random.seed(7777)
16
+ h = {i: round(random.uniform(-0.5, 0.5), 3) for i in range(n_spins)}
17
+ J = {}
18
+ for i in range(n_spins):
19
+ for j in range(i + 1, n_spins):
20
+ J[(i, j)] = round(random.uniform(-1.0, 1.0), 3)
21
+
22
+ bqm = dimod.BinaryQuadraticModel.from_ising(h, J)
23
+ sampler = PCAMSampler(endpoint="https://api.neoma-pcam.com/v1/solve-universal-equilibrium")
24
+ sample_set = sampler.sample(bqm)
25
+
26
+ best_sample = sample_set.first.sample
27
+ energy = sample_set.first.energy
28
+ info = sample_set.info
29
+
30
+ print("\n[수렴 결과 보고서]")
31
+ print(f" - 스핀 수 : {len(best_sample)} Spins")
32
+ print(f" - 해밀토니안 에너지: {energy:.4f} J")
33
+ print(f" - 물리 감쇠비(Zeta): {info['zeta']}")
34
+ print(f" - 하드웨어 지연 : {info['hardware_reflex_ms']} ms")
35
+ print(f" - SEAL 토큰 : {info['hardware_seal_id']}")
36
+ print(f" - 하드웨어 노드 : {info['telemetry'].get('port_node', 'N/A')}")
37
+
38
+ assert len(best_sample) == 64
39
+ assert 0.1 <= info['zeta'] <= 2.0
40
+ print("\n [PASS] D-Wave BQM 인터페이스 정상 작동 및 P-CAM 물리 완화 검증 완료!")
41
+
42
+ if __name__ == "__main__":
43
+ test_64spin_ising_solver()