cirq-core 1.5.0.dev20241120181130__py3-none-any.whl → 1.5.0.dev20241120233534__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.

Potentially problematic release.


This version of cirq-core might be problematic. Click here for more details.

cirq/_version.py CHANGED
@@ -28,4 +28,4 @@ if sys.version_info < (3, 10, 0): # pragma: no cover
28
28
  'of cirq (e.g. "python -m pip install cirq==1.1.*")'
29
29
  )
30
30
 
31
- __version__ = "1.5.0.dev20241120181130"
31
+ __version__ = "1.5.0.dev20241120233534"
cirq/_version_test.py CHANGED
@@ -3,4 +3,4 @@ import cirq
3
3
 
4
4
 
5
5
  def test_version():
6
- assert cirq.__version__ == "1.5.0.dev20241120181130"
6
+ assert cirq.__version__ == "1.5.0.dev20241120233534"
cirq/protocols/qasm.py CHANGED
@@ -55,14 +55,23 @@ class QasmArgs(string.Formatter):
55
55
  self.qubit_id_map = {} if qubit_id_map is None else qubit_id_map
56
56
  self.meas_key_id_map = {} if meas_key_id_map is None else meas_key_id_map
57
57
 
58
+ def _format_number(self, value) -> str:
59
+ """OpenQASM 2.0 does not support '1e-5' and wants '1.0e-5'"""
60
+ s = f'{value}'
61
+ if 'e' in s and not '.' in s:
62
+ return s.replace('e', '.0e')
63
+ return s
64
+
58
65
  def format_field(self, value: Any, spec: str) -> str:
59
66
  """Method of string.Formatter that specifies the output of format()."""
60
67
  if isinstance(value, (float, int)):
61
68
  if isinstance(value, float):
62
69
  value = round(value, self.precision)
63
70
  if spec == 'half_turns':
64
- value = f'pi*{value}' if value != 0 else '0'
71
+ value = f'pi*{self._format_number(value)}' if value != 0 else '0'
65
72
  spec = ''
73
+ else:
74
+ value = self._format_number(value)
66
75
  elif isinstance(value, ops.Qid):
67
76
  value = self.qubit_id_map[value]
68
77
  elif isinstance(value, str) and spec == 'meas':
@@ -52,3 +52,15 @@ def test_qasm():
52
52
 
53
53
  assert cirq.qasm(ExpectsArgs(), args=cirq.QasmArgs()) == 'text'
54
54
  assert cirq.qasm(ExpectsArgsQubits(), args=cirq.QasmArgs(), qubits=()) == 'text'
55
+
56
+
57
+ def test_qasm_args_formatting():
58
+ args = cirq.QasmArgs()
59
+ assert args.format_field(0.01, '') == '0.01'
60
+ assert args.format_field(0.01, 'half_turns') == 'pi*0.01'
61
+ assert args.format_field(0.00001, '') == '1.0e-05'
62
+ assert args.format_field(0.00001, 'half_turns') == 'pi*1.0e-05'
63
+ assert args.format_field(1e-10, 'half_turns') == 'pi*1.0e-10'
64
+ args = cirq.QasmArgs(precision=6)
65
+ assert args.format_field(0.00001234, '') == '1.2e-05'
66
+ assert args.format_field(0.00001234, 'half_turns') == 'pi*1.2e-05'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.5.0.dev20241120181130
3
+ Version: 1.5.0.dev20241120233534
4
4
  Summary: A framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
5
5
  Home-page: http://github.com/quantumlib/cirq
6
6
  Author: The Cirq Developers
@@ -4,8 +4,8 @@ cirq/_compat_test.py,sha256=Qq3ZcfgD-Nb81cEppQdJqhAyrVqXKtfXZYGXT0p-Wh0,34718
4
4
  cirq/_doc.py,sha256=yDyWUD_2JDS0gShfGRb-rdqRt9-WeL7DhkqX7np0Nko,2879
5
5
  cirq/_import.py,sha256=p9gMHJscbtDDkfHOaulvd3Aer0pwUF5AXpL89XR8dNw,8402
6
6
  cirq/_import_test.py,sha256=6K_v0riZJXOXUphHNkGA8MY-JcmGlezFaGmvrNhm3OQ,1015
7
- cirq/_version.py,sha256=2OWqbmzoA46VRJQ_rQM1qc8-NPDWvmZUNF4rMuEp-Ho,1206
8
- cirq/_version_test.py,sha256=AnC_NkSCz67ZzrvoWslWbEUWf_8sw8tZ2Uc8siHDEBE,147
7
+ cirq/_version.py,sha256=Vpw7ogLDvHEtwUmt0PWS86YxwvfTBHzf2H5ozGsjGX4,1206
8
+ cirq/_version_test.py,sha256=98FHCYSWpiencHGZFgwAHsrlf12_WFY-XR69vsgHreI,147
9
9
  cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
10
10
  cirq/json_resolver_cache.py,sha256=ytePZtNZgKjOF2NiVpUTuotB-JKZmQNOFIFdvXqsxHw,13271
11
11
  cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
@@ -419,8 +419,8 @@ cirq/protocols/phase_protocol.py,sha256=dXZRJb7aT8ZvtliItZOvoiaev-QvjBT4SknwZ5p-
419
419
  cirq/protocols/phase_protocol_test.py,sha256=eU4g6VDqfWZCpklVlY1t5msc5kAZsP-UlPrROLll_ms,1939
420
420
  cirq/protocols/pow_protocol.py,sha256=0wgb4LLAkOWjmP_u-_6IweXovDViocbdSgtsMOcXdkM,3290
421
421
  cirq/protocols/pow_protocol_test.py,sha256=8eBcGUqRWSSYkEkvSHXL6tcv1o-ilnl6nzgNl9vfctg,1626
422
- cirq/protocols/qasm.py,sha256=D55dieASN2PEPHsa8vSeUkaswzsuBTLHA0vM2_wqN6Y,6545
423
- cirq/protocols/qasm_test.py,sha256=FxMs2PKJEi5Y2XIDuXZKN1HJd0zgTqSuv8BQaudKwUw,1484
422
+ cirq/protocols/qasm.py,sha256=ekPlvfHIz9PUPdLeO7P_KMRuAh0rngM7r5grmW3kdWM,6869
423
+ cirq/protocols/qasm_test.py,sha256=MFkqSHByCbB46XOlAJgKQgEpANVwnmfO-tD-XofqrQ4,2013
424
424
  cirq/protocols/qid_shape_protocol.py,sha256=jCAdpBBkEyK6JGmZwVBp__lHW3JhLmYt0Qzf8OgZtNU,7690
425
425
  cirq/protocols/qid_shape_protocol_test.py,sha256=Qjo-wemjkP__1jQnVkkB91mUs8EpfXyKI9GzeZQVb1E,2303
426
426
  cirq/protocols/resolve_parameters.py,sha256=NVFS5PSq18Hcvjv_P6vaZIa2D4OCgZY1u5j6QgPMlTA,7374
@@ -1187,8 +1187,8 @@ cirq/work/sampler.py,sha256=y6qtCpAwO8SqZ_JKU8PwlbMLHpJskNPqGWD_pNbyZew,19779
1187
1187
  cirq/work/sampler_test.py,sha256=hL2UWx3dz2ukZVNxWftiKVvJcQoLplLZdQm-k1QcA40,13282
1188
1188
  cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
1189
1189
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1190
- cirq_core-1.5.0.dev20241120181130.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1191
- cirq_core-1.5.0.dev20241120181130.dist-info/METADATA,sha256=_6hfBHZQ9TowgdKEolGxgbVkVpsosrBA17nNJsCGl9E,1992
1192
- cirq_core-1.5.0.dev20241120181130.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
1193
- cirq_core-1.5.0.dev20241120181130.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1194
- cirq_core-1.5.0.dev20241120181130.dist-info/RECORD,,
1190
+ cirq_core-1.5.0.dev20241120233534.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1191
+ cirq_core-1.5.0.dev20241120233534.dist-info/METADATA,sha256=1-jjDNKO-NFEVTOQY2DZbUf27V0_P5XX9JMubj1miv8,1992
1192
+ cirq_core-1.5.0.dev20241120233534.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
1193
+ cirq_core-1.5.0.dev20241120233534.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1194
+ cirq_core-1.5.0.dev20241120233534.dist-info/RECORD,,