cirq-core 1.5.0.dev20241120163208__py3-none-any.whl → 1.5.0.dev20241120181130__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.dev20241120163208"
31
+ __version__ = "1.5.0.dev20241120181130"
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.dev20241120163208"
6
+ assert cirq.__version__ == "1.5.0.dev20241120181130"
@@ -24,10 +24,12 @@ class QasmLexer:
24
24
  def __init__(self):
25
25
  self.lex = lex.lex(object=self, debug=False)
26
26
 
27
- literals = "{}[]();,+/*-^"
27
+ literals = "{}[]();,+/*-^="
28
28
 
29
29
  reserved = {
30
+ 'qubit': 'QUBIT',
30
31
  'qreg': 'QREG',
32
+ 'bit': 'BIT',
31
33
  'creg': 'CREG',
32
34
  'measure': 'MEASURE',
33
35
  'if': 'IF',
@@ -35,9 +37,15 @@ class QasmLexer:
35
37
  '==': 'EQ',
36
38
  }
37
39
 
38
- tokens = ['FORMAT_SPEC', 'NUMBER', 'NATURAL_NUMBER', 'QELIBINC', 'ID', 'PI'] + list(
39
- reserved.values()
40
- )
40
+ tokens = [
41
+ 'FORMAT_SPEC',
42
+ 'NUMBER',
43
+ 'NATURAL_NUMBER',
44
+ 'STDGATESINC',
45
+ 'QELIBINC',
46
+ 'ID',
47
+ 'PI',
48
+ ] + list(reserved.values())
41
49
 
42
50
  def t_newline(self, t):
43
51
  r"""\n+"""
@@ -83,14 +91,26 @@ class QasmLexer:
83
91
  r"""include(\s+)"qelib1.inc";"""
84
92
  return t
85
93
 
94
+ def t_STDGATESINC(self, t):
95
+ r"""include(\s+)"stdgates.inc";"""
96
+ return t
97
+
86
98
  def t_QREG(self, t):
87
99
  r"""qreg"""
88
100
  return t
89
101
 
102
+ def t_QUBIT(self, t):
103
+ r"""qubit"""
104
+ return t
105
+
90
106
  def t_CREG(self, t):
91
107
  r"""creg"""
92
108
  return t
93
109
 
110
+ def t_BIT(self, t):
111
+ r"""bit"""
112
+ return t
113
+
94
114
  def t_MEASURE(self, t):
95
115
  r"""measure"""
96
116
  return t
@@ -270,6 +270,7 @@ class QasmParser:
270
270
 
271
271
  def p_qasm_no_format_specified_error(self, p):
272
272
  """qasm : QELIBINC
273
+ | STDGATESINC
273
274
  | circuit"""
274
275
  if self.supported_format is False:
275
276
  raise QasmException("Missing 'OPENQASM 2.0;' statement")
@@ -279,15 +280,21 @@ class QasmParser:
279
280
  self.qelibinc = True
280
281
  p[0] = Qasm(self.supported_format, self.qelibinc, self.qregs, self.cregs, self.circuit)
281
282
 
283
+ def p_qasm_include_stdgates(self, p):
284
+ """qasm : qasm STDGATESINC"""
285
+ self.qelibinc = True
286
+ p[0] = Qasm(self.supported_format, self.qelibinc, self.qregs, self.cregs, self.circuit)
287
+
282
288
  def p_qasm_circuit(self, p):
283
289
  """qasm : qasm circuit"""
284
290
  p[0] = Qasm(self.supported_format, self.qelibinc, self.qregs, self.cregs, p[2])
285
291
 
286
292
  def p_format(self, p):
287
293
  """format : FORMAT_SPEC"""
288
- if p[1] != "2.0":
294
+ if p[1] not in ["2.0", "3.0"]:
289
295
  raise QasmException(
290
- f"Unsupported OpenQASM version: {p[1]}, only 2.0 is supported currently by Cirq"
296
+ f"Unsupported OpenQASM version: {p[1]}, "
297
+ "only 2.0 and 3.0 are supported currently by Cirq"
291
298
  )
292
299
 
293
300
  # circuit : new_reg circuit
@@ -315,13 +322,28 @@ class QasmParser:
315
322
 
316
323
  def p_new_reg(self, p):
317
324
  """new_reg : QREG ID '[' NATURAL_NUMBER ']' ';'
318
- | CREG ID '[' NATURAL_NUMBER ']' ';'"""
319
- name, length = p[2], p[4]
325
+ | QUBIT '[' NATURAL_NUMBER ']' ID ';'
326
+ | QUBIT ID ';'
327
+ | CREG ID '[' NATURAL_NUMBER ']' ';'
328
+ | BIT '[' NATURAL_NUMBER ']' ID ';'
329
+ | BIT ID ';'
330
+ """
331
+ if p[1] == "qreg" or p[1] == "creg":
332
+ # QREG ID '[' NATURAL_NUMBER ']' ';'
333
+ name, length = p[2], p[4]
334
+ else:
335
+ if len(p) < 5:
336
+ # QUBIT ID ';' | BIT ID ';'
337
+ name = p[2]
338
+ length = 1
339
+ else:
340
+ # QUBIT '[' NATURAL_NUMBER ']' ID ';'
341
+ name, length = p[5], p[3]
320
342
  if name in self.qregs.keys() or name in self.cregs.keys():
321
343
  raise QasmException(f"{name} is already defined at line {p.lineno(2)}")
322
344
  if length == 0:
323
345
  raise QasmException(f"Illegal, zero-length register '{name}' at line {p.lineno(4)}")
324
- if p[1] == "qreg":
346
+ if p[1] == "qreg" or p[1] == "qubit":
325
347
  self.qregs[name] = length
326
348
  else:
327
349
  self.cregs[name] = length
@@ -485,9 +507,14 @@ class QasmParser:
485
507
  # measurement : MEASURE qarg ARROW carg
486
508
 
487
509
  def p_measurement(self, p):
488
- """measurement : MEASURE qarg ARROW carg ';'"""
489
- qreg = p[2]
490
- creg = p[4]
510
+ """measurement : MEASURE qarg ARROW carg ';'
511
+ | carg '=' MEASURE qarg ';'"""
512
+ if p[1] == 'measure':
513
+ qreg = p[2]
514
+ creg = p[4]
515
+ else:
516
+ qreg = p[4]
517
+ creg = p[1]
491
518
 
492
519
  if len(qreg) != len(creg):
493
520
  raise QasmException(
@@ -1057,3 +1057,51 @@ def test_single_qubit_gates(qasm_gate: str, cirq_gate: cirq.Gate):
1057
1057
 
1058
1058
  ct.assert_same_circuits(parsed_qasm.circuit, expected_circuit)
1059
1059
  assert parsed_qasm.qregs == {'q': 2}
1060
+
1061
+
1062
+ def test_openqasm_3_0_qubits():
1063
+ qasm = """OPENQASM 3.0;
1064
+ include "stdgates.inc";
1065
+ qubit[2] q;
1066
+ bit[2] b;
1067
+
1068
+ x q[0];
1069
+
1070
+ b[0] = measure q[0];
1071
+ """
1072
+ parser = QasmParser()
1073
+
1074
+ q0 = cirq.NamedQubit('q_0')
1075
+
1076
+ expected_circuit = Circuit([cirq.X.on(q0), cirq.measure(q0, key='b_0')])
1077
+
1078
+ parsed_qasm = parser.parse(qasm)
1079
+
1080
+ assert parsed_qasm.supportedFormat
1081
+
1082
+ ct.assert_same_circuits(parsed_qasm.circuit, expected_circuit)
1083
+ assert parsed_qasm.qregs == {'q': 2}
1084
+
1085
+
1086
+ def test_openqasm_3_0_scalar_qubit():
1087
+ qasm = """OPENQASM 3.0;
1088
+ include "stdgates.inc";
1089
+ qubit q;
1090
+ bit b;
1091
+
1092
+ x q;
1093
+
1094
+ b = measure q;
1095
+ """
1096
+ parser = QasmParser()
1097
+
1098
+ q0 = cirq.NamedQubit('q_0')
1099
+
1100
+ expected_circuit = Circuit([cirq.X.on(q0), cirq.measure(q0, key='b_0')])
1101
+
1102
+ parsed_qasm = parser.parse(qasm)
1103
+
1104
+ assert parsed_qasm.supportedFormat
1105
+
1106
+ ct.assert_same_circuits(parsed_qasm.circuit, expected_circuit)
1107
+ assert parsed_qasm.qregs == {'q': 1}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.5.0.dev20241120163208
3
+ Version: 1.5.0.dev20241120181130
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=QIb3tuB9AIOt1ws8jRDyC8bOA-JqqF5WwvE4ezZjV1o,1206
8
- cirq/_version_test.py,sha256=xq54nxrTncU1OKYghtg2oxLQJn2tg-NwfqCpNzJRcSs,147
7
+ cirq/_version.py,sha256=2OWqbmzoA46VRJQ_rQM1qc8-NPDWvmZUNF4rMuEp-Ho,1206
8
+ cirq/_version_test.py,sha256=AnC_NkSCz67ZzrvoWslWbEUWf_8sw8tZ2Uc8siHDEBE,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
@@ -103,10 +103,10 @@ cirq/contrib/paulistring/recombine_test.py,sha256=hJ083nR67JsIs38TfmCjmBLnhqyG0r
103
103
  cirq/contrib/paulistring/separate.py,sha256=2g4l78mXYJDR6xkv51VExZDb-rm5JEvhYrpMPgWa0Us,3961
104
104
  cirq/contrib/paulistring/separate_test.py,sha256=FzR78MSHDhNJxizbXreK6u3BeYhT7xn7W1QyHfEZ34E,1267
105
105
  cirq/contrib/qasm_import/__init__.py,sha256=RKX0vGDC2Pe5rH5rM4ClXdvtrAU16ePFImQpiJtJVNo,744
106
- cirq/contrib/qasm_import/_lexer.py,sha256=busw1Td1pJR-MBNGW-km1i9t2XKEqZTZ3zJnG6vXkmA,2943
106
+ cirq/contrib/qasm_import/_lexer.py,sha256=1BGtCS2RetdiYPNOe_ZnMeoEl-AVBvvee_7y-h8tYcE,3275
107
107
  cirq/contrib/qasm_import/_lexer_test.py,sha256=iiz-cmIt5hnhHBc4ub4btqHnbi4EPaO7BE7bsJKPet8,4142
108
- cirq/contrib/qasm_import/_parser.py,sha256=qaFAAmHgSqTwcFgzLCYp-tM-UHcdEVlQ3fJSkwQjPdo,19234
109
- cirq/contrib/qasm_import/_parser_test.py,sha256=WEP1xp7IPeXRmRlQn48OHZoQtkSyW5VVSDEFT-C_ae0,27391
108
+ cirq/contrib/qasm_import/_parser.py,sha256=e9ztG69dYm8dewM6efizbMT-Mf1n88hffg4ToBu0pig,20153
109
+ cirq/contrib/qasm_import/_parser_test.py,sha256=2XEfhoiHWDpnGh3yYrenekGTIYapDtf52AMzYulajRY,28374
110
110
  cirq/contrib/qasm_import/exception.py,sha256=Wm6cwUPIkNMPjkv-ELpQ-zSoXaiLOddOQ4iYybwuS6I,695
111
111
  cirq/contrib/qasm_import/qasm.py,sha256=CP444IWCw4zlDNA7HxsTJ2xIak4mZhQv62ZiLlUc2zo,914
112
112
  cirq/contrib/qasm_import/qasm_test.py,sha256=e5b7LVn_6FIFZ6kINqMzJFIjzgtTgutVhgXgX_DcTc0,1861
@@ -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.dev20241120163208.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1191
- cirq_core-1.5.0.dev20241120163208.dist-info/METADATA,sha256=qflTCIVln0_4cA3bMs9u6lHgJXCJ9MsNe7eXBhCHWa0,1992
1192
- cirq_core-1.5.0.dev20241120163208.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
1193
- cirq_core-1.5.0.dev20241120163208.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1194
- cirq_core-1.5.0.dev20241120163208.dist-info/RECORD,,
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,,