cirq-core 1.5.0.dev20241207174114__py3-none-any.whl → 1.5.0.dev20241209192542__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 +1 -1
- cirq/_version_test.py +1 -1
- cirq/contrib/qasm_import/_parser.py +18 -0
- cirq/contrib/qasm_import/_parser_test.py +107 -17
- {cirq_core-1.5.0.dev20241207174114.dist-info → cirq_core-1.5.0.dev20241209192542.dist-info}/METADATA +1 -1
- {cirq_core-1.5.0.dev20241207174114.dist-info → cirq_core-1.5.0.dev20241209192542.dist-info}/RECORD +9 -9
- {cirq_core-1.5.0.dev20241207174114.dist-info → cirq_core-1.5.0.dev20241209192542.dist-info}/LICENSE +0 -0
- {cirq_core-1.5.0.dev20241207174114.dist-info → cirq_core-1.5.0.dev20241209192542.dist-info}/WHEEL +0 -0
- {cirq_core-1.5.0.dev20241207174114.dist-info → cirq_core-1.5.0.dev20241209192542.dist-info}/top_level.txt +0 -0
cirq/_version.py
CHANGED
cirq/_version_test.py
CHANGED
|
@@ -243,6 +243,24 @@ class QasmParser:
|
|
|
243
243
|
'ch': QasmGateStatement(
|
|
244
244
|
qasm_gate='ch', cirq_gate=ops.ControlledGate(ops.H), num_params=0, num_args=2
|
|
245
245
|
),
|
|
246
|
+
'cu1': QasmGateStatement(
|
|
247
|
+
qasm_gate='cu1',
|
|
248
|
+
num_params=1,
|
|
249
|
+
num_args=2,
|
|
250
|
+
cirq_gate=(lambda params: ops.ControlledGate(QasmUGate(0, 0, params[0] / np.pi))),
|
|
251
|
+
),
|
|
252
|
+
'cu3': QasmGateStatement(
|
|
253
|
+
qasm_gate='cu3',
|
|
254
|
+
num_params=3,
|
|
255
|
+
num_args=2,
|
|
256
|
+
cirq_gate=(lambda params: ops.ControlledGate(QasmUGate(*[p / np.pi for p in params]))),
|
|
257
|
+
),
|
|
258
|
+
'crz': QasmGateStatement(
|
|
259
|
+
qasm_gate='crz',
|
|
260
|
+
num_params=1,
|
|
261
|
+
num_args=2,
|
|
262
|
+
cirq_gate=(lambda params: ops.ControlledGate(ops.rz(params[0]))),
|
|
263
|
+
),
|
|
246
264
|
'swap': QasmGateStatement(qasm_gate='swap', cirq_gate=ops.SWAP, num_params=0, num_args=2),
|
|
247
265
|
'cswap': QasmGateStatement(
|
|
248
266
|
qasm_gate='cswap', num_params=0, num_args=3, cirq_gate=ops.CSWAP
|
|
@@ -924,16 +924,24 @@ two_qubit_gates = [
|
|
|
924
924
|
]
|
|
925
925
|
|
|
926
926
|
|
|
927
|
+
# Mapping of two-qubit gates and `num_params`
|
|
928
|
+
two_qubit_param_gates = {
|
|
929
|
+
('cu1', cirq.ControlledGate(QasmUGate(0, 0, 0.1 / np.pi))): 1,
|
|
930
|
+
('cu3', cirq.ControlledGate(QasmUGate(0.1 / np.pi, 0.2 / np.pi, 0.3 / np.pi))): 3,
|
|
931
|
+
('crz', cirq.ControlledGate(cirq.rz(0.1))): 1,
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
|
|
927
935
|
@pytest.mark.parametrize('qasm_gate,cirq_gate', two_qubit_gates)
|
|
928
936
|
def test_two_qubit_gates(qasm_gate: str, cirq_gate: cirq.testing.TwoQubitGate):
|
|
929
937
|
qasm = f"""
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
938
|
+
OPENQASM 2.0;
|
|
939
|
+
include "qelib1.inc";
|
|
940
|
+
qreg q1[2];
|
|
941
|
+
qreg q2[2];
|
|
942
|
+
{qasm_gate} q1[0], q1[1];
|
|
943
|
+
{qasm_gate} q1, q2[0];
|
|
944
|
+
{qasm_gate} q2, q1;
|
|
937
945
|
"""
|
|
938
946
|
parser = QasmParser()
|
|
939
947
|
|
|
@@ -961,11 +969,85 @@ def test_two_qubit_gates(qasm_gate: str, cirq_gate: cirq.testing.TwoQubitGate):
|
|
|
961
969
|
assert parsed_qasm.qregs == {'q1': 2, 'q2': 2}
|
|
962
970
|
|
|
963
971
|
|
|
964
|
-
@pytest.mark.parametrize(
|
|
972
|
+
@pytest.mark.parametrize(
|
|
973
|
+
'qasm_gate,cirq_gate,num_params',
|
|
974
|
+
[
|
|
975
|
+
(gate_map[0], gate_map[1], num_param)
|
|
976
|
+
for gate_map, num_param in two_qubit_param_gates.items()
|
|
977
|
+
],
|
|
978
|
+
)
|
|
979
|
+
def test_two_qubit_param_gates(
|
|
980
|
+
qasm_gate: str, cirq_gate: cirq.testing.TwoQubitGate, num_params: int
|
|
981
|
+
):
|
|
982
|
+
params = '(0.1, 0.2, 0.3)' if num_params == 3 else '(0.1)'
|
|
983
|
+
qasm = f"""
|
|
984
|
+
OPENQASM 2.0;
|
|
985
|
+
include "qelib1.inc";
|
|
986
|
+
qreg q1[2];
|
|
987
|
+
qreg q2[2];
|
|
988
|
+
{qasm_gate}{params} q1[0], q1[1];
|
|
989
|
+
{qasm_gate}{params} q1, q2[0];
|
|
990
|
+
{qasm_gate}{params} q2, q1;
|
|
991
|
+
"""
|
|
992
|
+
parser = QasmParser()
|
|
993
|
+
|
|
994
|
+
q1_0 = cirq.NamedQubit('q1_0')
|
|
995
|
+
q1_1 = cirq.NamedQubit('q1_1')
|
|
996
|
+
q2_0 = cirq.NamedQubit('q2_0')
|
|
997
|
+
q2_1 = cirq.NamedQubit('q2_1')
|
|
998
|
+
|
|
999
|
+
expected_circuit = cirq.Circuit()
|
|
1000
|
+
expected_circuit.append(cirq_gate.on(q1_0, q1_1))
|
|
1001
|
+
expected_circuit.append(cirq_gate.on(q1_0, q2_0))
|
|
1002
|
+
expected_circuit.append(cirq_gate.on(q1_1, q2_0))
|
|
1003
|
+
expected_circuit.append(cirq_gate.on(q2_0, q1_0))
|
|
1004
|
+
expected_circuit.append(cirq_gate.on(q2_1, q1_1))
|
|
1005
|
+
parsed_qasm = parser.parse(qasm)
|
|
1006
|
+
|
|
1007
|
+
assert parsed_qasm.supportedFormat
|
|
1008
|
+
assert parsed_qasm.qelib1Include
|
|
1009
|
+
|
|
1010
|
+
ct.assert_same_circuits(parsed_qasm.circuit, expected_circuit)
|
|
1011
|
+
assert parsed_qasm.qregs == {'q1': 2, 'q2': 2}
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
@pytest.mark.parametrize(
|
|
1015
|
+
'qasm_gate', [g[0] for g in two_qubit_gates] + [g[0] for g in two_qubit_param_gates.keys()]
|
|
1016
|
+
)
|
|
1017
|
+
def test_two_qubit_gates_not_enough_qubits(qasm_gate: str):
|
|
1018
|
+
if qasm_gate in ('cu1', 'crz'):
|
|
1019
|
+
qasm = f"""
|
|
1020
|
+
OPENQASM 2.0;
|
|
1021
|
+
include "qelib1.inc";
|
|
1022
|
+
qreg q[2];
|
|
1023
|
+
{qasm_gate}(0.1) q[0];
|
|
1024
|
+
"""
|
|
1025
|
+
elif qasm_gate == 'cu3':
|
|
1026
|
+
qasm = f"""
|
|
1027
|
+
OPENQASM 2.0;
|
|
1028
|
+
include "qelib1.inc";
|
|
1029
|
+
qreg q[2];
|
|
1030
|
+
{qasm_gate}(0.1, 0.2, 0.3) q[0];
|
|
1031
|
+
"""
|
|
1032
|
+
else:
|
|
1033
|
+
qasm = f"""
|
|
1034
|
+
OPENQASM 2.0;
|
|
1035
|
+
include "qelib1.inc";
|
|
1036
|
+
qreg q[2];
|
|
1037
|
+
{qasm_gate} q[0];
|
|
1038
|
+
"""
|
|
1039
|
+
|
|
1040
|
+
parser = QasmParser()
|
|
1041
|
+
|
|
1042
|
+
with pytest.raises(QasmException, match=rf".*{qasm_gate}.* takes 2 arg\(s\).*got.*1.*line 5"):
|
|
1043
|
+
parser.parse(qasm)
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
@pytest.mark.parametrize('qasm_gate', [g[0] for g in two_qubit_param_gates.keys()])
|
|
965
1047
|
def test_two_qubit_gates_not_enough_args(qasm_gate: str):
|
|
966
1048
|
qasm = f"""
|
|
967
|
-
OPENQASM 2.0;
|
|
968
|
-
include "qelib1.inc";
|
|
1049
|
+
OPENQASM 2.0;
|
|
1050
|
+
include "qelib1.inc";
|
|
969
1051
|
qreg q[2];
|
|
970
1052
|
{qasm_gate} q[0];
|
|
971
1053
|
"""
|
|
@@ -976,19 +1058,27 @@ def test_two_qubit_gates_not_enough_args(qasm_gate: str):
|
|
|
976
1058
|
parser.parse(qasm)
|
|
977
1059
|
|
|
978
1060
|
|
|
979
|
-
@pytest.mark.parametrize(
|
|
1061
|
+
@pytest.mark.parametrize(
|
|
1062
|
+
'qasm_gate', [g[0] for g in two_qubit_gates] + [g[0] for g in two_qubit_param_gates.keys()]
|
|
1063
|
+
)
|
|
980
1064
|
def test_two_qubit_gates_with_too_much_parameters(qasm_gate: str):
|
|
1065
|
+
if qasm_gate in ('cu1', 'cu3', 'crz'):
|
|
1066
|
+
num_params_needed = 3 if qasm_gate == 'cu3' else 1
|
|
1067
|
+
else:
|
|
1068
|
+
num_params_needed = 0
|
|
1069
|
+
|
|
981
1070
|
qasm = f"""
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
"""
|
|
1071
|
+
OPENQASM 2.0;
|
|
1072
|
+
include "qelib1.inc";
|
|
1073
|
+
qreg q[2];
|
|
1074
|
+
{qasm_gate}(pi, pi/2, pi/3, pi/4) q[0],q[1];
|
|
1075
|
+
"""
|
|
987
1076
|
|
|
988
1077
|
parser = QasmParser()
|
|
989
1078
|
|
|
990
1079
|
with pytest.raises(
|
|
991
|
-
QasmException,
|
|
1080
|
+
QasmException,
|
|
1081
|
+
match=rf".*{qasm_gate}*. takes {num_params_needed} parameter\(s\).*got.*4.*line 5",
|
|
992
1082
|
):
|
|
993
1083
|
parser.parse(qasm)
|
|
994
1084
|
|
{cirq_core-1.5.0.dev20241207174114.dist-info → cirq_core-1.5.0.dev20241209192542.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.5.0.
|
|
3
|
+
Version: 1.5.0.dev20241209192542
|
|
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
|
{cirq_core-1.5.0.dev20241207174114.dist-info → cirq_core-1.5.0.dev20241209192542.dist-info}/RECORD
RENAMED
|
@@ -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=
|
|
8
|
-
cirq/_version_test.py,sha256=
|
|
7
|
+
cirq/_version.py,sha256=oixWi6sQgXRWW0C2yWJvKmlxsHZd1zBeIcVaNAzG5KU,1206
|
|
8
|
+
cirq/_version_test.py,sha256=cZzmqjzEi-UgTZ8_h7wOX7aNBzAmNTCsR303SwiVtVA,147
|
|
9
9
|
cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
|
|
10
10
|
cirq/json_resolver_cache.py,sha256=03MVo6Y-UYrzt9CKHmwpiBLN2ixL6uSU-OWnKZXfG7k,13302
|
|
11
11
|
cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
|
|
@@ -105,8 +105,8 @@ cirq/contrib/paulistring/separate_test.py,sha256=FzR78MSHDhNJxizbXreK6u3BeYhT7xn
|
|
|
105
105
|
cirq/contrib/qasm_import/__init__.py,sha256=RKX0vGDC2Pe5rH5rM4ClXdvtrAU16ePFImQpiJtJVNo,744
|
|
106
106
|
cirq/contrib/qasm_import/_lexer.py,sha256=J0ExK_6VGMoql0ha0hrxHzbFuqFYazHSSruhgznI66Y,3366
|
|
107
107
|
cirq/contrib/qasm_import/_lexer_test.py,sha256=iiz-cmIt5hnhHBc4ub4btqHnbi4EPaO7BE7bsJKPet8,4142
|
|
108
|
-
cirq/contrib/qasm_import/_parser.py,sha256=
|
|
109
|
-
cirq/contrib/qasm_import/_parser_test.py,sha256=
|
|
108
|
+
cirq/contrib/qasm_import/_parser.py,sha256=JroR-z7EcUhVd2-556h007H7SnzmmbqM4tsSOwsvwNw,21061
|
|
109
|
+
cirq/contrib/qasm_import/_parser_test.py,sha256=EliIovGMcHYxgyxm12D41dN7LCM4oBL1okhSsUw0BzM,31706
|
|
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
|
|
@@ -1189,8 +1189,8 @@ cirq/work/sampler.py,sha256=bE5tmVkcR6cZZMLETxDfHehdsYUMbx2RvBeIBetehI4,19187
|
|
|
1189
1189
|
cirq/work/sampler_test.py,sha256=hL2UWx3dz2ukZVNxWftiKVvJcQoLplLZdQm-k1QcA40,13282
|
|
1190
1190
|
cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
|
|
1191
1191
|
cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
|
|
1192
|
-
cirq_core-1.5.0.
|
|
1193
|
-
cirq_core-1.5.0.
|
|
1194
|
-
cirq_core-1.5.0.
|
|
1195
|
-
cirq_core-1.5.0.
|
|
1196
|
-
cirq_core-1.5.0.
|
|
1192
|
+
cirq_core-1.5.0.dev20241209192542.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
1193
|
+
cirq_core-1.5.0.dev20241209192542.dist-info/METADATA,sha256=fwCbJHlnyj84m62Ft8iabnsYuC3NeRYdFzpZsS-53Is,1992
|
|
1194
|
+
cirq_core-1.5.0.dev20241209192542.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
1195
|
+
cirq_core-1.5.0.dev20241209192542.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
|
|
1196
|
+
cirq_core-1.5.0.dev20241209192542.dist-info/RECORD,,
|
{cirq_core-1.5.0.dev20241207174114.dist-info → cirq_core-1.5.0.dev20241209192542.dist-info}/LICENSE
RENAMED
|
File without changes
|
{cirq_core-1.5.0.dev20241207174114.dist-info → cirq_core-1.5.0.dev20241209192542.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|