Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix passing of dd_strategy kwargs in compile #824

Merged
merged 8 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cirq-superstaq/cirq_superstaq/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,9 @@ def ibmq_compile(
if not target.startswith("ibmq_"):
raise ValueError(f"{target!r} is not a valid IBMQ target.")

options = {"dynamical_decoupling": dynamical_decoupling, "dd_strategy": dd_strategy}
kwargs.update(options)

return self.compile(circuits, target=target, **kwargs)

def compile(
Expand Down
11 changes: 10 additions & 1 deletion cirq-superstaq/cirq_superstaq/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,16 @@ def test_service_ibmq_compile(mock_post: mock.MagicMock) -> None:
"final_logical_to_physicals": cirq.to_json([list(final_logical_to_physical.items())]),
}

assert service.ibmq_compile(circuit, test_options="yes").circuit == circuit
assert (
service.ibmq_compile(circuit, dd_strategy="dynamic", test_options="yes").circuit == circuit
)

assert json.loads(mock_post.call_args.kwargs["json"]["options"]) == {
"dd_strategy": "dynamic",
"dynamical_decoupling": True,
"test_options": "yes",
}

assert service.ibmq_compile([circuit]).circuits == [circuit]
assert service.ibmq_compile(circuit).pulse_sequence == mock.DEFAULT
assert service.ibmq_compile([circuit]).pulse_sequences == [mock.DEFAULT]
Expand Down
1 change: 1 addition & 0 deletions qiskit-superstaq/qiskit_superstaq/superstaq_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def ibmq_compile(
options: Dict[str, Any] = {**kwargs}

options["dynamical_decoupling"] = dynamical_decoupling
options["dd_strategy"] = dd_strategy
request_json = self._get_compile_request_json(circuits, **options)
circuits_is_list = not isinstance(circuits, qiskit.QuantumCircuit)
json_dict = self._provider._client.compile(request_json)
Expand Down
9 changes: 8 additions & 1 deletion qiskit-superstaq/qiskit_superstaq/superstaq_backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,15 @@ def test_ibmq_compile(mock_post: MagicMock) -> None:
"pulses": gss.serialization.serialize([DEFAULT]),
}
assert backend.compile(
qiskit.QuantumCircuit(), test_options="yes"
qiskit.QuantumCircuit(), dd_strategy="static", test_options="yes"
) == qss.compiler_output.CompilerOutput(qc, final_logical_to_physical, pulse_sequences=DEFAULT)

assert json.loads(mock_post.call_args.kwargs["json"]["options"]) == {
"dd_strategy": "static",
"dynamical_decoupling": True,
"test_options": "yes",
}

assert backend.compile([qiskit.QuantumCircuit()]) == qss.compiler_output.CompilerOutput(
[qc], [final_logical_to_physical], pulse_sequences=[DEFAULT]
)
Expand Down
3 changes: 3 additions & 0 deletions qiskit-superstaq/qiskit_superstaq/superstaq_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ def ibmq_compile(
if not target.startswith("ibmq_"):
raise ValueError(f"{target!r} is not a valid IBMQ target.")

options = {"dynamical_decoupling": dynamical_decoupling, "dd_strategy": dd_strategy}
kwargs.update(options)

return self.get_backend(target).compile(circuits, **kwargs)

def qscout_compile(
Expand Down
9 changes: 9 additions & 0 deletions qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ def test_ibmq_compile(mock_post: MagicMock, fake_superstaq_provider: MockSuperst
[qiskit.QuantumCircuit()]
) == qss.compiler_output.CompilerOutput([qc], [final_logical_to_physical], pulse_sequences=None)

assert fake_superstaq_provider.ibmq_compile(
qiskit.QuantumCircuit(), dd_strategy="static", test_options="yes"
) == qss.compiler_output.CompilerOutput(qc, final_logical_to_physical, pulse_sequences=None)
assert json.loads(mock_post.call_args.kwargs["json"]["options"]) == {
"dd_strategy": "static",
"dynamical_decoupling": True,
"test_options": "yes",
}


def test_invalid_target_ibmq_compile() -> None:
provider = qss.SuperstaqProvider(api_key="MY_TOKEN")
Expand Down