classiq 0.32.1__py3-none-any.whl → 0.34.0__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.
Files changed (74) hide show
  1. classiq/__init__.py +2 -1
  2. classiq/_analyzer_extras/_ipywidgets_async_extension.py +1 -1
  3. classiq/_internals/api_wrapper.py +34 -23
  4. classiq/_internals/jobs.py +41 -14
  5. classiq/analyzer/__init__.py +3 -1
  6. classiq/applications/__init__.py +3 -1
  7. classiq/applications/benchmarking/__init__.py +3 -1
  8. classiq/applications/chemistry/__init__.py +3 -1
  9. classiq/applications/combinatorial_optimization/__init__.py +3 -1
  10. classiq/applications/combinatorial_optimization/examples/__init__.py +3 -1
  11. classiq/applications/finance/__init__.py +3 -1
  12. classiq/applications/qnn/__init__.py +3 -1
  13. classiq/applications/qnn/datasets/__init__.py +3 -1
  14. classiq/applications/qsvm/qsvm.py +1 -1
  15. classiq/applications_model_constructors/grover_model_constructor.py +25 -8
  16. classiq/builtin_functions/__init__.py +3 -1
  17. classiq/execution/__init__.py +3 -1
  18. classiq/execution/jobs.py +57 -20
  19. classiq/executor.py +4 -11
  20. classiq/interface/_version.py +1 -1
  21. classiq/interface/analyzer/analysis_params.py +1 -1
  22. classiq/interface/backend/backend_preferences.py +17 -0
  23. classiq/interface/backend/pydantic_backend.py +8 -0
  24. classiq/interface/backend/quantum_backend_providers.py +15 -1
  25. classiq/interface/chemistry/ground_state_problem.py +1 -1
  26. classiq/interface/chemistry/operator.py +198 -0
  27. classiq/interface/executor/execution_request.py +5 -12
  28. classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
  29. classiq/interface/generator/complex_type.py +4 -1
  30. classiq/interface/generator/functions/__init__.py +3 -1
  31. classiq/interface/generator/functions/core_lib_declarations/quantum_functions/__init__.py +0 -1
  32. classiq/interface/generator/functions/core_lib_declarations/quantum_functions/atomic_quantum_functions.py +39 -39
  33. classiq/interface/generator/functions/core_lib_declarations/quantum_functions/std_lib_functions.py +251 -87
  34. classiq/interface/generator/functions/core_lib_declarations/quantum_operators.py +5 -54
  35. classiq/interface/generator/generated_circuit.py +14 -43
  36. classiq/interface/generator/generated_circuit_data.py +26 -34
  37. classiq/interface/generator/model/preferences/preferences.py +3 -3
  38. classiq/interface/generator/partitioned_register.py +1 -1
  39. classiq/interface/generator/quantum_function_call.py +1 -1
  40. classiq/interface/generator/validations/validator_functions.py +4 -2
  41. classiq/interface/hardware.py +3 -2
  42. classiq/interface/ide/show.py +1 -14
  43. classiq/interface/model/bind_operation.py +20 -0
  44. classiq/interface/model/handle_binding.py +8 -0
  45. classiq/interface/model/native_function_definition.py +15 -5
  46. classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +8 -3
  47. classiq/interface/model/quantum_expressions/arithmetic_operation.py +9 -4
  48. classiq/interface/model/quantum_expressions/quantum_expression.py +10 -5
  49. classiq/interface/model/quantum_function_call.py +24 -347
  50. classiq/interface/model/quantum_function_declaration.py +7 -11
  51. classiq/interface/model/quantum_statement.py +13 -7
  52. classiq/interface/model/validations/handle_validation_base.py +1 -2
  53. classiq/interface/model/validations/handles_validator.py +34 -8
  54. classiq/interface/model/variable_declaration_statement.py +8 -0
  55. classiq/interface/server/routes.py +11 -16
  56. classiq/model/__init__.py +3 -1
  57. classiq/model/function_handler.py +1 -1
  58. classiq/model/function_handler.pyi +88 -88
  59. classiq/qmod/declaration_inferrer.py +37 -18
  60. classiq/qmod/model_state_container.py +6 -3
  61. classiq/qmod/qmod_builtins.py +892 -4
  62. classiq/qmod/qmod_parameter.py +24 -8
  63. classiq/qmod/qmod_variable.py +2 -1
  64. classiq/qmod/quantum_expandable.py +6 -2
  65. classiq/qmod/quantum_function.py +11 -10
  66. classiq/quantum_functions/quantum_function.py +4 -1
  67. {classiq-0.32.1.dist-info → classiq-0.34.0.dist-info}/METADATA +1 -1
  68. {classiq-0.32.1.dist-info → classiq-0.34.0.dist-info}/RECORD +69 -72
  69. classiq/interface/generator/functions/core_lib_declarations/quantum_functions/apps_lib_functions.py +0 -262
  70. classiq/interface/model/clients/__init__.py +0 -0
  71. classiq/interface/model/clients/qmod/__init__.py +0 -0
  72. classiq/interface/model/clients/qmod/qmod_builtins.py +0 -908
  73. classiq/interface/model/semantics.py +0 -15
  74. {classiq-0.32.1.dist-info → classiq-0.34.0.dist-info}/WHEEL +0 -0
@@ -7,17 +7,10 @@ from classiq.interface.model.quantum_function_declaration import (
7
7
  QFT_STEP = QuantumFunctionDeclaration.parse_raw(
8
8
  """{
9
9
  "name": "qft_step",
10
- "param_decls": {
11
- "num_qbits": {
12
- "kind": "int"
13
- }
14
- },
10
+ "param_decls": {},
15
11
  "port_declarations": {
16
- "qbv": {
17
- "name": "qbv",
18
- "size": {
19
- "expr": "num_qbits"
20
- },
12
+ "target": {
13
+ "name": "target",
21
14
  "direction": "inout"
22
15
  }
23
16
  },
@@ -29,17 +22,10 @@ QFT_STEP = QuantumFunctionDeclaration.parse_raw(
29
22
  QFT = QuantumFunctionDeclaration.parse_raw(
30
23
  """{
31
24
  "name": "qft",
32
- "param_decls": {
33
- "num_qbits": {
34
- "kind": "int"
35
- }
36
- },
25
+ "param_decls": {},
37
26
  "port_declarations": {
38
- "qbv": {
39
- "name": "qbv",
40
- "size": {
41
- "expr": "num_qbits"
42
- },
27
+ "target": {
28
+ "name": "target",
43
29
  "direction": "inout"
44
30
  }
45
31
  },
@@ -52,41 +38,22 @@ QPE = QuantumFunctionDeclaration.parse_raw(
52
38
  """{
53
39
  "name": "qpe",
54
40
  "param_decls": {
55
- "reg_size": {
56
- "kind": "int"
57
- },
58
- "qpe_reg_size": {
41
+ "precision": {
59
42
  "kind": "int"
60
43
  }
61
44
  },
62
45
  "port_declarations": {
63
- "x": {
64
- "name": "x",
46
+ "phase": {
47
+ "name": "phase",
65
48
  "size": {
66
- "expr": "reg_size"
49
+ "expr": "precision"
67
50
  },
68
- "direction": "inout"
69
- },
70
- "q": {
71
- "name": "q",
72
- "size": {
73
- "expr": "qpe_reg_size"
74
- },
75
- "direction": "inout"
51
+ "direction": "output"
76
52
  }
77
53
  },
78
54
  "operand_declarations": {
79
- "qfunc": {
80
- "name": "qfunc",
81
- "port_declarations": {
82
- "target": {
83
- "name": "target",
84
- "size": {
85
- "expr": "reg_size"
86
- },
87
- "direction": "inout"
88
- }
89
- }
55
+ "unitary": {
56
+ "name": "unitary"
90
57
  }
91
58
  },
92
59
  "positional_arg_declarations": []
@@ -97,9 +64,6 @@ SINGLE_PAULI = QuantumFunctionDeclaration.parse_raw(
97
64
  """{
98
65
  "name": "single_pauli",
99
66
  "param_decls": {
100
- "reg_size": {
101
- "kind": "int"
102
- },
103
67
  "slope": {
104
68
  "kind": "real"
105
69
  },
@@ -110,9 +74,6 @@ SINGLE_PAULI = QuantumFunctionDeclaration.parse_raw(
110
74
  "port_declarations": {
111
75
  "x": {
112
76
  "name": "x",
113
- "size": {
114
- "expr": "reg_size"
115
- },
116
77
  "direction": "inout"
117
78
  },
118
79
  "q": {
@@ -150,12 +111,6 @@ LINEAR_PAULI_ROTATIONS = QuantumFunctionDeclaration.parse_raw(
150
111
  """{
151
112
  "name": "linear_pauli_rotations",
152
113
  "param_decls": {
153
- "reg_size": {
154
- "kind": "int"
155
- },
156
- "num_state_qubits": {
157
- "kind": "int"
158
- },
159
114
  "bases": {
160
115
  "kind": "list",
161
116
  "element_type": {
@@ -178,16 +133,10 @@ LINEAR_PAULI_ROTATIONS = QuantumFunctionDeclaration.parse_raw(
178
133
  "port_declarations": {
179
134
  "x": {
180
135
  "name": "x",
181
- "size": {
182
- "expr": "reg_size"
183
- },
184
136
  "direction": "inout"
185
137
  },
186
138
  "q": {
187
139
  "name": "q",
188
- "size": {
189
- "expr": "num_state_qubits"
190
- },
191
140
  "direction": "inout"
192
141
  }
193
142
  },
@@ -377,20 +326,13 @@ GROVER_OPERATOR = QuantumFunctionDeclaration.parse_raw(
377
326
  }"""
378
327
  )
379
328
 
380
- UNIFORM_SUPERPOSITION = QuantumFunctionDeclaration.parse_raw(
329
+ HADAMARD_TRANSFORM = QuantumFunctionDeclaration.parse_raw(
381
330
  """{
382
- "name": "uniform_superposition",
383
- "param_decls": {
384
- "num_qubits": {
385
- "kind": "int"
386
- }
387
- },
331
+ "name": "hadamard_transform",
332
+ "param_decls": {},
388
333
  "port_declarations": {
389
- "q": {
390
- "name": "q",
391
- "size": {
392
- "expr": "num_qubits"
393
- },
334
+ "target": {
335
+ "name": "target",
394
336
  "direction": "inout"
395
337
  }
396
338
  },
@@ -402,17 +344,10 @@ UNIFORM_SUPERPOSITION = QuantumFunctionDeclaration.parse_raw(
402
344
  APPLY_TO_ALL = QuantumFunctionDeclaration.parse_raw(
403
345
  """{
404
346
  "name": "apply_to_all",
405
- "param_decls": {
406
- "num_qubits": {
407
- "kind": "int"
408
- }
409
- },
347
+ "param_decls": {},
410
348
  "port_declarations": {
411
- "q": {
412
- "name": "q",
413
- "size": {
414
- "expr": "num_qubits"
415
- },
349
+ "target": {
350
+ "name": "target",
416
351
  "direction": "inout"
417
352
  }
418
353
  },
@@ -499,6 +434,229 @@ PREPARE_INT = QuantumFunctionDeclaration.parse_raw(
499
434
  }"""
500
435
  )
501
436
 
437
+ QAOA_MIXER_LAYER = QuantumFunctionDeclaration.parse_raw(
438
+ """{
439
+ "name": "qaoa_mixer_layer",
440
+ "param_decls": {
441
+ "b": {
442
+ "kind": "real"
443
+ }
444
+ },
445
+ "port_declarations": {
446
+ "target": {
447
+ "name": "target",
448
+ "direction": "inout"
449
+ }
450
+ },
451
+ "operand_declarations": {},
452
+ "positional_arg_declarations": []
453
+ }"""
454
+ )
455
+
456
+ QAOA_COST_LAYER = QuantumFunctionDeclaration.parse_raw(
457
+ """{
458
+ "name": "qaoa_cost_layer",
459
+ "param_decls": {
460
+ "g": {
461
+ "kind": "real"
462
+ },
463
+ "hamiltonian": {
464
+ "kind": "list",
465
+ "element_type": {
466
+ "kind": "struct_instance",
467
+ "name": "PauliTerm"
468
+ }
469
+ },
470
+ "is_st": {
471
+ "kind": "bool"
472
+ }
473
+ },
474
+ "port_declarations": {
475
+ "target": {
476
+ "name": "target",
477
+ "direction": "inout"
478
+ }
479
+ },
480
+ "operand_declarations": {},
481
+ "positional_arg_declarations": []
482
+ }"""
483
+ )
484
+
485
+ QAOA_LAYER = QuantumFunctionDeclaration.parse_raw(
486
+ """{
487
+ "name": "qaoa_layer",
488
+ "param_decls": {
489
+ "g": {
490
+ "kind": "real"
491
+ },
492
+ "b": {
493
+ "kind": "real"
494
+ },
495
+ "hamiltonian": {
496
+ "kind": "list",
497
+ "element_type": {
498
+ "kind": "struct_instance",
499
+ "name": "PauliTerm"
500
+ }
501
+ },
502
+ "is_st": {
503
+ "kind": "bool"
504
+ }
505
+ },
506
+ "port_declarations": {
507
+ "target": {
508
+ "name": "target",
509
+ "direction": "inout"
510
+ }
511
+ },
512
+ "operand_declarations": {},
513
+ "positional_arg_declarations": []
514
+ }"""
515
+ )
516
+
517
+ QAOA_INIT = QuantumFunctionDeclaration.parse_raw(
518
+ """{
519
+ "name": "qaoa_init",
520
+ "param_decls": {},
521
+ "port_declarations": {
522
+ "target": {
523
+ "name": "target",
524
+ "direction": "inout"
525
+ }
526
+ },
527
+ "operand_declarations": {},
528
+ "positional_arg_declarations": []
529
+ }"""
530
+ )
531
+
532
+ QAOA_PENALTY = QuantumFunctionDeclaration.parse_raw(
533
+ """{
534
+ "name": "qaoa_penalty",
535
+ "param_decls": {
536
+ "num_qubits": {
537
+ "kind": "int"
538
+ },
539
+ "params_list": {
540
+ "kind": "list",
541
+ "element_type": {
542
+ "kind": "real"
543
+ }
544
+ },
545
+ "hamiltonian": {
546
+ "kind": "list",
547
+ "element_type": {
548
+ "kind": "struct_instance",
549
+ "name": "PauliTerm"
550
+ }
551
+ },
552
+ "is_st": {
553
+ "kind": "bool"
554
+ }
555
+ },
556
+ "port_declarations": {
557
+ "target": {
558
+ "name": "target",
559
+ "size": {
560
+ "expr": "num_qubits"
561
+ },
562
+ "direction": "inout"
563
+ }
564
+ },
565
+ "operand_declarations": {},
566
+ "positional_arg_declarations": []
567
+ }"""
568
+ )
569
+
570
+ FULL_HEA = QuantumFunctionDeclaration.parse_raw(
571
+ """{
572
+ "name": "full_hea",
573
+ "param_decls": {
574
+ "num_qubits": {
575
+ "kind": "int"
576
+ },
577
+ "is_parametrized": {
578
+ "kind": "list",
579
+ "element_type": {
580
+ "kind": "int"
581
+ }
582
+ },
583
+ "angle_params": {
584
+ "kind": "list",
585
+ "element_type": {
586
+ "kind": "real"
587
+ }
588
+ },
589
+ "connectivity_map": {
590
+ "kind": "list",
591
+ "element_type": {
592
+ "kind": "list",
593
+ "element_type": {
594
+ "kind": "int"
595
+ }
596
+ }
597
+ },
598
+ "reps": {
599
+ "kind": "int"
600
+ }
601
+ },
602
+ "port_declarations": {
603
+ "x": {
604
+ "name": "x",
605
+ "size": {
606
+ "expr": "num_qubits"
607
+ },
608
+ "direction": "inout"
609
+ }
610
+ },
611
+ "operand_declarations": {
612
+ "operands_1qubit": {
613
+ "name": "operands_1qubit",
614
+ "param_decls": {
615
+ "angle": {
616
+ "kind": "real"
617
+ }
618
+ },
619
+ "port_declarations": {
620
+ "q": {
621
+ "name": "q",
622
+ "size": {
623
+ "expr": "1"
624
+ },
625
+ "direction": "inout"
626
+ }
627
+ },
628
+ "is_list": true
629
+ },
630
+ "operands_2qubit": {
631
+ "name": "operands_2qubit",
632
+ "param_decls": {
633
+ "angle": {
634
+ "kind": "real"
635
+ }
636
+ },
637
+ "port_declarations": {
638
+ "q1": {
639
+ "name": "q1",
640
+ "size": {
641
+ "expr": "1"
642
+ },
643
+ "direction": "inout"
644
+ },
645
+ "q2": {
646
+ "name": "q2",
647
+ "size": {
648
+ "expr": "1"
649
+ },
650
+ "direction": "inout"
651
+ }
652
+ },
653
+ "is_list": true
654
+ }
655
+ },
656
+ "positional_arg_declarations": []
657
+ }"""
658
+ )
659
+
502
660
  __all__ = [
503
661
  "QFT_STEP",
504
662
  "QFT",
@@ -509,8 +667,14 @@ __all__ = [
509
667
  "SIMPLE_ORACLE",
510
668
  "GROVER_DIFFUSER",
511
669
  "GROVER_OPERATOR",
512
- "UNIFORM_SUPERPOSITION",
670
+ "HADAMARD_TRANSFORM",
513
671
  "APPLY_TO_ALL",
514
672
  "GROVER_SEARCH",
515
673
  "PREPARE_INT",
674
+ "QAOA_MIXER_LAYER",
675
+ "QAOA_COST_LAYER",
676
+ "QAOA_LAYER",
677
+ "QAOA_INIT",
678
+ "QAOA_PENALTY",
679
+ "FULL_HEA",
516
680
  ]
@@ -23,24 +23,7 @@ REPEAT_OPERATOR = QuantumFunctionDeclaration(
23
23
 
24
24
  INVERT_OPERATOR = QuantumFunctionDeclaration(
25
25
  name="invert",
26
- port_declarations={
27
- "target": PortDeclaration(
28
- name="target",
29
- direction=PortDeclarationDirection.Inout,
30
- ),
31
- },
32
- operand_declarations={
33
- "operand": QuantumOperandDeclaration(
34
- name="operand",
35
- port_declarations={
36
- "target": PortDeclaration(
37
- name="target",
38
- direction=PortDeclarationDirection.Inout,
39
- size=Expression(expr="len(target)"),
40
- )
41
- },
42
- ),
43
- },
26
+ operand_declarations={"operand": QuantumOperandDeclaration(name="operand")},
44
27
  )
45
28
 
46
29
 
@@ -50,24 +33,9 @@ CONTROL_OPERATOR = QuantumFunctionDeclaration(
50
33
  "ctrl": PortDeclaration(
51
34
  name="ctrl",
52
35
  direction=PortDeclarationDirection.Inout,
53
- ),
54
- "target": PortDeclaration(
55
- name="target",
56
- direction=PortDeclarationDirection.Inout,
57
- ),
58
- },
59
- operand_declarations={
60
- "operand": QuantumOperandDeclaration(
61
- name="operand",
62
- port_declarations={
63
- "target": PortDeclaration(
64
- name="target",
65
- direction=PortDeclarationDirection.Inout,
66
- size=Expression(expr="len(target)"),
67
- )
68
- },
69
36
  )
70
37
  },
38
+ operand_declarations={"operand": QuantumOperandDeclaration(name="operand")},
71
39
  )
72
40
 
73
41
  IF_OPERATOR = QuantumFunctionDeclaration(
@@ -138,28 +106,11 @@ PERMUTE_OPERATOR = QuantumFunctionDeclaration(
138
106
  POWER_OPERATOR = QuantumFunctionDeclaration(
139
107
  name="power",
140
108
  param_decls={"power": Integer()},
141
- port_declarations={
142
- "qbv": PortDeclaration(
143
- name="qbv",
144
- direction=PortDeclarationDirection.Inout,
145
- )
146
- },
147
- operand_declarations={
148
- "operand": QuantumOperandDeclaration(
149
- name="operand",
150
- port_declarations={
151
- "qbv": PortDeclaration(
152
- name="qbv",
153
- direction=PortDeclarationDirection.Inout,
154
- size=Expression(expr="len(qbv)"),
155
- )
156
- },
157
- )
158
- },
109
+ operand_declarations={"operand": QuantumOperandDeclaration(name="operand")},
159
110
  )
160
111
 
161
112
 
162
- _BUILTIN_QUANTUM_OPERATOR_LIST = [
113
+ BUILTIN_QUANTUM_OPERATOR_LIST = [
163
114
  REPEAT_OPERATOR,
164
115
  INVERT_OPERATOR,
165
116
  CONTROL_OPERATOR,
@@ -173,5 +124,5 @@ _BUILTIN_QUANTUM_OPERATOR_LIST = [
173
124
 
174
125
 
175
126
  QuantumFunctionDeclaration.BUILTIN_FUNCTION_DECLARATIONS.update(
176
- nameables_to_dict(_BUILTIN_QUANTUM_OPERATOR_LIST)
127
+ nameables_to_dict(BUILTIN_QUANTUM_OPERATOR_LIST)
177
128
  )
@@ -1,7 +1,7 @@
1
- import abc
1
+ import uuid
2
2
  from datetime import datetime
3
3
  from pathlib import Path
4
- from typing import Dict, List, Literal, Optional, Tuple, Union
4
+ from typing import Dict, List, Optional, Tuple, Union
5
5
 
6
6
  import pydantic
7
7
  from typing_extensions import TypeAlias
@@ -16,9 +16,7 @@ from classiq.interface.generator.circuit_code.types_and_constants import (
16
16
  VENDOR_TO_INSTRUCTION_SET,
17
17
  CodeAndSyntax,
18
18
  )
19
- from classiq.interface.generator.function_params import ArithmeticIODict
20
19
  from classiq.interface.generator.generated_circuit_data import (
21
- ExecutionCircuitData,
22
20
  FunctionDebugInfo,
23
21
  GeneratedCircuitData,
24
22
  )
@@ -27,7 +25,6 @@ from classiq.interface.generator.model.model import ExecutionModel, SynthesisMod
27
25
  from classiq.interface.generator.synthesis_metadata.synthesis_duration import (
28
26
  SynthesisStepDurations,
29
27
  )
30
- from classiq.interface.helpers.pydantic_model_helpers import get_discriminator_field
31
28
  from classiq.interface.helpers.versioned_model import VersionedModel
32
29
  from classiq.interface.ide.ide_data import CircuitMetrics
33
30
 
@@ -50,11 +47,20 @@ class TranspiledCircuitData(CircuitCodeInterface):
50
47
  return CircuitMetrics(depth=self.depth, count_ops=self.count_ops)
51
48
 
52
49
 
53
- class GeneratedCircuitBase(abc.ABC, VersionedModel, CircuitCodeInterface):
50
+ def get_uuid_as_str() -> str:
51
+ return str(uuid.uuid4())
52
+
53
+
54
+ class GeneratedCircuit(VersionedModel, CircuitCodeInterface):
54
55
  hardware_data: SynthesisHardwareData
55
- data: Union[GeneratedCircuitData, ExecutionCircuitData]
56
56
  initial_values: Optional[InitialConditions]
57
- model: Union[SynthesisModel, ExecutionModel]
57
+ data: GeneratedCircuitData
58
+ model: SynthesisModel
59
+ transpiled_circuit: Optional[TranspiledCircuitData]
60
+ creation_time: str = pydantic.Field(default_factory=datetime.utcnow().isoformat)
61
+ synthesis_duration: Optional[SynthesisStepDurations]
62
+ debug_info: Optional[List[FunctionDebugInfo]]
63
+ program_id: str = pydantic.Field(default_factory=get_uuid_as_str)
58
64
 
59
65
  def _hardware_agnostic_program_code(self) -> CodeAndSyntax:
60
66
  circuit_code = self.program_circuit.get_code_by_priority()
@@ -128,41 +134,6 @@ class GeneratedCircuitBase(abc.ABC, VersionedModel, CircuitCodeInterface):
128
134
  for name, init_value in initial_values.items()
129
135
  }
130
136
 
131
- @property
132
- @abc.abstractmethod
133
- def program_circuit(self) -> CircuitCodeInterface:
134
- pass
135
-
136
- @property
137
- @abc.abstractmethod
138
- def execution_model(self) -> ExecutionModel:
139
- pass
140
-
141
-
142
- class ExecutionCircuit(GeneratedCircuitBase):
143
- circuit_type: Literal["execution"] = get_discriminator_field("execution")
144
- data: ExecutionCircuitData
145
- model: ExecutionModel
146
- arithmetic_outputs: ArithmeticIODict = dict()
147
-
148
- @property
149
- def program_circuit(self) -> CircuitCodeInterface:
150
- return self
151
-
152
- @property
153
- def execution_model(self) -> ExecutionModel:
154
- return self.model
155
-
156
-
157
- class GeneratedCircuit(GeneratedCircuitBase):
158
- circuit_type: Literal["generated"] = get_discriminator_field("generated")
159
- data: GeneratedCircuitData
160
- model: SynthesisModel
161
- transpiled_circuit: Optional[TranspiledCircuitData]
162
- creation_time: str = pydantic.Field(default_factory=datetime.utcnow().isoformat)
163
- synthesis_duration: Optional[SynthesisStepDurations]
164
- debug_info: List[FunctionDebugInfo]
165
-
166
137
  def save_results(self, filename: Optional[Union[str, Path]] = None) -> None:
167
138
  """
168
139
  Saves generated circuit results as json.
@@ -1,4 +1,4 @@
1
- from typing import Dict, List, Optional, Tuple, Union
1
+ from typing import Dict, List, Literal, Optional, Tuple, Union
2
2
 
3
3
  import pydantic
4
4
  from typing_extensions import TypeAlias
@@ -13,6 +13,22 @@ ParameterName = str
13
13
  IOQubitMapping: TypeAlias = Dict[str, Tuple[int, ...]]
14
14
 
15
15
 
16
+ CLASSIQ_HIERARCHY_SEPARATOR: Literal["."] = "."
17
+
18
+ VISUALIZATION_HIDE_LIST = [
19
+ "apply_to_all",
20
+ "repeat",
21
+ "control",
22
+ "mcx",
23
+ "iteration",
24
+ "operand",
25
+ ]
26
+
27
+
28
+ def last_name_in_call_hierarchy(name: str) -> str:
29
+ return name.split(CLASSIQ_HIERARCHY_SEPARATOR)[-1]
30
+
31
+
16
32
  class QubitMapping(pydantic.BaseModel):
17
33
  logical_inputs: IOQubitMapping = pydantic.Field(default_factory=dict)
18
34
  logical_outputs: IOQubitMapping = pydantic.Field(default_factory=dict)
@@ -59,49 +75,25 @@ class GeneratedFunction(pydantic.BaseModel):
59
75
  except KeyError:
60
76
  return None
61
77
 
78
+ @property
79
+ def should_appear_in_visualization(self) -> bool:
80
+ return all(
81
+ hide_regex not in last_name_in_call_hierarchy(self.name.lower())
82
+ for hide_regex in VISUALIZATION_HIDE_LIST
83
+ )
84
+
62
85
 
63
- class CircuitDataBase(pydantic.BaseModel):
86
+ class GeneratedCircuitData(pydantic.BaseModel):
64
87
  width: int
65
88
  circuit_parameters: List[ParameterName] = pydantic.Field(default_factory=list)
66
89
  qubit_mapping: QubitMapping = pydantic.Field(default_factory=QubitMapping)
67
90
  execution_data: Optional[ExecutionData] = pydantic.Field(default=None)
68
91
 
69
92
  @classmethod
70
- def from_empty_logic_flow(cls) -> "CircuitDataBase":
93
+ def from_empty_logic_flow(cls) -> "GeneratedCircuitData":
71
94
  return cls(width=0)
72
95
 
73
96
 
74
- class ExecutionCircuitData(CircuitDataBase):
75
- depth: Optional[int]
76
- count_ops: Optional[Dict[str, int]]
77
-
78
-
79
- class GeneratedCircuitData(CircuitDataBase):
80
- generated_functions: List[GeneratedFunction] = pydantic.Field(default_factory=list)
81
-
82
- def __len__(self) -> int:
83
- return self.generated_functions.__len__()
84
-
85
- def __iter__(self):
86
- yield from self.generated_functions
87
-
88
- def pprint(self) -> None:
89
- print("Circuit Synthesis Metrics")
90
- print(f"The circuit has {len(self.generated_functions)} functions:")
91
- for index, fm in enumerate(self.generated_functions):
92
- print(f"{index}) {fm.name}")
93
- print(
94
- f" depth: {fm.depth} ; "
95
- f"width: {fm.width} ; "
96
- f"registers: {len(fm.registers)}"
97
- )
98
- for reg_index, register in enumerate(fm.registers):
99
- print(
100
- f" {reg_index}) {register.role.value} - {register.name} ; "
101
- f"qubits: {register.qubit_indexes_absolute}"
102
- )
103
-
104
-
105
97
  class FunctionDebugInfo(pydantic.BaseModel):
106
98
  generated_function: Optional[GeneratedFunction]
107
99
  children: List[Optional["FunctionDebugInfo"]]