Skip to content

Commit

Permalink
Merge branch 'main' into add-get-circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
bharat-thotakura authored Oct 12, 2023
2 parents 994d9f9 + 2c9435d commit fab0cdc
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 21 deletions.
16 changes: 0 additions & 16 deletions cirq-superstaq/cirq_superstaq/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,22 +388,6 @@ def get_job(self, job_id: str) -> css.job.Job:
"""
return css.job.Job(client=self._client, job_id=job_id)

def get_balance(self, pretty_output: bool = True) -> Union[str, float]:
"""Get the querying user's account balance in USD.
Args:
pretty_output: Whether to return a pretty string or a float of the balance.
Returns:
If `pretty_output` is `True`, returns the balance as a nicely formatted string
($-prefix, commas on LHS every three digits, and two digits after period). Otherwise,
simply returns a float of the balance.
"""
balance = self._client.get_balance()["balance"]
if pretty_output:
return f"${balance:,.2f}"
return balance

def get_targets(self) -> Dict[str, List[str]]:
"""Gets a list of available, unavailable, and retired targets.
Expand Down
2 changes: 1 addition & 1 deletion cirq-superstaq/cirq_superstaq/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_service_get_balance() -> None:
mock_client.get_balance.return_value = {"balance": 12345.6789}
service._client = mock_client

assert service.get_balance() == "$12,345.68"
assert service.get_balance() == "12,345.68 credits"
assert service.get_balance(pretty_output=False) == 12345.6789


Expand Down
2 changes: 1 addition & 1 deletion general-superstaq/general_superstaq/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_balance(self, pretty_output: bool = True) -> Union[str, float]:

balance = self._client.get_balance()["balance"]
if pretty_output:
return f"${balance:,.2f}"
return f"{balance:,.2f} credits"
return balance

def _accept_terms_of_use(self, user_input: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion general-superstaq/general_superstaq/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_service_get_balance() -> None:
mock_client.get_balance.return_value = {"balance": 12345.6789}
service._client = mock_client

assert service.get_balance() == "$12,345.68"
assert service.get_balance() == "12,345.68 credits"
assert service.get_balance(pretty_output=False) == 12345.6789


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_aqt_compile_eca_regression(provider: qss.SuperstaqProvider) -> None:
def test_get_balance(provider: qss.SuperstaqProvider) -> None:
balance_str = provider.get_balance()
assert isinstance(balance_str, str)
assert balance_str.startswith("$")
assert balance_str.endswith("credits")

assert isinstance(provider.get_balance(pretty_output=False), float)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_get_balance() -> None:
mock_client.get_balance.return_value = {"balance": 12345.6789}
ss_provider._client = mock_client

assert ss_provider.get_balance() == "$12,345.68"
assert ss_provider.get_balance() == "12,345.68 credits"
assert ss_provider.get_balance(pretty_output=False) == 12345.6789


Expand Down

0 comments on commit fab0cdc

Please sign in to comment.