qadence 1.11.0__py3-none-any.whl → 1.11.1__py3-none-any.whl

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.
@@ -281,6 +281,12 @@ class ObservableConfig:
281
281
  If True, the scale and shift are VariationalParameter.
282
282
  If False, the scale and shift are FeatureParameter.
283
283
  """
284
+ tag: str | None = None
285
+ """
286
+ String to indicate the name tag of the observable.
287
+
288
+ Defaults to None, in which case no tag will be applied.
289
+ """
284
290
 
285
291
  def __post_init__(self) -> None:
286
292
  if self.interaction is None and self.detuning is None:
@@ -313,6 +319,7 @@ def total_magnetization_config(
313
319
  scale=scale,
314
320
  shift=shift,
315
321
  trainable_transform=trainable_transform,
322
+ tag="Total Magnetization",
316
323
  )
317
324
 
318
325
 
@@ -327,6 +334,7 @@ def zz_hamiltonian_config(
327
334
  scale=scale,
328
335
  shift=shift,
329
336
  trainable_transform=trainable_transform,
337
+ tag="ZZ Hamiltonian",
330
338
  )
331
339
 
332
340
 
@@ -348,8 +356,9 @@ def ising_hamiltonian_config(
348
356
 
349
357
  return ObservableConfig(
350
358
  interaction=ZZ_Z_hamiltonian,
351
- detuning=Z,
359
+ detuning=X,
352
360
  scale=scale,
353
361
  shift=shift,
354
362
  trainable_transform=trainable_transform,
363
+ tag="Ising Hamiltonian",
355
364
  )
qadence/draw/utils.py CHANGED
@@ -147,7 +147,8 @@ def _(model: QuantumModel, *args: Any, **kwargs: Any) -> QuantumCircuitDiagram:
147
147
  raise ValueError("Cannot visualize QuantumModel with more than one observable.")
148
148
 
149
149
  obs = deepcopy(model._observable[0].original) # type: ignore [index]
150
- obs.tag = "Obs."
150
+ if not isinstance(obs.tag, str):
151
+ obs.tag = "Obs."
151
152
 
152
153
  block: AbstractBlock = chain(model._circuit.original.block, obs)
153
154
  else:
@@ -733,7 +733,13 @@ def create_observable(
733
733
  interaction=config.interaction,
734
734
  detuning=config.detuning,
735
735
  )
736
- return add(shifting_term, detuning_hamiltonian)
736
+
737
+ obs: AbstractBlock = add(shifting_term, detuning_hamiltonian)
738
+
739
+ if isinstance(config.tag, str):
740
+ tag(obs, config.tag)
741
+
742
+ return obs
737
743
 
738
744
 
739
745
  def build_qnn_from_configs(
@@ -795,7 +801,6 @@ def build_qnn_from_configs(
795
801
  if isinstance(observable_config, list)
796
802
  else create_observable(register=register, config=observable_config)
797
803
  )
798
-
799
804
  ufa = QNN(
800
805
  circ,
801
806
  observable,
@@ -360,13 +360,8 @@ class QNN(QuantumModel):
360
360
  )
361
361
  observable_str = ""
362
362
  if self._observable:
363
- observable_str = (
364
- "observable_config = [\n"
365
- + "\n".join(
366
- (block_to_mathematical_expression(obs.original) for obs in self._observable)
367
- )
368
- + "\n]"
369
- )
363
+ observable_str = f"observable_config = {self.observables_to_expression()}"
364
+
370
365
  return f"{type(self).__name__}(\n{configs_str}\n{observable_str}\n)"
371
366
 
372
367
  return super().__str__()
@@ -530,15 +530,7 @@ class Trainer(BaseTrainer):
530
530
  self.ng_params = ng_params
531
531
  loss_metrics = loss, metrics
532
532
 
533
- # --------------------- FIX: Post-Optimization Loss --------------------- #
534
- # Because the loss/metrics are returned before the optimization. To sync
535
- # model state and current loss/metrics we calculate them again after optimization.
536
- # This is not strictly necessary.
537
- # TODO: Should be removed if loss can be logged at an unoptimized model state
538
- with torch.no_grad():
539
- post_update_loss_metrics = self.loss_fn(self.model, batch)
540
-
541
- return self._modify_batch_end_loss_metrics(post_update_loss_metrics)
533
+ return self._modify_batch_end_loss_metrics(loss_metrics)
542
534
 
543
535
  @BaseTrainer.callback("val_epoch")
544
536
  def run_validation(self, dataloader: DataLoader) -> list[tuple[torch.Tensor, dict[str, Any]]]:
qadence/model.py CHANGED
@@ -27,6 +27,7 @@ from qadence.mitigations import Mitigations
27
27
  from qadence.noise import NoiseHandler
28
28
  from qadence.parameters import Parameter
29
29
  from qadence.types import DiffMode, Endianness
30
+ from qadence.utils import block_to_mathematical_expression
30
31
 
31
32
  logger = getLogger(__name__)
32
33
 
@@ -568,6 +569,28 @@ class QuantumModel(nn.Module):
568
569
  logger.warning(f"Unable to move {self} to {args}, {kwargs} due to {e}.")
569
570
  return self
570
571
 
572
+ def observables_to_expression(self) -> dict[str, str] | str:
573
+ """
574
+ Convert the observable to a dictionary representation of Pauli terms.
575
+
576
+ If no observable is set, returns an empty dictionary. Each observable is
577
+ represented by its tag (if available) as the key and its mathematical expression
578
+ as the value.
579
+
580
+ Returns:
581
+ dict[str, str]: A dictionary where the keys are observable tags (or "Obs." if not provided)
582
+ and the values are the corresponding mathematical expressions.
583
+ """
584
+ if self._observable is None:
585
+ return "No observable set."
586
+ else:
587
+ return {
588
+ obs.original.tag if obs.original.tag else "Obs.": block_to_mathematical_expression(
589
+ obs.original
590
+ )
591
+ for obs in self._observable
592
+ }
593
+
571
594
  @property
572
595
  def device(self) -> torch.device:
573
596
  """Get device.
qadence/register.py CHANGED
@@ -329,8 +329,12 @@ class Register:
329
329
  return Register(g, spacing=None, device_specs=self.device_specs)
330
330
 
331
331
  def _to_dict(self) -> dict:
332
+ try:
333
+ graph_data = nx.node_link_data(self.graph, edges="links")
334
+ except TypeError: # For Python 3.9 support
335
+ graph_data = nx.node_link_data(self.graph)
332
336
  return {
333
- "graph": nx.node_link_data(self.graph),
337
+ "graph": graph_data,
334
338
  "device_specs": self.device_specs._to_dict(),
335
339
  }
336
340
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qadence
3
- Version: 1.11.0
3
+ Version: 1.11.1
4
4
  Summary: Pasqal interface for circuit-based quantum computing SDKs
5
5
  Author-email: Aleksander Wennersteen <aleksander.wennersteen@pasqal.com>, Gert-Jan Both <gert-jan.both@pasqal.com>, Niklas Heim <niklas.heim@pasqal.com>, Mario Dagrada <mario.dagrada@pasqal.com>, Vincent Elfving <vincent.elfving@pasqal.com>, Dominik Seitz <dominik.seitz@pasqal.com>, Roland Guichard <roland.guichard@pasqal.com>, "Joao P. Moutinho" <joao.moutinho@pasqal.com>, Vytautas Abramavicius <vytautas.abramavicius@pasqal.com>, Gergana Velikova <gergana.velikova@pasqal.com>, Eduardo Maschio <eduardo.maschio@pasqal.com>, Smit Chaudhary <smit.chaudhary@pasqal.com>, Ignacio Fernández Graña <ignacio.fernandez-grana@pasqal.com>, Charles Moussa <charles.moussa@pasqal.com>, Giorgio Tosti Balducci <giorgio.tosti-balducci@pasqal.com>, Daniele Cucurachi <daniele.cucurachi@pasqal.com>, Pim Venderbosch <pim.venderbosch@pasqal.com>, Manu Lahariya <manu.lahariya@pasqal.com>
6
6
  License: Apache 2.0
@@ -23,7 +23,7 @@ Requires-Dist: nevergrad
23
23
  Requires-Dist: numpy
24
24
  Requires-Dist: openfermion
25
25
  Requires-Dist: pasqal-cloud
26
- Requires-Dist: pyqtorch==1.7.1
26
+ Requires-Dist: pyqtorch==1.7.2
27
27
  Requires-Dist: pyyaml
28
28
  Requires-Dist: rich
29
29
  Requires-Dist: scipy
@@ -55,7 +55,7 @@ Requires-Dist: mlflow; extra == 'mlflow'
55
55
  Provides-Extra: protocols
56
56
  Requires-Dist: qadence-protocols; extra == 'protocols'
57
57
  Provides-Extra: pulser
58
- Requires-Dist: pasqal-cloud==0.13.0; extra == 'pulser'
58
+ Requires-Dist: pasqal-cloud==0.20.2; extra == 'pulser'
59
59
  Requires-Dist: pulser-core==1.3.0; extra == 'pulser'
60
60
  Requires-Dist: pulser-simulation==1.3.0; extra == 'pulser'
61
61
  Provides-Extra: visualization
@@ -8,14 +8,14 @@ qadence/extensions.py,sha256=Bx2cMsBq3sNTnmwPoqQF-7Tks-FspXb1fTl6zncJFUE,6068
8
8
  qadence/libs.py,sha256=HetkKO8TCTlVCViQdVQJvxwBekrhd-y_iMox4UJMY1M,410
9
9
  qadence/log_config.yaml,sha256=QiwoB1bnRdk9NpxnvfgWX2PjN7EDfYlrc3GVD38rtdI,739
10
10
  qadence/logger.py,sha256=Hb76pK3VyQjVjJb4_NqFlOJgjYJVa8t7DHJFlzOM86M,407
11
- qadence/model.py,sha256=OH61_Ij_c7PRywiXf16tJ5mnK9iYNbBTdRiHeG8PZ54,21623
11
+ qadence/model.py,sha256=88zou7mge3JVFhed_X9Zr83QRh3Bq17GRCzVbru-B44,22581
12
12
  qadence/overlap.py,sha256=ekaUnIcQWdF4hSFuUWpRjaxo43JyDGFOayP7vMXCZpw,16821
13
13
  qadence/parameters.py,sha256=RDYklyW5EQZTjsAazEXa4lLGDOdmUUU53hLj385uSaI,12687
14
14
  qadence/pasqal_cloud_connection.py,sha256=1lz_AJRo54-YMnsYGJD_SFpUK-0_ZzJRWr9Qqa_pBZU,9675
15
15
  qadence/protocols.py,sha256=bcYTxSjgMPV-a-D6yv90jCpnGik8myzaNpFv9z1gzJ0,442
16
16
  qadence/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  qadence/qubit_support.py,sha256=Nkn1Q01RVViTcggSIom7EFKdWpAuM4TMGwBZ5feCUxA,2120
18
- qadence/register.py,sha256=mwmvS6PcTY0F9cIhTUXG3NT73FIagfMCwVqYa4DrQrk,13001
18
+ qadence/register.py,sha256=MlI1-L1P_e7ugjelhH-1YdxrfPsgmLmX5m-dueawuWQ,13172
19
19
  qadence/serial_expr_grammar.peg,sha256=z5ytL7do9kO8o4h-V5GrsDuLdso0KsRcMuIYURFfmAY,328
20
20
  qadence/serialization.py,sha256=qEET6Gu9u2aSibPve3bJrqDzK2_gO3RPDJjt4ZY8GbE,15596
21
21
  qadence/states.py,sha256=Aj28aNHGWkZrFw_mKpHrxCA1bDXlkFhw18D70tg0RF0,15953
@@ -62,7 +62,7 @@ qadence/blocks/utils.py,sha256=_V43qD7kQNK8JS3gxfpkRn56ZIF_GGrhAnARn1hq2hk,17772
62
62
  qadence/constructors/__init__.py,sha256=LiFkGzgMa27LrY1LhINfmj3UWfrjoUk9wwRM9a54rK0,1211
63
63
  qadence/constructors/ala.py,sha256=76rdD_vMki5F_r_Iq-68zU3NHrJiebVmr-e7L4lIDAo,8359
64
64
  qadence/constructors/feature_maps.py,sha256=BaAxFi6fSKwjsfFjqZ8T7lyZfjotcgH2OW3b0j67YVk,8644
65
- qadence/constructors/hamiltonians.py,sha256=FR0WDDI2c6zqv8U1DI786xsbKEpvvcyc3xFxX72mcEw,12543
65
+ qadence/constructors/hamiltonians.py,sha256=SSo_Cd1wr8ryXz_DN2xSPlQNauXwYhDQPzP35tmYdtM,12800
66
66
  qadence/constructors/hea.py,sha256=EJveIvEAwOGWfMQ08LUdZkjTRFoqQioXjQXimv4-VUs,11702
67
67
  qadence/constructors/iia.py,sha256=wYcvR-4U-C1WkyK_EN8Rz2g3kZpWb1-302X3h60PtWw,7946
68
68
  qadence/constructors/qft.py,sha256=2LpgQ-z1HUxB3rqHzYsbjqpdU63gyuuaUVCbNEFbjo8,7688
@@ -75,7 +75,7 @@ qadence/constructors/daqc/gen_parser.py,sha256=taZMJ9BNp672qXqsNSQ8RY71tN2gMV4Rb
75
75
  qadence/constructors/daqc/utils.py,sha256=1T83veISoOXhJYUWXhfocbISpfIgsrKrdDHCMbskGoQ,1067
76
76
  qadence/draw/__init__.py,sha256=A2lU7_CfCjwZCnMRojG5CsoWm-7aWKpUYGyaJ9qBZIQ,2319
77
77
  qadence/draw/themes.py,sha256=VV4YtC8X3UI63AuJO2D0fLMTLbdDUjIyXQcKuDuIVmI,5533
78
- qadence/draw/utils.py,sha256=4Hk-vwGz6ZRLKYnV26r1g3zBvOONvlFiN4Kh6toUsI0,12107
78
+ qadence/draw/utils.py,sha256=Xr9XIFzsdux9Z2GrPL6RYf_5RYohQiavI0R3eF-FaHk,12152
79
79
  qadence/draw/vizbackend.py,sha256=BKq1fjW7zgEhaIhrmi-i6XV9ZWY7NmlmdDo9-tfP0Hk,14997
80
80
  qadence/draw/assets/dark/measurement.png,sha256=hSMhZZCFKHNO2tCpYTTSYIF-nsAfNalRunRUIyhygC0,502
81
81
  qadence/draw/assets/dark/measurement.svg,sha256=6ALGjaCX3xZ1NqB6RW6yzOchzZV-j8ukW4aGhEWe4Lk,7282
@@ -103,14 +103,14 @@ qadence/mitigations/protocols.py,sha256=0TeHvlGTN8_88XNEwrjA97C5BUlrh34wYmx0w6-5
103
103
  qadence/mitigations/readout.py,sha256=nI-voV5N0R7630Cn8t8x9EdV9iB76P0LDkRosy1s0Ec,6631
104
104
  qadence/ml_tools/__init__.py,sha256=Z744FRFAzU5iw-4JC5YC43mDQD6rTa5ApdkWbUFuTbQ,970
105
105
  qadence/ml_tools/config.py,sha256=0qN0FVXRwYNMLGKgvk70cHTnEbl5_p83dU85sIyXls4,22728
106
- qadence/ml_tools/constructors.py,sha256=tzKCWX4RL-M3HOoEh2Q5Y-Bl16AsFXJS4lL7Oy5GgsA,27842
106
+ qadence/ml_tools/constructors.py,sha256=L_oai1uOUK_jQW0G18lgBS2vZ5QJtmT4mvCnjGsHvzc,27938
107
107
  qadence/ml_tools/data.py,sha256=-HUQk3-0UHOBA4KMFQ63tlt3si4W66psbgR1DAjtoVE,5481
108
- qadence/ml_tools/models.py,sha256=H-UY3bShlc4QX9jUytFkamwuTsypH8jIecDhxvGHR7g,19303
108
+ qadence/ml_tools/models.py,sha256=v3zRLuLN2IyTaL3eTNbdS65E1UeQV-mcZD3uIPJ6Eng,19112
109
109
  qadence/ml_tools/optimize_step.py,sha256=21m2Wxmxkj_kMHQnKygOWqFdcO-wi5CnMnIZTGEw9IM,3300
110
110
  qadence/ml_tools/parameters.py,sha256=gew2Kq_5-RgRpaTvs8eauVhgo0sTqqDQEV6WHFEiLGM,1301
111
111
  qadence/ml_tools/stages.py,sha256=qW2phMIvQBLM3tn2UoGN-ePiBnZoNq5k844eHVnnn8Y,1407
112
112
  qadence/ml_tools/tensors.py,sha256=xZ9ZRzOqEaMgLUGWQf1najDmL6iLuN1ojCGVFs1Tm94,1337
113
- qadence/ml_tools/trainer.py,sha256=dXXkywtyPTtq2bbZSGBS2XUKGtGT8GGaCP7kP3UWU5A,35412
113
+ qadence/ml_tools/trainer.py,sha256=rAm4hpXpPSt1pCWUtMenVBsRXiodwBpUpmWWMP1duDs,34914
114
114
  qadence/ml_tools/utils.py,sha256=PW8FyoV0mG_DtN1U8njTDV5qxZ0EK4mnFwMAsLBArfk,1410
115
115
  qadence/ml_tools/callbacks/__init__.py,sha256=pTdfjulDGNKca--9BgrdmMyvJSah_0spp929Th6RzC8,913
116
116
  qadence/ml_tools/callbacks/callback.py,sha256=JVY1BtPItCx11oAa1-3wICZyDfDLFdc5pmjTbfASHqA,29929
@@ -144,7 +144,7 @@ qadence/transpile/flatten.py,sha256=k4HAfVzvDV40HyfaukiEHyJtAtvFRIcyDbAWiCL8tf0,
144
144
  qadence/transpile/invert.py,sha256=IeyidgBwECCKB0i7Ym0KkLyfcx42LyT2mbqkfbK1H8M,4843
145
145
  qadence/transpile/noise.py,sha256=LDcDJtQGkgUPkL2t69gg6AScTb-p3J3SxCDZbYOu1L8,1668
146
146
  qadence/transpile/transpile.py,sha256=xnzkHA6Qdb-Y5Fv9Latrolrpw44N6_OKc7_QGt70f0I,2713
147
- qadence-1.11.0.dist-info/METADATA,sha256=y7-SPjq9bkVeTmytdaL_BeWQwvAXA16JdXKss6MNxjI,10211
148
- qadence-1.11.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
149
- qadence-1.11.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
150
- qadence-1.11.0.dist-info/RECORD,,
147
+ qadence-1.11.1.dist-info/METADATA,sha256=BrS9vWyf87UbydethjWshIbhObTb9Nu5DleYwC8q154,10211
148
+ qadence-1.11.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
149
+ qadence-1.11.1.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
150
+ qadence-1.11.1.dist-info/RECORD,,