isthmus 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.
- isthmus-1.0.0/LICENSE +202 -0
- isthmus-1.0.0/PKG-INFO +127 -0
- isthmus-1.0.0/README.md +103 -0
- isthmus-1.0.0/isthmus/__init__.py +29 -0
- isthmus-1.0.0/isthmus/__main__.py +3 -0
- isthmus-1.0.0/isthmus/adaptadores.py +157 -0
- isthmus-1.0.0/isthmus/alignment.py +69 -0
- isthmus-1.0.0/isthmus/budget.py +24 -0
- isthmus-1.0.0/isthmus/canon.py +30 -0
- isthmus-1.0.0/isthmus/characterize.py +19 -0
- isthmus-1.0.0/isthmus/cli.py +44 -0
- isthmus-1.0.0/isthmus/cudaq_alvo.py +117 -0
- isthmus-1.0.0/isthmus/errors.py +34 -0
- isthmus-1.0.0/isthmus/estimator.py +12 -0
- isthmus-1.0.0/isthmus/fringe.py +27 -0
- isthmus-1.0.0/isthmus/mitigation.py +15 -0
- isthmus-1.0.0/isthmus/quantum.py +25 -0
- isthmus-1.0.0/isthmus/ramp.py +179 -0
- isthmus-1.0.0/isthmus/receipt.py +53 -0
- isthmus-1.0.0/isthmus/refase.py +17 -0
- isthmus-1.0.0/isthmus/sampler.py +14 -0
- isthmus-1.0.0/isthmus/shutter.py +20 -0
- isthmus-1.0.0/isthmus/sth.py +33 -0
- isthmus-1.0.0/isthmus/sth_cli.py +32 -0
- isthmus-1.0.0/isthmus/transpile.py +11 -0
- isthmus-1.0.0/isthmus.egg-info/PKG-INFO +127 -0
- isthmus-1.0.0/isthmus.egg-info/SOURCES.txt +36 -0
- isthmus-1.0.0/isthmus.egg-info/dependency_links.txt +1 -0
- isthmus-1.0.0/isthmus.egg-info/entry_points.txt +5 -0
- isthmus-1.0.0/isthmus.egg-info/top_level.txt +1 -0
- isthmus-1.0.0/pyproject.toml +39 -0
- isthmus-1.0.0/setup.cfg +4 -0
- isthmus-1.0.0/tests/test_aceite.py +242 -0
- isthmus-1.0.0/tests/test_adaptadores.py +51 -0
- isthmus-1.0.0/tests/test_alignment.py +70 -0
- isthmus-1.0.0/tests/test_cudaq_alvo.py +54 -0
- isthmus-1.0.0/tests/test_ramp_sequencial.py +101 -0
- isthmus-1.0.0/tests/test_sth.py +65 -0
isthmus-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
isthmus-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: isthmus
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Sub-linguagem híbrida de interoperabilidade, controle e verificação do ecossistema ZEPHIRUM
|
|
5
|
+
Author: Serena Solutions
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/SerenaSolutions/isthmus
|
|
8
|
+
Project-URL: Repository, https://github.com/SerenaSolutions/isthmus
|
|
9
|
+
Project-URL: Issues, https://github.com/SerenaSolutions/isthmus/issues
|
|
10
|
+
Keywords: quantum,verification,receipts,trivalent,isthmus,ist,sth
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# ISTHMUS
|
|
26
|
+
|
|
27
|
+
Sub-linguagem híbrida de interoperabilidade, controle e verificação do ecossistema
|
|
28
|
+
ZEPHIRUM/ZYQL. Abreviações: **ISTH** e **STH**.
|
|
29
|
+
|
|
30
|
+
Quatorze algoritmos em três camadas, recibo com duas etapas de verificação, zero
|
|
31
|
+
dependência externa.
|
|
32
|
+
|
|
33
|
+
Versão 0.1.1 · 42 testes · Apache-2.0
|
|
34
|
+
|
|
35
|
+
## Instalar
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install -e .
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Rodar em trinta segundos
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
python3 -m unittest discover -s tests -v # 42 testes, todos passando
|
|
45
|
+
isth decide --p0 0.9 --shots 512 > r.json
|
|
46
|
+
sth verify r.json # {"state":"ok","stage":"fine"}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Os três comandos `isthmus`, `isth` e `ist` são equivalentes e decidem.
|
|
50
|
+
`sth` é a derivada: sela, verifica e encadeia, e **não decide**.
|
|
51
|
+
|
|
52
|
+
Alterar `verdict` no `r.json` e repetir a verificação devolve
|
|
53
|
+
`{"state":"refused","code":"ISTH-FINE-SEAL"}` com saída de código 1.
|
|
54
|
+
|
|
55
|
+
## ISTH e STH
|
|
56
|
+
|
|
57
|
+
| | ISTH | STH |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| decide | sim | **não** |
|
|
60
|
+
| sela payload já decidido | sim | sim |
|
|
61
|
+
| verifica recibo e cadeia | sim | sim |
|
|
62
|
+
| tem Ramp, Shutter, banda, oráculo | sim | não |
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
isth decide --p0 0.9 --shots 512 > r.json # decide e sela
|
|
66
|
+
sth seal payload.json # sela payload cru, exige campo verdict
|
|
67
|
+
sth verify r.json # confere
|
|
68
|
+
sth chain r1.json r2.json r3.json # confere a cadeia
|
|
69
|
+
sth decide # recusa: ISTH-STH-NOT-ALLOWED
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`sth seal` recebe um payload cru, não um recibo. O mínimo é:
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{"p0": 0.9, "n": 4, "shots": 512, "seed": 1, "mode": "sim", "error_bound": 0.05, "verdict": 1}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Recibo emitido sob ISTH verifica sob STH. É o sentido da derivação: quem só
|
|
79
|
+
confere não precisa da camada que decide.
|
|
80
|
+
|
|
81
|
+
## O que existe
|
|
82
|
+
|
|
83
|
+
| Camada | Algoritmos | Estado |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| Clássico puro | Ramp, Shutter, Canonize, Fringe, Refase | implementado e testado |
|
|
86
|
+
| Híbrido | Sampler, Estimator com Alignment Two, Mitigation audit, Budget, Transpile audit | implementado como contrato |
|
|
87
|
+
| Ponta quântica | Prepare, Evolve, Measure, Reset, Flow, Characterize | implementado como fluxo local |
|
|
88
|
+
| Ponte com backend real | as cinco responsabilidades híbridas | **planejado** |
|
|
89
|
+
|
|
90
|
+
A ponte com QPU e simulador externo não está implementada. Nenhum adaptador foi
|
|
91
|
+
conectado, e este README não afirma o contrário.
|
|
92
|
+
|
|
93
|
+
## As duas etapas do verificador
|
|
94
|
+
|
|
95
|
+
1. **Grossa**: esquema, versão de gramática e campos obrigatórios. Barata, falha cedo.
|
|
96
|
+
2. **Fina**: selo SHA3-256 sobre os bytes canônicos. Cara, falha tarde.
|
|
97
|
+
|
|
98
|
+
A cadeia tem verificação própria: um elo re-selado passa sozinho e só
|
|
99
|
+
`verify_chain` o denuncia, que é a diferença entre dano contíguo (*snowball*) e
|
|
100
|
+
dano distribuído (*shower*).
|
|
101
|
+
|
|
102
|
+
## Testado com simulador, não com hardware
|
|
103
|
+
|
|
104
|
+
A integração já rodada usa Qiskit Aer, simulador local: circuito de Bell, duas
|
|
105
|
+
rodadas de 1.024 tiros, p0 de 0,4951 e 0,5020, recibo e cadeia verificando,
|
|
106
|
+
adulteração recusada com `ISTH-FINE-SEAL`. Nenhum hardware foi usado.
|
|
107
|
+
|
|
108
|
+
## Contradição aberta
|
|
109
|
+
|
|
110
|
+
Alignment Two exige duas rodadas; a regra do projeto diz uma chamada de oráculo por
|
|
111
|
+
decisão. `Budget` recebe `oracle_calls` declarado em vez de fingir que é sempre um.
|
|
112
|
+
As três saídas possíveis estão em `docs/ISTHMUS_1.4_implementacao_2026-11-17.md`.
|
|
113
|
+
|
|
114
|
+
## Documentação
|
|
115
|
+
|
|
116
|
+
- `docs/ISTHMUS_prompt_mestre_2026-11-17.md`: especificação e prompt mestre
|
|
117
|
+
- `docs/ISTHMUS_v1.1_ponte_hibrida_2026-11-17.md`: ponte híbrida e maturidade
|
|
118
|
+
- `docs/ISTHMUS_1.2_vocabulario_verificacao_2026-11-17.md`: vocabulário e testes de aceite
|
|
119
|
+
- `docs/ISTHMUS_1.3_inventario_algoritmos_2026-11-17.md`: inventário e ordem de construção
|
|
120
|
+
- `docs/ISTHMUS_1.4_implementacao_2026-11-17.md`: primeira implementação, com medições
|
|
121
|
+
- `NAMING.md`: nome canônico, abreviação ISTH e a derivada STH
|
|
122
|
+
- `docs/ERRATA.md`: correções de nomenclatura, inclusive as que já foram para o histórico
|
|
123
|
+
- `CHANGELOG.md`: versões, mudanças e quebras
|
|
124
|
+
|
|
125
|
+
## Licença
|
|
126
|
+
|
|
127
|
+
Apache-2.0.
|
isthmus-1.0.0/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# ISTHMUS
|
|
2
|
+
|
|
3
|
+
Sub-linguagem híbrida de interoperabilidade, controle e verificação do ecossistema
|
|
4
|
+
ZEPHIRUM/ZYQL. Abreviações: **ISTH** e **STH**.
|
|
5
|
+
|
|
6
|
+
Quatorze algoritmos em três camadas, recibo com duas etapas de verificação, zero
|
|
7
|
+
dependência externa.
|
|
8
|
+
|
|
9
|
+
Versão 0.1.1 · 42 testes · Apache-2.0
|
|
10
|
+
|
|
11
|
+
## Instalar
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install -e .
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Rodar em trinta segundos
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
python3 -m unittest discover -s tests -v # 42 testes, todos passando
|
|
21
|
+
isth decide --p0 0.9 --shots 512 > r.json
|
|
22
|
+
sth verify r.json # {"state":"ok","stage":"fine"}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Os três comandos `isthmus`, `isth` e `ist` são equivalentes e decidem.
|
|
26
|
+
`sth` é a derivada: sela, verifica e encadeia, e **não decide**.
|
|
27
|
+
|
|
28
|
+
Alterar `verdict` no `r.json` e repetir a verificação devolve
|
|
29
|
+
`{"state":"refused","code":"ISTH-FINE-SEAL"}` com saída de código 1.
|
|
30
|
+
|
|
31
|
+
## ISTH e STH
|
|
32
|
+
|
|
33
|
+
| | ISTH | STH |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| decide | sim | **não** |
|
|
36
|
+
| sela payload já decidido | sim | sim |
|
|
37
|
+
| verifica recibo e cadeia | sim | sim |
|
|
38
|
+
| tem Ramp, Shutter, banda, oráculo | sim | não |
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
isth decide --p0 0.9 --shots 512 > r.json # decide e sela
|
|
42
|
+
sth seal payload.json # sela payload cru, exige campo verdict
|
|
43
|
+
sth verify r.json # confere
|
|
44
|
+
sth chain r1.json r2.json r3.json # confere a cadeia
|
|
45
|
+
sth decide # recusa: ISTH-STH-NOT-ALLOWED
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`sth seal` recebe um payload cru, não um recibo. O mínimo é:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{"p0": 0.9, "n": 4, "shots": 512, "seed": 1, "mode": "sim", "error_bound": 0.05, "verdict": 1}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Recibo emitido sob ISTH verifica sob STH. É o sentido da derivação: quem só
|
|
55
|
+
confere não precisa da camada que decide.
|
|
56
|
+
|
|
57
|
+
## O que existe
|
|
58
|
+
|
|
59
|
+
| Camada | Algoritmos | Estado |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| Clássico puro | Ramp, Shutter, Canonize, Fringe, Refase | implementado e testado |
|
|
62
|
+
| Híbrido | Sampler, Estimator com Alignment Two, Mitigation audit, Budget, Transpile audit | implementado como contrato |
|
|
63
|
+
| Ponta quântica | Prepare, Evolve, Measure, Reset, Flow, Characterize | implementado como fluxo local |
|
|
64
|
+
| Ponte com backend real | as cinco responsabilidades híbridas | **planejado** |
|
|
65
|
+
|
|
66
|
+
A ponte com QPU e simulador externo não está implementada. Nenhum adaptador foi
|
|
67
|
+
conectado, e este README não afirma o contrário.
|
|
68
|
+
|
|
69
|
+
## As duas etapas do verificador
|
|
70
|
+
|
|
71
|
+
1. **Grossa**: esquema, versão de gramática e campos obrigatórios. Barata, falha cedo.
|
|
72
|
+
2. **Fina**: selo SHA3-256 sobre os bytes canônicos. Cara, falha tarde.
|
|
73
|
+
|
|
74
|
+
A cadeia tem verificação própria: um elo re-selado passa sozinho e só
|
|
75
|
+
`verify_chain` o denuncia, que é a diferença entre dano contíguo (*snowball*) e
|
|
76
|
+
dano distribuído (*shower*).
|
|
77
|
+
|
|
78
|
+
## Testado com simulador, não com hardware
|
|
79
|
+
|
|
80
|
+
A integração já rodada usa Qiskit Aer, simulador local: circuito de Bell, duas
|
|
81
|
+
rodadas de 1.024 tiros, p0 de 0,4951 e 0,5020, recibo e cadeia verificando,
|
|
82
|
+
adulteração recusada com `ISTH-FINE-SEAL`. Nenhum hardware foi usado.
|
|
83
|
+
|
|
84
|
+
## Contradição aberta
|
|
85
|
+
|
|
86
|
+
Alignment Two exige duas rodadas; a regra do projeto diz uma chamada de oráculo por
|
|
87
|
+
decisão. `Budget` recebe `oracle_calls` declarado em vez de fingir que é sempre um.
|
|
88
|
+
As três saídas possíveis estão em `docs/ISTHMUS_1.4_implementacao_2026-11-17.md`.
|
|
89
|
+
|
|
90
|
+
## Documentação
|
|
91
|
+
|
|
92
|
+
- `docs/ISTHMUS_prompt_mestre_2026-11-17.md`: especificação e prompt mestre
|
|
93
|
+
- `docs/ISTHMUS_v1.1_ponte_hibrida_2026-11-17.md`: ponte híbrida e maturidade
|
|
94
|
+
- `docs/ISTHMUS_1.2_vocabulario_verificacao_2026-11-17.md`: vocabulário e testes de aceite
|
|
95
|
+
- `docs/ISTHMUS_1.3_inventario_algoritmos_2026-11-17.md`: inventário e ordem de construção
|
|
96
|
+
- `docs/ISTHMUS_1.4_implementacao_2026-11-17.md`: primeira implementação, com medições
|
|
97
|
+
- `NAMING.md`: nome canônico, abreviação ISTH e a derivada STH
|
|
98
|
+
- `docs/ERRATA.md`: correções de nomenclatura, inclusive as que já foram para o histórico
|
|
99
|
+
- `CHANGELOG.md`: versões, mudanças e quebras
|
|
100
|
+
|
|
101
|
+
## Licença
|
|
102
|
+
|
|
103
|
+
Apache-2.0.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""isthmus: sublinguagem hibrida de interoperabilidade, controle e verificacao."""
|
|
3
|
+
__version__ = "1.0.0"
|
|
4
|
+
ABBREV = ("ISTH",)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def abbrev_name():
|
|
8
|
+
"""Abreviacao oficial de Isthmus."""
|
|
9
|
+
return ABBREV[0]
|
|
10
|
+
|
|
11
|
+
from .errors import Refusal, CODES
|
|
12
|
+
from .canon import canonize, PROFILES
|
|
13
|
+
from .fringe import fringe
|
|
14
|
+
from .shutter import shutter
|
|
15
|
+
from .ramp import fit as ramp_fit
|
|
16
|
+
from .refase import refase
|
|
17
|
+
from .budget import Budget
|
|
18
|
+
from .sampler import sample
|
|
19
|
+
from .estimator import estimate_two_rounds
|
|
20
|
+
from .mitigation import audit as mitigation_audit
|
|
21
|
+
from .transpile import audit as transpile_audit
|
|
22
|
+
from .quantum import Flow
|
|
23
|
+
from .characterize import characterize, check_band
|
|
24
|
+
from .receipt import build, verify, verify_chain, REQUIRED
|
|
25
|
+
|
|
26
|
+
__all__ = ["Refusal", "CODES", "canonize", "PROFILES", "fringe", "shutter", "ramp_fit",
|
|
27
|
+
"refase", "Budget", "sample", "estimate_two_rounds", "mitigation_audit",
|
|
28
|
+
"transpile_audit", "Flow", "characterize", "check_band", "build", "verify",
|
|
29
|
+
"verify_chain", "REQUIRED", "__version__", "ABBREV", "abbrev_name"]
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Adaptadores de execucao: a ponte que o Isthmus opera.
|
|
3
|
+
|
|
4
|
+
Dois lados, cada um com codigo de recusa proprio e nenhum silencio:
|
|
5
|
+
- qBraid: simulador gratuito (qir-sv), util como segundo lado do Alignment Two;
|
|
6
|
+
- IBM: QPU real pela API v1 da plataforma, com sampler V2.
|
|
7
|
+
|
|
8
|
+
Regra que vale para os dois: credencial ausente, saldo zero ou dispositivo offline
|
|
9
|
+
viram recusa declarada, nunca excecao crua e nunca resultado inventado.
|
|
10
|
+
"""
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import subprocess
|
|
14
|
+
|
|
15
|
+
from .errors import Refusal
|
|
16
|
+
|
|
17
|
+
IBM_BASE = "https://quantum.cloud.ibm.com/api/v1"
|
|
18
|
+
# CRN da instancia de quantum-computing; pode ser sobrescrito por IBM_CRN
|
|
19
|
+
IBM_CRN_PADRAO = ("crn:v1:bluemix:public:quantum-computing:us-east:"
|
|
20
|
+
"a/95c41207c62e44b4836797c50afa51b8:52de7392-9adb-443b-9b46-ea0b88a0145f::")
|
|
21
|
+
IBM_UA = ("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
|
|
22
|
+
"(KHTML, like Gecko) Chrome/131.0 Safari/537.36")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _curl(metodo, url, cabecalhos, corpo=None, timeout=90):
|
|
26
|
+
args = ["curl", "-s", "-w", "\n%{http_code}", "-m", str(timeout), "-X", metodo, url]
|
|
27
|
+
for k, v in cabecalhos.items():
|
|
28
|
+
args += ["-H", f"{k}: {v}"]
|
|
29
|
+
if corpo is not None:
|
|
30
|
+
args += ["-H", "content-type: application/json", "-d", json.dumps(corpo)]
|
|
31
|
+
saida = subprocess.run(args, capture_output=True, text=True, timeout=timeout + 15)
|
|
32
|
+
partes = saida.stdout.rsplit("\n", 1)
|
|
33
|
+
texto = partes[0] if len(partes) == 2 else ""
|
|
34
|
+
codigo = int(partes[1]) if len(partes) == 2 and partes[1].strip().isdigit() else 0
|
|
35
|
+
try:
|
|
36
|
+
return codigo, json.loads(texto or "{}")
|
|
37
|
+
except json.JSONDecodeError:
|
|
38
|
+
return codigo, {"bruto": texto[:300]}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# ----------------------------------------------------------------- qBraid
|
|
42
|
+
def qbraid_simulador(portoes, shots=1024, dispositivo="qbraid:qbraid:sim:qir-sv"):
|
|
43
|
+
"""Executa no simulador gratuito do qBraid. Sem credito, recusa ISTH-BUDGET."""
|
|
44
|
+
chave = os.environ.get("QBRAID_API_KEY") or os.environ.get("QBRAID_CHAVE")
|
|
45
|
+
if not chave:
|
|
46
|
+
raise Refusal("ISTH-BUDGET", "QBRAID_API_KEY ausente")
|
|
47
|
+
try:
|
|
48
|
+
from qbraid.runtime import QbraidProvider
|
|
49
|
+
except ImportError:
|
|
50
|
+
raise Refusal("ISTH-BUDGET", "SDK do qBraid ausente")
|
|
51
|
+
from qiskit import QuantumCircuit
|
|
52
|
+
n = 1 + max(max(p[1:]) for p in portoes)
|
|
53
|
+
qc = QuantumCircuit(n, n)
|
|
54
|
+
for porta in portoes:
|
|
55
|
+
nome = porta[0].upper()
|
|
56
|
+
if nome == "H":
|
|
57
|
+
qc.h(porta[1])
|
|
58
|
+
elif nome == "X":
|
|
59
|
+
qc.x(porta[1])
|
|
60
|
+
elif nome == "CNOT":
|
|
61
|
+
qc.cx(porta[1], porta[2])
|
|
62
|
+
else:
|
|
63
|
+
raise ValueError(f"porta fora do conjunto: {nome}")
|
|
64
|
+
qc.measure(range(n), range(n))
|
|
65
|
+
try:
|
|
66
|
+
alvo = QbraidProvider(api_key=chave).get_device(dispositivo)
|
|
67
|
+
resultado = alvo.run(qc, shots=shots).result()
|
|
68
|
+
except Exception as e:
|
|
69
|
+
texto = str(e)
|
|
70
|
+
if "Insufficient qBraid credits" in texto:
|
|
71
|
+
raise Refusal("ISTH-BUDGET", "saldo qBraid em zero")
|
|
72
|
+
raise Refusal("ISTH-BUDGET", f"qbraid: {texto[:120]}")
|
|
73
|
+
contagens = resultado.data.get_counts()
|
|
74
|
+
return {k.replace(" ", ""): int(v) for k, v in contagens.items()}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# ----------------------------------------------------------------- IBM
|
|
78
|
+
def _ibm_token():
|
|
79
|
+
chave = os.environ.get("IBM_API_KEY")
|
|
80
|
+
if not chave:
|
|
81
|
+
raise Refusal("ISTH-BUDGET", "IBM_API_KEY ausente")
|
|
82
|
+
saida = subprocess.run(
|
|
83
|
+
["curl", "-s", "-X", "POST", "https://iam.cloud.ibm.com/identity/token",
|
|
84
|
+
"-H", "content-type: application/x-www-form-urlencoded",
|
|
85
|
+
"--data-urlencode", "grant_type=urn:ibm:params:oauth:grant-type:apikey",
|
|
86
|
+
"--data-urlencode", f"apikey={chave}",
|
|
87
|
+
"--data-urlencode", "response_type=cloud_iam"],
|
|
88
|
+
capture_output=True, text=True, timeout=60)
|
|
89
|
+
try:
|
|
90
|
+
token = json.loads(saida.stdout)["access_token"]
|
|
91
|
+
except Exception:
|
|
92
|
+
raise Refusal("ISTH-BUDGET", "credencial IBM recusada pelo IAM")
|
|
93
|
+
return token
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _ibm(caminho, metodo="GET", corpo=None):
|
|
97
|
+
token = _ibm_token()
|
|
98
|
+
crn = os.environ.get("IBM_CRN") or IBM_CRN_PADRAO
|
|
99
|
+
return _curl(metodo, f"{IBM_BASE}{caminho}",
|
|
100
|
+
{"Authorization": f"Bearer {token}", "Service-CRN": crn,
|
|
101
|
+
"IBM-API-Version": "2025-05-01", "Accept": "application/json",
|
|
102
|
+
"User-Agent": IBM_UA}, corpo)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def ibm_dispositivos():
|
|
106
|
+
codigo, dados = _ibm("/backends")
|
|
107
|
+
if codigo != 200:
|
|
108
|
+
raise Refusal("ISTH-BUDGET", f"listagem IBM falhou: {codigo}")
|
|
109
|
+
return [d["name"] for d in dados.get("devices", [])
|
|
110
|
+
if d.get("status", {}).get("name") == "online"]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def ibm_executar(qasm, backend="ibm_kingston", shots=1024, timeout=600):
|
|
114
|
+
"""Submete um circuito OpenQASM 3 ao QPU real e devolve as contagens."""
|
|
115
|
+
codigo, resp = _ibm("/jobs", "POST", {"program_id": "sampler", "backend": backend,
|
|
116
|
+
"params": {"version": 2, "pubs": [[qasm, None, shots]]}})
|
|
117
|
+
if codigo != 200 or "id" not in resp:
|
|
118
|
+
raise Refusal("ISTH-BUDGET", f"submissao recusada: {codigo} {str(resp)[:120]}")
|
|
119
|
+
job = resp["id"]
|
|
120
|
+
import time
|
|
121
|
+
for _ in range(max(1, timeout // 10)):
|
|
122
|
+
_, st = _ibm(f"/jobs/{job}")
|
|
123
|
+
estado = st.get("state") or st.get("status") or {}
|
|
124
|
+
if isinstance(estado, dict):
|
|
125
|
+
estado = estado.get("name") or estado.get("status")
|
|
126
|
+
if str(estado).lower() == "completed":
|
|
127
|
+
_, res = _ibm(f"/jobs/{job}/results")
|
|
128
|
+
amostras = res["results"][0]["data"]["c"]["samples"]
|
|
129
|
+
n = int(res["results"][0]["data"]["c"].get("num_bits", 0)) or _bits(qasm)
|
|
130
|
+
contagens = {}
|
|
131
|
+
for s in amostras:
|
|
132
|
+
k = format(int(s, 16), f"0{n}b")
|
|
133
|
+
contagens[k] = contagens.get(k, 0) + 1
|
|
134
|
+
return {"job": job, "backend": backend, "contagens": contagens}
|
|
135
|
+
if str(estado).lower() in ("failed", "error", "cancelled"):
|
|
136
|
+
raise Refusal("ISTH-BUDGET", f"job {job} terminou em {estado}")
|
|
137
|
+
time.sleep(10)
|
|
138
|
+
raise Refusal("ISTH-BUDGET", f"job {job} nao terminou em {timeout}s")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def ibm_executar_circuito(circuito, backend="ibm_kingston", shots=1024, timeout=600):
|
|
142
|
+
"""Recebe um QuantumCircuit, transpila para os portoes nativos do alvo e executa."""
|
|
143
|
+
from qiskit import transpile, qasm3
|
|
144
|
+
codigo, conf = _ibm(f"/backends/{backend}/configuration")
|
|
145
|
+
if codigo != 200:
|
|
146
|
+
raise Refusal("ISTH-BUDGET", f"configuracao de {backend} indisponivel")
|
|
147
|
+
base = [g for g in conf["basis_gates"] if g != "xslow"] # xslow nao e portao padrao do Qiskit
|
|
148
|
+
pronto = transpile(circuito, basis_gates=base, coupling_map=conf["coupling_map"],
|
|
149
|
+
optimization_level=1, seed_transpiler=17)
|
|
150
|
+
return ibm_executar(qasm3.dumps(pronto), backend=backend, shots=shots, timeout=timeout)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _bits(qasm):
|
|
154
|
+
for linha in qasm.splitlines():
|
|
155
|
+
if linha.strip().startswith("bit["):
|
|
156
|
+
return int(linha.split("[")[1].split("]")[0])
|
|
157
|
+
return 0
|