azure-quantum-python icon indicating copy to clipboard operation
azure-quantum-python copied to clipboard

Azure-quantum authentication is near to impossible with EnvironmentCredential

Open SagarDollin opened this issue 2 years ago • 0 comments

The code below to solve a simple problem on azure quantum never works. Microsoft, please help me with authentication.

from azure.quantum.optimization import Problem, ProblemType, Term
from typing import List
from azure.quantum.optimization import Term
from azure.quantum import Workspace
from azure.identity import EnvironmentCredential
from azure.quantum.optimization import ParallelTempering

problem = Problem(name="My First Problem", problem_type=ProblemType.ising)

workspace = Workspace (
    subscription_id = "my-subscription-id",  # Add your subscription_id
    resource_group = "AzureQuantum",   # Add your resource_group
    name = "my-workspace-name",             # Add your workspace name
    location = "my-workspace-location"  ,        # Add your workspace location (for example, "westus")
    credential = EnvironmentCredential(AZURE_USERNAME="my-email-id", AZURE_PASSWORD="my-microsoft-password")
    # credential = ManagedIdentityCredential()
    )

terms = [
    Term(c=-9, indices=[0]),
    Term(c=-3, indices=[1,0]),
    Term(c=5, indices=[2,0]),
    Term(c=9, indices=[2,1]),
    Term(c=2, indices=[3,0]),
    Term(c=-4, indices=[3,1]),
    Term(c=4, indices=[3,2])
]

problem.add_terms(terms=terms)



solver = ParallelTempering(workspace, timeout=100)

result = solver.optimize(problem)
print(result)

The above code throws the error:

EnvironmentCredential.get_token failed: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot.this issue.
---------------------------------------------------------------------------
CredentialUnavailableError                Traceback (most recent call last)
[<ipython-input-19-90cd448f8194>](https://localhost:8080/#) in <module>()
      3 solver = ParallelTempering(workspace, timeout=100)
      4 
----> 5 result = solver.optimize(problem)
      6 print(result)

19 frames
[/usr/local/lib/python3.7/dist-packages/azure/identity/_credentials/environment.py](https://localhost:8080/#) in get_token(self, *scopes, **kwargs)
    141                 "this issue."
    142             )
--> 143             raise CredentialUnavailableError(message=message)
    144         return self._credential.get_token(*scopes, **kwargs)

CredentialUnavailableError: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot this issue.

Details The above code works perfectly fine when I do not pass any credentials to the workspace, but this pops up a window for authentication. I do not want to click manually on the browser every time I run something to autheticate. I just want to pass the credentials in code with ease without having to deal with all the complicated things defined for the authentication in the docs.

Note: I'm passing my email and password in the EnvironmentCredential (I'm obviously not writing confidential info here like subscription id passed in workspace)

SagarDollin avatar Aug 08 '22 13:08 SagarDollin