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

Tq bugfix #239

Merged
merged 4 commits into from
Feb 21, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/functional_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest qiskit-aer qiskit-ibmq-provider
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install flake8 pytest qiskit-aer qiskit_ibm_runtime
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ opt_einsum
pathos>=0.2.7
pylatexenc>=2.10
pyscf>=2.0.1
qiskit>=0.39.0
qiskit>=0.39.0,<1.0.0
recommonmark

scipy>=1.5.2
Expand Down
33 changes: 10 additions & 23 deletions torchquantum/util/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import torch.nn as nn
import torch.nn.functional as F
from opt_einsum import contract
from qiskit import IBMQ
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit.exceptions import QiskitError
from qiskit.providers.aer.noise.device.parameters import gate_error_values
from torchpack.utils.config import Config
Expand Down Expand Up @@ -738,7 +738,6 @@ def get_success_rate(properties, transpiled_circ):

return success_rate


def get_provider(backend_name, hub=None):
"""
Get the provider object for a specific backend from IBM Quantum.
Expand All @@ -753,13 +752,9 @@ def get_provider(backend_name, hub=None):
# mass-inst-tech-1 or MIT-1
if backend_name in ["ibmq_casablanca", "ibmq_rome", "ibmq_bogota", "ibmq_jakarta"]:
if hub == "mass" or hub is None:
provider = IBMQ.get_provider(
hub="ibm-q-research", group="mass-inst-tech-1", project="main"
)
provider = QiskitRuntimeService(channel = "ibm_quantum", instance = "ibm-q-research/mass-inst-tech-1/main")
elif hub == "mit":
provider = IBMQ.get_provider(
hub="ibm-q-research", group="MIT-1", project="main"
)
provider = QiskitRuntimeService(channel = "ibm_quantum", instance = "ibm-q-research/MIT-1/main")
else:
raise ValueError(f"not supported backend {backend_name} in hub " f"{hub}")
elif backend_name in [
Expand All @@ -769,33 +764,25 @@ def get_provider(backend_name, hub=None):
"ibmq_guadalupe",
"ibmq_montreal",
]:
provider = IBMQ.get_provider(hub="ibm-q-ornl", group="anl", project="csc428")
provider = QiskitRuntimeService(channel = "ibm_quantum", instance = "ibm-q-ornl/anl/csc428")
else:
if hub == "mass" or hub is None:
try:
provider = IBMQ.get_provider(
hub="ibm-q-research", group="mass-inst-tech-1", project="main"
)
provider = QiskitRuntimeService(channel = "ibm_quantum", instance = "ibm-q-research/mass-inst-tech-1/main")
except QiskitError:
# logger.warning(f"Cannot use MIT backend, roll back to open")
logger.warning(f"Use the open backend")
provider = IBMQ.get_provider(hub="ibm-q", group="open", project="main")
provider = QiskitRuntimeService(channel = "ibm_quantum", instance = "ibm-q/open/main")
elif hub == "mit":
provider = IBMQ.get_provider(
hub="ibm-q-research", group="MIT-1", project="main"
)
provider = QiskitRuntimeService(channel = "ibm_quantum", instance = "ibm-q-research/MIT-1/main")
else:
provider = IBMQ.get_provider(hub="ibm-q", group="open", project="main")
provider = QiskitRuntimeService(channel = "ibm_quantum", instance = "ibm-q/open/main")

return provider


def get_provider_hub_group_project(hub="ibm-q", group="open", project="main"):
provider = IBMQ.get_provider(
hub=hub,
group=group,
project=project,
)
provider = QiskitRuntimeService(channel = "ibm_quantum", instance = f"{hub}/{group}/{project}")
return provider


Expand Down Expand Up @@ -1085,4 +1072,4 @@ def clone_model(model_to_clone):#i have to note:this clone_model function was ma
state_dict_minus_shift[key] += shift_rate

gradient_of_par[idx-2] = (expectation_plus_shift - expectation_minus_shift) * 0.5
return gradient_of_par
return gradient_of_par
Loading